From 79ed4b626e68327eefa6f416fb4c17d3fbd966be Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 3 Mar 2025 21:20:59 -0800 Subject: [PATCH 01/12] (UI) Fix session handling with cookies (#8969) * add cookieUtils * use utils for clearing cookies * on logout use clearTokenCookies * ui use correct clearTokenCookies * navbar show userEmail on UserID page --- .../src/app/onboarding/page.tsx | 9 +--- ui/litellm-dashboard/src/app/page.tsx | 1 + .../src/components/navbar.tsx | 6 ++- .../src/components/user_dashboard.tsx | 11 +++-- ui/litellm-dashboard/src/utils/cookieUtils.ts | 44 +++++++++++++++++++ 5 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 ui/litellm-dashboard/src/utils/cookieUtils.ts diff --git a/ui/litellm-dashboard/src/app/onboarding/page.tsx b/ui/litellm-dashboard/src/app/onboarding/page.tsx index ff301d7a47..e46e46fcb5 100644 --- a/ui/litellm-dashboard/src/app/onboarding/page.tsx +++ b/ui/litellm-dashboard/src/app/onboarding/page.tsx @@ -20,14 +20,7 @@ import { } from "@/components/networking"; import { jwtDecode } from "jwt-decode"; import { Form, Button as Button2, message } from "antd"; - -function getCookie(name: string) { - console.log("COOKIES", document.cookie) - const cookieValue = document.cookie - .split('; ') - .find(row => row.startsWith(name + '=')); - return cookieValue ? cookieValue.split('=')[1] : null; -} +import { getCookie } from "@/utils/cookieUtils"; export default function Onboarding() { const [form] = Form.useForm(); diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index 33d52bc41a..2612cab594 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -211,6 +211,7 @@ export default function CreateKeyPage() { userID={userID} userRole={userRole} premiumUser={premiumUser} + userEmail={userEmail} setProxySettings={setProxySettings} proxySettings={proxySettings} /> diff --git a/ui/litellm-dashboard/src/components/navbar.tsx b/ui/litellm-dashboard/src/components/navbar.tsx index 325ad9c359..9bdc0fe9b7 100644 --- a/ui/litellm-dashboard/src/components/navbar.tsx +++ b/ui/litellm-dashboard/src/components/navbar.tsx @@ -8,8 +8,10 @@ import { UserOutlined, LogoutOutlined } from '@ant-design/icons'; +import { clearTokenCookies } from "@/utils/cookieUtils"; interface NavbarProps { userID: string | null; + userEmail: string | null; userRole: string | null; premiumUser: boolean; setProxySettings: React.Dispatch>; @@ -18,6 +20,7 @@ interface NavbarProps { const Navbar: React.FC = ({ userID, + userEmail, userRole, premiumUser, proxySettings, @@ -27,7 +30,7 @@ const Navbar: React.FC = ({ let logoutUrl = proxySettings?.PROXY_LOGOUT_URL || ""; const handleLogout = () => { - document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + clearTokenCookies(); window.location.href = logoutUrl; }; @@ -37,6 +40,7 @@ const Navbar: React.FC = ({ label: (

Role: {userRole}

+

Email: {userEmail || "Unknown"}

{userID}

Premium User: {String(premiumUser)}

diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index 8b9f5e328f..22b47d525f 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -21,6 +21,7 @@ import { useSearchParams, useRouter } from "next/navigation"; import { Team } from "./key_team_helpers/key_list"; import { jwtDecode } from "jwt-decode"; import { Typography } from "antd"; +import { clearTokenCookies } from "@/utils/cookieUtils"; const isLocal = process.env.NODE_ENV === "development"; if (isLocal != true) { console.log = function() {}; @@ -295,14 +296,15 @@ const UserDashboard: React.FC = ({ if (userID == null || token == null) { // user is not logged in as yet + console.log("All cookies before redirect:", document.cookie); + + // Clear token cookies using the utility function + clearTokenCookies(); + const url = proxyBaseUrl ? `${proxyBaseUrl}/sso/key/generate` : `/sso/key/generate`; - - // clear cookie called "token" since user will be logging in again - document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; - console.log("Full URL:", url); window.location.href = url; @@ -326,6 +328,7 @@ const UserDashboard: React.FC = ({ } console.log("inside user dashboard, selected team", selectedTeam); + console.log("All cookies after redirect:", document.cookie); return (
diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts new file mode 100644 index 0000000000..a09cf4e97f --- /dev/null +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -0,0 +1,44 @@ +/** + * Utility functions for managing cookies + */ + +/** + * Clears the token cookie from both root and /ui paths + */ +export function clearTokenCookies() { + // Get the current domain + const domain = window.location.hostname; + + // Clear with various combinations of path and SameSite + const paths = ['/', '/ui']; + const sameSiteValues = ['Lax', 'Strict', 'None']; + + paths.forEach(path => { + // Basic clearing + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; + + // With domain + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; + + // Try different SameSite values + sameSiteValues.forEach(sameSite => { + const secureFlag = sameSite === 'None' ? ' Secure;' : ''; + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; + }); + }); + + console.log("After clearing cookies:", document.cookie); +} + +/** + * Gets a cookie value by name + * @param name The name of the cookie to retrieve + * @returns The cookie value or null if not found + */ +export function getCookie(name: string) { + const cookieValue = document.cookie + .split('; ') + .find(row => row.startsWith(name + '=')); + return cookieValue ? cookieValue.split('=')[1] : null; +} \ No newline at end of file From c015fb34f1e120d4631ab58ebd76879b27c76bd7 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 3 Mar 2025 22:17:21 -0800 Subject: [PATCH 02/12] (UI) - Improvements to session handling logic (#8970) * add cookieUtils * use utils for clearing cookies * on logout use clearTokenCookies * ui use correct clearTokenCookies * navbar show userEmail on UserID page * add timestamp on token cookie * update generate_authenticated_redirect_response * use common getAuthToken * fix clearTokenCookies * fixes for get auth token * fix invitation link sign in logic * Revert "fix invitation link sign in logic" This reverts commit 30e5308cb3223981c715e723cdd3a6d2ee3aaa4b. * fix getAuthToken * update setAuthToken * fix ui session handling * fix ui session handler --- litellm/proxy/management_endpoints/ui_sso.py | 9 +- .../management_helpers/ui_session_handler.py | 24 +++++ litellm/proxy/proxy_server.py | 14 +-- .../src/app/onboarding/page.tsx | 6 +- ui/litellm-dashboard/src/app/page.tsx | 9 +- .../src/components/user_dashboard.tsx | 11 +-- ui/litellm-dashboard/src/utils/cookieUtils.ts | 96 ++++++++++++++----- 7 files changed, 117 insertions(+), 52 deletions(-) create mode 100644 litellm/proxy/management_helpers/ui_session_handler.py diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index 86dec9fcaf..d903e2665c 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -7,6 +7,7 @@ Has all /sso/* routes import asyncio import os +import time import uuid from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast @@ -44,6 +45,7 @@ from litellm.proxy.management_endpoints.sso_helper_utils import ( ) from litellm.proxy.management_endpoints.team_endpoints import team_member_add from litellm.proxy.management_endpoints.types import CustomOpenID +from litellm.proxy.management_helpers.ui_session_handler import UISessionHandler from litellm.secret_managers.main import str_to_bool if TYPE_CHECKING: @@ -691,9 +693,10 @@ async def auth_callback(request: Request): # noqa: PLR0915 ) if user_id is not None and isinstance(user_id, str): litellm_dashboard_ui += "?userID=" + user_id - redirect_response = RedirectResponse(url=litellm_dashboard_ui, status_code=303) - redirect_response.set_cookie(key="token", value=jwt_token, secure=True) - return redirect_response + + return UISessionHandler.generate_authenticated_redirect_response( + redirect_url=litellm_dashboard_ui, jwt_token=jwt_token + ) async def insert_sso_user( diff --git a/litellm/proxy/management_helpers/ui_session_handler.py b/litellm/proxy/management_helpers/ui_session_handler.py new file mode 100644 index 0000000000..6afe158c33 --- /dev/null +++ b/litellm/proxy/management_helpers/ui_session_handler.py @@ -0,0 +1,24 @@ +import time + +from fastapi.responses import RedirectResponse + + +class UISessionHandler: + @staticmethod + def generate_authenticated_redirect_response( + redirect_url: str, jwt_token: str + ) -> RedirectResponse: + redirect_response = RedirectResponse(url=redirect_url, status_code=303) + redirect_response.set_cookie( + key=UISessionHandler._generate_token_name(), + value=jwt_token, + secure=True, + samesite="strict", + ) + return redirect_response + + @staticmethod + def _generate_token_name() -> str: + current_timestamp = int(time.time()) + cookie_name = f"token_{current_timestamp}" + return cookie_name diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 19d0ebe9ea..bcca95b310 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7372,6 +7372,8 @@ async def login(request: Request): # noqa: PLR0915 import multipart except ImportError: subprocess.run(["pip", "install", "python-multipart"]) + from litellm.proxy.management_helpers.ui_session_handler import UISessionHandler + global master_key if master_key is None: raise ProxyException( @@ -7489,9 +7491,9 @@ async def login(request: Request): # noqa: PLR0915 algorithm="HS256", ) litellm_dashboard_ui += "?userID=" + user_id - redirect_response = RedirectResponse(url=litellm_dashboard_ui, status_code=303) - redirect_response.set_cookie(key="token", value=jwt_token) - return redirect_response + return UISessionHandler.generate_authenticated_redirect_response( + redirect_url=litellm_dashboard_ui, jwt_token=jwt_token + ) elif _user_row is not None: """ When sharing invite links @@ -7557,11 +7559,9 @@ async def login(request: Request): # noqa: PLR0915 algorithm="HS256", ) litellm_dashboard_ui += "?userID=" + user_id - redirect_response = RedirectResponse( - url=litellm_dashboard_ui, status_code=303 + return UISessionHandler.generate_authenticated_redirect_response( + redirect_url=litellm_dashboard_ui, jwt_token=jwt_token ) - redirect_response.set_cookie(key="token", value=jwt_token) - return redirect_response else: raise ProxyException( message=f"Invalid credentials used to access UI.\nNot valid credentials for {username}", diff --git a/ui/litellm-dashboard/src/app/onboarding/page.tsx b/ui/litellm-dashboard/src/app/onboarding/page.tsx index e46e46fcb5..0c194ba0cb 100644 --- a/ui/litellm-dashboard/src/app/onboarding/page.tsx +++ b/ui/litellm-dashboard/src/app/onboarding/page.tsx @@ -20,12 +20,12 @@ import { } from "@/components/networking"; import { jwtDecode } from "jwt-decode"; import { Form, Button as Button2, message } from "antd"; -import { getCookie } from "@/utils/cookieUtils"; +import { getAuthToken, setAuthToken } from "@/utils/cookieUtils"; export default function Onboarding() { const [form] = Form.useForm(); const searchParams = useSearchParams()!; - const token = getCookie('token'); + const token = getAuthToken(); const inviteID = searchParams.get("invitation_id"); const [accessToken, setAccessToken] = useState(null); const [defaultUserEmail, setDefaultUserEmail] = useState(""); @@ -88,7 +88,7 @@ export default function Onboarding() { litellm_dashboard_ui += "?userID=" + user_id; // set cookie "token" to jwtToken - document.cookie = "token=" + jwtToken; + setAuthToken(jwtToken); console.log("redirecting to:", litellm_dashboard_ui); window.location.href = litellm_dashboard_ui; diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index 2612cab594..fa07c08615 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -30,12 +30,7 @@ import { Organization } from "@/components/networking"; import GuardrailsPanel from "@/components/guardrails"; import { fetchUserModels } from "@/components/create_key_button"; import { fetchTeams } from "@/components/common_components/fetch_teams"; -function getCookie(name: string) { - const cookieValue = document.cookie - .split("; ") - .find((row) => row.startsWith(name + "=")); - return cookieValue ? cookieValue.split("=")[1] : null; -} +import { getAuthToken } from "@/utils/cookieUtils"; function formatUserRole(userRole: string) { if (!userRole) { @@ -117,7 +112,7 @@ export default function CreateKeyPage() { const [accessToken, setAccessToken] = useState(null); useEffect(() => { - const token = getCookie("token"); + const token = getAuthToken(); setToken(token); }, []); diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index 22b47d525f..9f4230e6b2 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -21,6 +21,7 @@ import { useSearchParams, useRouter } from "next/navigation"; import { Team } from "./key_team_helpers/key_list"; import { jwtDecode } from "jwt-decode"; import { Typography } from "antd"; +import { getAuthToken } from "@/utils/cookieUtils"; import { clearTokenCookies } from "@/utils/cookieUtils"; const isLocal = process.env.NODE_ENV === "development"; if (isLocal != true) { @@ -45,14 +46,6 @@ export type UserInfo = { spend: number; } -function getCookie(name: string) { - console.log("COOKIES", document.cookie) - const cookieValue = document.cookie - .split('; ') - .find(row => row.startsWith(name + '=')); - return cookieValue ? cookieValue.split('=')[1] : null; -} - interface UserDashboardProps { userID: string | null; userRole: string | null; @@ -94,7 +87,7 @@ const UserDashboard: React.FC = ({ // Assuming useSearchParams() hook exists and works in your setup const searchParams = useSearchParams()!; - const token = getCookie('token'); + const token = getAuthToken(); const invitation_id = searchParams.get("invitation_id"); diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts index a09cf4e97f..e181606e93 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -13,32 +13,82 @@ export function clearTokenCookies() { const paths = ['/', '/ui']; const sameSiteValues = ['Lax', 'Strict', 'None']; - paths.forEach(path => { - // Basic clearing - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; - - // With domain - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; - - // Try different SameSite values - sameSiteValues.forEach(sameSite => { - const secureFlag = sameSite === 'None' ? ' Secure;' : ''; - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; + // Get all cookies + const allCookies = document.cookie.split("; "); + const tokenPattern = /^token_\d+$/; + + // Find all token cookies + const tokenCookieNames = allCookies + .map(cookie => cookie.split("=")[0]) + .filter(name => name === "token" || tokenPattern.test(name)); + + // Clear each token cookie with various combinations + tokenCookieNames.forEach(cookieName => { + paths.forEach(path => { + // Basic clearing + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; + + // With domain + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; + + // Try different SameSite values + sameSiteValues.forEach(sameSite => { + const secureFlag = sameSite === 'None' ? ' Secure;' : ''; + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; + }); }); }); console.log("After clearing cookies:", document.cookie); } -/** - * Gets a cookie value by name - * @param name The name of the cookie to retrieve - * @returns The cookie value or null if not found - */ -export function getCookie(name: string) { - const cookieValue = document.cookie - .split('; ') - .find(row => row.startsWith(name + '=')); - return cookieValue ? cookieValue.split('=')[1] : null; -} \ No newline at end of file +export function setAuthToken(token: string) { + // Generate a token name with current timestamp + const currentTimestamp = Math.floor(Date.now() / 1000); + const tokenName = `token_${currentTimestamp}`; + + // Set the cookie with the timestamp-based name + document.cookie = `${tokenName}=${token}; path=/; domain=${window.location.hostname};`; +} + +export function getAuthToken() { + // Check if we're in a browser environment + if (typeof window === 'undefined' || typeof document === 'undefined') { + return null; + } + + const tokenPattern = /^token_(\d+)$/; + const allCookies = document.cookie.split("; "); + + const tokenCookies = allCookies + .map(cookie => { + const parts = cookie.split("="); + const name = parts[0]; + + // Explicitly skip cookies named just "token" + if (name === "token") { + return null; + } + + // Only match cookies with the token_{timestamp} format + const match = name.match(tokenPattern); + if (match) { + return { + name, + timestamp: parseInt(match[1], 10), + value: parts.slice(1).join("=") + }; + } + return null; + }) + .filter((cookie): cookie is { name: string; timestamp: number; value: string } => cookie !== null); + + if (tokenCookies.length > 0) { + // Sort by timestamp (newest first) + tokenCookies.sort((a, b) => b.timestamp - a.timestamp); + return tokenCookies[0].value; + } + + return null; +} From 94563ab1e73c143a592cfa7988031e82e1fe90cd Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 3 Mar 2025 22:21:31 -0800 Subject: [PATCH 03/12] ui new build --- .../_buildManifest.js | 0 .../_ssgManifest.js | 0 .../static/chunks/app/onboarding/page-8ba945cf183c937c.js | 1 + .../static/chunks/app/onboarding/page-f2e9aa9e77b66520.js | 1 - .../out/_next/static/chunks/app/page-a006114359094d34.js | 1 + .../out/_next/static/chunks/app/page-e28453cd004ff93c.js | 1 - litellm/proxy/_experimental/out/index.html | 2 +- litellm/proxy/_experimental/out/index.txt | 4 ++-- litellm/proxy/_experimental/out/model_hub.txt | 2 +- litellm/proxy/_experimental/out/onboarding.html | 1 + litellm/proxy/_experimental/out/onboarding.txt | 4 ++-- ui/litellm-dashboard/out/404.html | 2 +- .../_buildManifest.js | 0 .../_ssgManifest.js | 0 .../static/chunks/app/onboarding/page-8ba945cf183c937c.js | 1 + .../static/chunks/app/onboarding/page-f2e9aa9e77b66520.js | 1 - .../out/_next/static/chunks/app/page-a006114359094d34.js | 1 + .../out/_next/static/chunks/app/page-e28453cd004ff93c.js | 1 - ui/litellm-dashboard/out/index.html | 2 +- ui/litellm-dashboard/out/index.txt | 4 ++-- ui/litellm-dashboard/out/model_hub.html | 2 +- ui/litellm-dashboard/out/model_hub.txt | 2 +- ui/litellm-dashboard/out/onboarding.html | 2 +- ui/litellm-dashboard/out/onboarding.txt | 4 ++-- 24 files changed, 20 insertions(+), 19 deletions(-) rename litellm/proxy/_experimental/out/_next/static/{sW550-yvC4l9ZFA0scEUc => FMvuTRMhZEulJpWx99WMb}/_buildManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/{sW550-yvC4l9ZFA0scEUc => FMvuTRMhZEulJpWx99WMb}/_ssgManifest.js (100%) create mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js delete mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js create mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js delete mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js create mode 100644 litellm/proxy/_experimental/out/onboarding.html rename ui/litellm-dashboard/out/_next/static/{sW550-yvC4l9ZFA0scEUc => FMvuTRMhZEulJpWx99WMb}/_buildManifest.js (100%) rename ui/litellm-dashboard/out/_next/static/{sW550-yvC4l9ZFA0scEUc => FMvuTRMhZEulJpWx99WMb}/_ssgManifest.js (100%) create mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js delete mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js create mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js delete mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js diff --git a/litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js new file mode 100644 index 0000000000..a22da3c6fe --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,t,n){Promise.resolve().then(n.bind(n,12011))},12011:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return g}});var o=n(57437),a=n(2265),c=n(99376),s=n(20831),i=n(94789),l=n(12514),r=n(49804),u=n(67101),m=n(84264),d=n(49566),h=n(96761),p=n(84566),f=n(19250),x=n(14474),k=n(13634),_=n(73002),j=n(3914);function g(){let[e]=k.Z.useForm(),t=(0,c.useSearchParams)();(0,j.bW)();let n=t.get("invitation_id"),[g,w]=(0,a.useState)(null),[S,Z]=(0,a.useState)(""),[b,N]=(0,a.useState)(""),[v,y]=(0,a.useState)(null),[T,E]=(0,a.useState)(""),[C,U]=(0,a.useState)("");return(0,a.useEffect)(()=>{n&&(0,f.W_)(n).then(e=>{let t=e.login_url;console.log("login_url:",t),E(t);let n=e.token,o=(0,x.o)(n);U(n),console.log("decoded:",o),w(o.key),console.log("decoded user email:",o.user_email),N(o.user_email),y(o.user_id)})},[n]),(0,o.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,o.jsxs)(l.Z,{children:[(0,o.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,o.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,o.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,o.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,o.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,o.jsx)(r.Z,{children:"SSO is under the Enterprise Tirer."}),(0,o.jsx)(r.Z,{children:(0,o.jsx)(s.Z,{variant:"primary",className:"mb-2",children:(0,o.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,o.jsxs)(k.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",C,"formValues:",e),g&&C&&(e.user_email=b,v&&n&&(0,f.m_)(g,n,v,e.password).then(e=>{var t;let n="/ui/";n+="?userID="+((null===(t=e.data)||void 0===t?void 0:t.user_id)||e.user_id),(0,j.uB)(C),console.log("redirecting to:",n),window.location.href=n}))},children:[(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(k.Z.Item,{label:"Email Address",name:"user_email",children:(0,o.jsx)(d.Z,{type:"email",disabled:!0,value:b,defaultValue:b,className:"max-w-md"})}),(0,o.jsx)(k.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,o.jsx)(d.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,o.jsx)("div",{className:"mt-10",children:(0,o.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},3914:function(e,t,n){"use strict";function o(){let e=window.location.hostname,t=["/","/ui"],n=["Lax","Strict","None"],o=document.cookie.split("; "),a=/^token_\d+$/;o.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(o=>{t.forEach(t=>{document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,";"),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,";"),n.forEach(n=>{let a="None"===n?" Secure;":"";document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; SameSite=").concat(n,";").concat(a),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,"; SameSite=").concat(n,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let t=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(t),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function c(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,t=document.cookie.split("; ").map(t=>{let n=t.split("="),o=n[0];if("token"===o)return null;let a=o.match(e);return a?{name:o,timestamp:parseInt(a[1],10),value:n.slice(1).join("=")}:null}).filter(e=>null!==e);return t.length>0?(t.sort((e,t)=>t.timestamp-e.timestamp),t[0].value):null}n.d(t,{bA:function(){return o},bW:function(){return c},uB:function(){return a}})}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js deleted file mode 100644 index 2909ac65a0..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,s,t){Promise.resolve().then(t.bind(t,12011))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return g}});var l=t(57437),n=t(2265),a=t(99376),i=t(20831),r=t(94789),o=t(12514),c=t(49804),u=t(67101),d=t(84264),m=t(49566),h=t(96761),x=t(84566),f=t(19250),p=t(14474),j=t(13634),_=t(73002);function g(){let[e]=j.Z.useForm(),s=(0,a.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));s&&s.split("=")[1]}("token");let t=s.get("invitation_id"),[g,Z]=(0,n.useState)(null),[k,w]=(0,n.useState)(""),[S,b]=(0,n.useState)(""),[N,v]=(0,n.useState)(null),[y,E]=(0,n.useState)(""),[I,O]=(0,n.useState)("");return(0,n.useEffect)(()=>{t&&(0,f.W_)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),E(s);let t=e.token,l=(0,p.o)(t);O(t),console.log("decoded:",l),Z(l.key),console.log("decoded user email:",l.user_email),b(l.user_email),v(l.user_id)})},[t]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,l.jsx)(d.Z,{children:"Claim your user account to login to Admin UI."}),(0,l.jsx)(r.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,l.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tirer."}),(0,l.jsx)(c.Z,{children:(0,l.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,l.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,l.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",I,"formValues:",e),g&&I&&(e.user_email=S,N&&t&&(0,f.m_)(g,t,N,e.password).then(e=>{var s;let t="/ui/";t+="?userID="+((null===(s=e.data)||void 0===s?void 0:s.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",t),window.location.href=t}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(m.Z,{type:"email",disabled:!0,value:S,defaultValue:S,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,l.jsx)(m.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js new file mode 100644 index 0000000000..d7f1882c15 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return v}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002),_=s(3914);function v(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();(0,_.bW)();let s=l.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[S,k]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[A,E]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),I(l);let s=e.token,t=(0,g.o)(s);E(s),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),k(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",A,"formValues:",e),v&&A&&(e.user_email=N,S&&s&&(0,p.m_)(v,s,S,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),(0,_.uB)(A),console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return te}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=s(3914),g=e=>{let{userID:l,userEmail:s,userRole:t,premiumUser:a,proxySettings:i}=e,n=(null==i?void 0:i.PROXY_LOGOUT_URL)||"",o=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",s||"Unknown"]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,p.bA)(),window.location.href=n},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:o,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},j=s(19250);let f=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,j.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,j.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var _=s(49804),v=s(67101),y=s(20831),b=s(49566),Z=s(87452),N=s(88829),w=s(72208),S=s(84264),k=s(96761),C=s(29233),I=s(52787),A=s(13634),E=s(41021),P=s(51369),O=s(29967),T=s(73002),M=s(20577),L=s(56632);let D=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,j.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},R=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},F=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var U=s(15424),z=s(98074);let V=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,q=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},K=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return V(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var B=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),V(e,l)&&p.push({validator:async(e,l)=>{if(l&&!q(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(z.Z,{title:h,children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}):u;return t=V(e,l)?(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(I.default,{children:l.enum.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(M.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(b.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(b.Z,{placeholder:h||""}),(0,r.jsx)(A.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:K(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},H=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(I.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},J=s(57365),G=s(93192);function W(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=G.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(P.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(S.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{children:"Invitation Link"}),(0,r.jsx)(S.Z,{children:(0,r.jsx)(S.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>E.ZP.success("Copied!"),children:(0,r.jsx)(y.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var Y=s(30967),$=s(28181),X=s(73879),Q=s(3632),ee=s(15452),el=s.n(ee),es=s(71157),et=s(44643),ea=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.g)(l);g(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let v=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,j.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,j.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(P.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=new Blob([el().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(Y.Z,{beforeUpload:e=>(x(null),el().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(Q.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(y.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(S.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(S.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(et.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(S.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)($.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(C.CopyToClipboard,{text:l.invitation_link,onCopy:()=>E.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([el().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:er}=I.default;var ei=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=A.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[v,C]=(0,i.useState)(!1),[O,M]=(0,i.useState)(null),D=(0,n.useRouter)(),[F,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.So)(s,l,"any"),t=[];for(let l=0;l{D&&V(new URL("/",window.location.href).toString())},[D]);let q=async e=>{var t,a,r;try{E.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.Ov)(s,null,e);console.log("user create Response:",a),g(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};M(e),C(!0)}else(0,j.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,M(e),C(!0)});E.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";E.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(ea,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(P.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),g(null),u.resetFields()},children:[(0,r.jsx)(S.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(z.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(U.Z,{})})]}),name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(A.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(W,{isInvitationLinkModalVisible:v,setIsInvitationLinkModalVisible:C,baseUrl:F,invitationLinkData:O})]})},en=s(7310),eo=s.n(en);let{Option:ed}=I.default,ec=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},em=(e,l)=>F(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),eu=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,j.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eh=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,D]=(0,i.useState)([]),[F,V]=(0,i.useState)([]),[q,K]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ec(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[er,en]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&eu(l,a,n,D)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,j.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(E.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,j.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),g(m.soft_budget),E.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),E.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(em($,f)),c.setFieldValue("models",[])},[$,f]);let ef=async e=>{if(!e){en([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,j.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(s)}catch(e){console.error("Error fetching users:",e),E.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(eo()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(P.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(A.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(z.Z,{title:"Select who will own this API key",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(O.ZP.Group,{onChange:e=>K(e.target.value),value:q,children:[(0,r.jsx)(O.ZP,{value:"you",children:"You"}),(0,r.jsx)(O.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(O.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(z.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:er,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(T.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(z.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(H,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(z.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),F.map(e=>(0,r.jsx)(ed,{value:e,children:R(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(z.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(z.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(z.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(b.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(z.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(z.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:j.H2?"".concat(j.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(U.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(B,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(P.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(ei,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(P.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Save your Key"}),(0,r.jsx)(_.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)(_.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(S.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:h})}),(0,r.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{E.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(S.Z,{children:"Key being created, this might take 30s"})})]})})]})},ex=s(7366),ep=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,j.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},eg=s(71594),ej=s(24525),ef=s(21626),e_=s(97214),ev=s(28241),ey=s(58834),eb=s(69552),eZ=s(71876);function eN(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,eg.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,ej.sC)(),getExpandedRowModel:(0,ej.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:n?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var ew=s(27281),eS=s(41649),ek=s(12514),eC=s(12485),eI=s(18135),eA=s(35242),eE=s(29706),eP=s(77991),eO=s(10900),eT=s(23628),eM=s(74998);function eL(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=A.Z.useForm(),[h,x]=(0,i.useState)([]),p=em(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,j.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let g={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(A.Z,{form:u,onFinish:n,initialValues:g,layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(L.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(y.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]})}function eD(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let g=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,j.s0)(a,l.token,e);d(s.key),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key"),p(!1)}}},f=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(P.Z,{title:"Regenerate API Key",open:s,onCancel:f,footer:o?[(0,r.jsx)(y.Z,{onClick:f,children:"Close"},"close")]:[(0,r.jsx)(y.Z,{onClick:f,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(C.CopyToClipboard,{text:o,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(A.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eR(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=A.Z.useForm(),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),E.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,j.Nc)(o,e),E.ZP.success("Key updated successfully"),h(!1)}catch(e){E.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,j.I1)(o,n.token),E.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),E.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(k.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{icon:eT.Z,variant:"secondary",onClick:()=>_(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>g(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eD,{selectedToken:n,visible:f,onClose:()=>_(!1),accessToken:o}),p&&(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)(y.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>g(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(S.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(y.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eL,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(S.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(S.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(S.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(S.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(S.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(S.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eF=s(87908),eU=s(82422),ez=s(2356),eV=s(44633),eq=s(86462),eK=s(3837),eB=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[v,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let C=(0,i.useCallback)(eo()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eU.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),O=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(y.Z,{icon:ez.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(ek.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(T.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==O?void 0:O.label)||m,f?(0,r.jsx)(eV.Z,{className:"h-4 w-4"}):(0,r.jsx)(eq.Z,{className:"h-4 w-4"})]})}),(null==O?void 0:O.isSearchable)?(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search ".concat(O.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),C(e,O)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:v,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eF.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(T.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(L.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eK.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(T.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(T.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eH=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eJ=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eG(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[g,f]=(0,i.useState)(null),[_,v]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,j.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.getValue(),children:(0,r.jsx)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eH(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eJ(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:g?(0,r.jsx)(eR,{keyId:g,onClose:()=>f(null),keyData:l.find(e=>e.token===g),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eB,{options:w,onApplyFilters:e=>{if(v({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{v({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eN,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eW=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[I,O]=(0,i.useState)(null),[T,L]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ep({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=A.Z.useForm(),[em,eu]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await D(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,j.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),w(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){E.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,j.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eG,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),f&&(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)(y.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(P.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(y.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(A.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(y.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(P.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(y.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(C.CopyToClipboard,{text:ei,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eY=s(12011);console.log=function(){},console.log("isLocal:",!1);var e$=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:g}=e,[y,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),w=(0,n.useSearchParams)(),S=(0,p.bW)(),k=w.get("invitation_id"),[C,I]=(0,i.useState)(null),[A,E]=(0,i.useState)(null),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)(null),[L,D]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(S){let e=(0,o.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),I(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&C&&s&&!a&&!y){let e=sessionStorage.getItem("userModels"+l);e?O(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.g)(C);M(e);let t=await (0,j.Br)(C,l,s,!1,null,null);b(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(y))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,j.So)(C,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),O(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),f(C,l,s,Z,u))}},[l,S,C,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(C,", userID: ").concat(l,", userRole: ").concat(s)),C&&(console.log("fetching teams"),f(C,l,s,Z,u))},[Z]),(0,i.useEffect)(()=>{if(null!==a&&null!=L&&null!==L.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))L.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===L.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),E(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;E(e)}},[L]),null!=k)return(0,r.jsx)(eY.default,{});if(null==l||null==S){console.log("All cookies before redirect:",document.cookie),(0,p.bA)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=G.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",L),console.log("All cookies after redirect:",document.cookie),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(_.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eh,{userID:l,team:L,teams:t,userRole:s,accessToken:C,data:a,setData:h},L?L.team_id:null),(0,r.jsx)(eW,{userID:l,userRole:s,accessToken:C,selectedTeam:L||null,setSelectedTeam:D,data:a,setData:h,premiumUser:x,teams:t,currentOrg:Z,setCurrentOrg:N,organizations:g})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let eX={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eQ={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},e0=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eQ[e],displayName:e}}let l=Object.keys(eX).find(l=>eX[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eQ[s],displayName:s}},e1=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e2=(e,l)=>{console.log("Provider key: ".concat(e));let s=eX[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e4=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=eX[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=eX[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,j.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){E.ZP.error("Failed to create model: "+e,10)}},e5=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e3=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,j.um)(l,i),E.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e6=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=A.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(P.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(A.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},e8=s(47323),e7=s(53410),e9=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),E.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){E.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(I.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(P.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(A.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(S.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(I.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(T.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},le=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,j.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(eo()((e,l)=>f(e,l),300),[]),v=(e,l)=>{g(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(P.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(A.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:(0,r.jsxs)(z.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},ll=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,g]=(0,i.useState)(!1),[f]=A.Z.useForm(),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.Xm)(a,s);u(e)}catch(e){E.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.cu)(a,s,l),E.ZP.success("Team member added successfully"),g(!1),f.resetFields(),O()}catch(e){E.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},F=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.sN)(a,s,l),E.ZP.success("Team member updated successfully"),b(!1),O()}catch(e){E.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,j.Lp)(a,s,e),E.ZP.success("Team member removed successfully"),O()}catch(e){E.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,j.Gh)(a,t),E.ZP.success("Team settings updated successfully"),C(!1),O()}catch(e){E.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:K.team_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"User Email"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>V(e),icon:eM.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(y.Z,{onClick:()=>g(!0),children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Team Settings"}),P&&!w&&(0,r.jsx)(y.Z,{onClick:()=>C(!0),children:"Edit Settings"})]}),w?(0,r.jsxs)(A.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(L.Z,{type:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>C(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(eS.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e9,{visible:_,onCancel:()=>b(!1),onSubmit:F,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(le,{isVisible:p,onCancel:()=>g(!1),onSubmit:D,accessToken:a})]})},ls=s(30150);function lt(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,g,f,_,Z,N,w,C;let{modelId:I,onClose:P,modelData:O,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=A.Z.useForm(),[V,q]=(0,i.useState)(O),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:I}};await (0,j.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),E.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),E.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!O)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(S.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,j.Og)(M,I),E.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),E.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(k.Z,{children:["Public Model Name: ",e5(O)]}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:O.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-6",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[O.provider&&(0,r.jsx)("img",{src:e0(O.provider).logo,alt:"".concat(O.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=O.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(k.Z,{children:O.provider||"Not Set"})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(k.Z,{children:O.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Input: $",O.input_cost,"/1M tokens"]}),(0,r.jsxs)(S.Z,{children:["Output: $",O.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",O.model_info.created_at?new Date(O.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",O.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(A.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*O.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*O.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*O.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*O.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=V.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=V.litellm_params)||void 0===_?void 0:_.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=V.litellm_params)||void 0===w?void 0:w.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:O.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(y.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(O,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(T.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(T.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var la=s(67960),lr=s(47451),li=s(69410),ln=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=A.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(b.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(b.Z,{placeholder:t(l)})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},lo=()=>{let e=A.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=A.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=A.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(b.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)($.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:ld}=G.default;var lc=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(A.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(b.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(b.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(b.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(Y.Z,{...s,children:(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(Q.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(I.default,{placeholder:"Select API Base",children:[(0,r.jsx)(I.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(I.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(b.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(b.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(A.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(ld,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(b.Z,{placeholder:"sk-",type:"password"})})]})},lm=s(63709),lu=s(90464);let{Link:lh}=G.default;var lx=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=A.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(Z.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(A.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(H,{teams:t})}),(0,r.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lm.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}):(0,r.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lm.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(A.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(lr.Z,{className:"mb-4",children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(A.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lp,Link:lg}=G.default;var lj=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lp,{level:2,children:"Add new model"}),(0,r.jsx)(la.Z,{children:(0,r.jsx)(A.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(I.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eQ[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(ln,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(lo,{}),(0,r.jsx)(lc,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lx,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(z.Z,{title:"Get help on our github",children:(0,r.jsx)(G.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lf=s(49084);function l_(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let lv=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:e0(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(z.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:ly,Link:lb}=G.default,lZ={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lN=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[w,C]=(0,i.useState)([]),[I,P]=(0,i.useState)(a.OpenAI),[O,T]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[H,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[eN,eS]=(0,i.useState)(null),[eO,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==eN?void 0:eN.token;void 0===r&&(r=null);let i=eO;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,j.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,j.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,j.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,j.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,j.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,j.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[eN,eO]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,j.K_)(l,{router_settings:{model_group_retry_policy:ex}}),E.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),E.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let g=await (0,j.hy)(l);C(g);let f=await (0,j.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,j.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,j.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,j.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,j.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==eN?void 0:eN.token,eO),S=await (0,j.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,j.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,j.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,j.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,j.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==g&&a(),eJ()},[l,s,t,n,g,_]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e0=l.litellm_params)||void 0===e0?void 0:e0.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=G.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 e7=async()=>{try{E.ZP.info("Running health check..."),T("");let e=await (0,j.EY)(l);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}};S.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{eS(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(J.Z,{value:String(l),disabled:!0,onClick:()=>{eS(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(J.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(I)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===I);return(e9&&w.find(e=>e.name===eX[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(ll,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(lt,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"All Models"}),(0,r.jsx)(eC.Z,{children:"Add Model"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(eC.Z,{children:"Model Analytics"}),(0,r.jsx)(eC.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",_]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(J.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(l_,{columns:lv(m,ez,eB,e5,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e6,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e3(e,l,D,F)})]}),(0,r.jsx)(eE.Z,{className:"h-full",children:(0,r.jsx)(lj,{form:p,handleOk:()=>{p.validateFields().then(e=>{e4(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:I,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e2(e,g);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e1,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?E.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&E.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(y.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(k.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(S.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lZ&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lZ).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(M.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(y.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lw=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=A.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(P.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(A.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lS=s(15731);let lk=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(z.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(z.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lS.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(v.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(eS.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(eS.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lC(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lI=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(1),[_,v]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[A,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(A&&l)try{if(await (0,j.Eb)(l,[A]),E.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==A);h(e)}}catch(e){console.error("Error deleting user:",e),E.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,j.pf)(l,e,null),E.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(g));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,j.Br)(l,null,a,!0,g,25);sessionStorage.setItem("userList_".concat(g),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,j.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,g]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lk(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(ei,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||g<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||g>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lC,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lw,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",A]})]})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lA=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,j.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,j.cu)(l,e,{user_id:s,role:"user"}),E.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),E.ZP.error("Failed to join team")}};return(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Description"}),(0,r.jsx)(eb.Z,{children:"Members"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsxs)(e_.Z,{children:[t.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.team_alias})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.description||"No description available"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eS.Z,{size:"xs",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(S.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lE=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,F(s,l)};var lP=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&f(t,n,o,u,a),ew()},[c]);let[g]=A.Z.useForm(),[k]=A.Z.useForm(),{Title:C,Paragraph:O}=G.default,[F,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[J,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lE(x,ea);console.log("models: ".concat(e)),em(e),g.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,j.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},ej=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,j.rs)(t,eo),f(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await D(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));E.ZP.info("Creating Team");let o=await (0,j.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),E.ZP.success("Team created"),g.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),E.ZP.error("Error creating the team: "+e,20)}},ew=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:J?(0,r.jsx)(ll,{teamId:J,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===J)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Your Teams"}),(0,r.jsx)(eC.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(S.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Team ID"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Organization"}),(0,r.jsx)(eb.Z,{children:"Info"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ev.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)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)})},l))}):null}),(0,r.jsx)(ev.Z,{children:e.organization_id}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(ev.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>eg(e.team_id),icon:eM.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(y.Z,{onClick:ej,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(P.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),g.resetFields()},onCancel:()=>{Q(!1),g.resetFields()},children:(0,r.jsxs)(A.Z,{form:g,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{g.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(b.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lA,{accessToken:t,userID:n})})]})]})})},lO=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(!1),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,C]=(0,i.useState)(null),P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.t$)(a,s);u(e)}catch(e){E.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.vh)(a,s,l),E.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.LY)(a,s,l),E.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,j.Sb)(a,s,e.user_id),E.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,j.VA)(a,l),E.ZP.success("Organization settings updated successfully"),f(!1),O()}catch(e){E.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:m.organization_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Created At"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{C({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(y.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Organization Settings"}),P&&!g&&(0,r.jsx)(y.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),g?(0,r.jsxs)(A.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(L.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(le,{isVisible:_,onCancel:()=>b(!1),onSubmit:D,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e9,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:w,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lT=async(e,l)=>{l(await (0,j.r6)(e))};var lM=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[k,C]=(0,i.useState)(!1),[O]=A.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lT(a,m)},[l,a]);let T=e=>{e&&(w(e),Z(!0))},D=async()=>{if(N&&a)try{await (0,j.cq)(a,N),E.ZP.success("Organization deleted successfully"),Z(!1),w(null),lT(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,j.H1)(a,e),C(!1),O.resetFields(),lT(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lO,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(eC.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(S.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Organization ID"}),(0,r.jsx)(eb.Z,{children:"Organization Name"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(eb.Z,{children:"Info"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.organization_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{children:e.organization_alias}),(0,r.jsx)(ev.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{children:e.spend}),(0,r.jsx)(ev.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(ev.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)},l))})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(ev.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>T(e.organization_id),icon:eM.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>C(!0),children:"+ Create New Organization"}),(0,r.jsx)(P.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{C(!1),O.resetFields()},children:(0,r.jsxs)(A.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(y.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),f?(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 Organization"}),(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 organization?"})})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(S.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lL=s(94789);let lD={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lR={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lF=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lR[e];return l?l.fields.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(L.Z.Password,{}):(0,r.jsx)(b.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(P.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(A.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(I.default,{children:Object.entries(lD).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(A.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(P.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(S.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)(T.ZP,{onClick:n,children:"Done"})})]})]})};let lU=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lz=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=A.Z.useForm(),[d]=A.Z.useForm(),{Title:c,Paragraph:m}=G.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[I,O]=(0,i.useState)(!1),[M,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,J]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lU(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){E.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,j.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),E.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,j.eH)(s,e.ip);let l=await (0,j.PT)(s);B(l),E.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),E.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{J(e),q(!0)},et=async()=>{if(H&&s)try{await (0,j.$I)(s,H);let e=await (0,j.PT)(s);B(e.length>0?e:[X]),E.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),E.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),J(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,j.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,j.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,j.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;E.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,j.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,j.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lR[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,j.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:()=>!0===a?O(!0):E.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lF,{isAddSSOModalVisible:I,isInstructionsModalVisible:M,handleAddSSOOk:()=>{O(!1),o.resetFields()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),O(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(P.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(y.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"IP Address"}),(0,r.jsx)(eb.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:K.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e}),(0,r.jsx)(ev.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(y.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(P.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(A.Z,{onFinish:el,children:[(0,r.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(L.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(A.Z.Item,{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(P.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(y.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lL.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lV=s(92858),lq=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=A.Z.useForm();return(0,r.jsxs)(A.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{align:"center",children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(A.Z.Item,{name:e.field_name,children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lK=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,j.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lq,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,j.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.jA)(l,"alerting",["slack"]):(0,j.jA)(l,"alerting",[])),E.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lB=s(86582);let{Title:lH,Paragraph:lJ}=G.default;console.log=function(){};var lG=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=A.Z.useForm(),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[_,Z]=(0,i.useState)(""),[N,w]=(0,i.useState)({}),[k,C]=(0,i.useState)([]),[O,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),H=e=>{k.includes(e)?C(k.filter(l=>l!==e)):C([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),C(e.active_alerts),Z(s),w(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,j.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,j.K_)(l,{environment_variables:s}),E.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,j.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),E.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eC.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(eC.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(eC.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(v.Z,{numItems:2,children:(0,r.jsx)(ek.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(eb.Z,{children:"Callback Name"})})}),(0,r.jsx)(e_.Z,{children:n.map((e,s)=>(0,r.jsxs)(eZ.Z,{className:"flex justify-between",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.name})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(S.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)}):(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:_})})]},l)})})]}),(0,r.jsx)(y.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,j.K_)(l,s)}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lK,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Email Settings"}),(0,r.jsxs)(S.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(ev.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(v.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(S.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"mt-2",children:l}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(P.Z,{title:"Add Logging Callback",visible:O,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(A.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lB.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(I.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(J.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lB.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(b.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(P.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(A.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lB.Z,{label:l,name:l,children:(0,r.jsx)(b.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lW=s(92414),lY=s(46030);let{Option:l$}=I.default;var lX=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(P.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(A.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,j.K_)(s,{router_settings:o}),a(o)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(ew.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(A.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lW.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lQ=s(33619);async function l0(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lQ.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});E.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l1={ttl:3600,lowest_latency_buffer:0},l2=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(N.Z,{children:"latency-based-routing"==l?(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(S.Z,{children:"No specific settings"})})]})};var l4=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(null),I={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,j.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,j.K_)(l,{router_settings:t}),o(t),E.ZP.success("Router settings updated successfully")}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},T=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,j.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,j.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,j.K_)(l,{router_settings:s})}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(eC.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(eC.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(k.Z,{children:"Router Settings"}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[l]})]}),(0,r.jsx)(ev.Z,{children:"routing_strategy"==l?(0,r.jsxs)(ew.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(J.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(J.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(J.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l2,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l1,paramExplanation:I})]}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Model Name"}),(0,r.jsx)(eb.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(e_.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:t}),(0,r.jsx)(ev.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{onClick:()=>l0(t,l),children:"Test Fallback"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(lX,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"}),(0,r.jsx)(eb.Z,{children:"Status"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(ev.Z,{children:"Integer"==e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(y.Z,{onClick:()=>T(e.field_name,l),children:"Update"}),(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l5=s(93142),l3=s(45246),l6=s(96473),l8=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l5.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(b.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(b.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l3.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(T.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l6.Z,{}),children:"Add Header"})]})};let{Option:l7}=I.default;var l9=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=A.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(P.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(A.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,j.Vt)(l,e),s(r)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l8,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},se=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,j.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,j.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),E.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Path"}),(0,r.jsx)(eb.Z,{children:"Target"}),(0,r.jsx)(eb.Z,{children:"Headers"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:n.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.path})}),(0,r.jsx)(ev.Z,{children:e.target}),(0,r.jsx)(ev.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l9,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=A.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call");let l=await (0,j.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),E.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(A.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ss=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=A.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call"),t(!0);let l=await (0,j.qI)(s,e);a(e=>e?[...e,l]:[l]),E.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(A.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},st=s(17906),sa=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,j.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;E.ZP.info("Request made"),await (0,j.NV)(l,e);let t=[...c];t.splice(s,1),m(t),E.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,j.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(y.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(sl,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(ss,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Budget ID"}),(0,r.jsx)(eb.Z,{children:"Max Budget"}),(0,r.jsx)(eb.Z,{children:"TPM"}),(0,r.jsx)(eb.Z,{children:"RPM"})]})}),(0,r.jsx)(e_.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.budget_id}),(0,r.jsx)(ev.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(ev.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(ev.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(eC.Z,{children:"Test it (Curl)"}),(0,r.jsx)(eC.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sr=s(77398),si=s.n(sr),sn=s(20016);async function so(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let sd=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return so(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sc=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sm=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sc(l)})},su=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sm,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(z.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(sd,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:e0(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(z.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],sh=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,j.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sx=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sp=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sg=["Internal User","Internal Viewer"],sj=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sf(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(si()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(si()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sg.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&g(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sg.includes(o)&&q(!0)},[o]);let B=(0,sn.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=si()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?si()(S).utc().format("YYYY-MM-DD HH:mm:ss"):si()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,j.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await sh(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(si()(N).format("MMM D, h:mm A")," - ").concat(si()(S).format("MMM D, h:mm A"));let e=si()(),l=si()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>g(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),g(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(si()().format("YYYY-MM-DDTHH:mm")),w(si()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eN,{columns:su,data:H,renderSubComponent:s_,getRowCanExpand:()=>!0})]})]})}function s_(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sj,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sx,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var sv=s(92699),sy=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(S.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eC.Z,{children:"LlamaIndex"}),(0,r.jsx)(eC.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sb=s(243),sZ=s(94263);async function sN(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lQ.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sw=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[w,k]=(0,i.useState)([]),C=(0,i.useRef)(null),A=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,j.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),f(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{A.current&&setTimeout(()=>{var e;null===(e=A.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){E.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{g&&await sN(i,(e,l)=>P("assistant",e,l),g,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=G.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)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eC.Z,{children:"Chat"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"API Key Source"}),(0,r.jsx)(I.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(_.Z,{className:"mx-2",children:[(0,r.jsx)(S.Z,{children:"Select Model:"}),(0,r.jsx)(I.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),N("custom"===e)},options:[...w,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{f(e)},500)}})]})]}),(0,r.jsx)(y.Z,{onClick:()=>{p([]),E.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ef.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{})})}),(0,r.jsxs)(e_.Z,{children:[x.map((e,l)=>(0,r.jsx)(eZ.Z,{children:(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sb.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(st.Z,{style:sZ.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{ref:A,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(b.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(y.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sS=s(19226),sk=s(45937),sC=s(92403),sI=s(28595),sA=s(68208),sE=s(9775),sP=s(41361),sO=s(37527),sT=s(12660),sM=s(88009),sL=s(48231),sD=s(41169),sR=s(44625),sF=s(57400),sU=s(55322);let{Sider:sz}=sS.default,sV=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sC.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sI.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sA.Z,{}),roles:sp},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sE.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sP.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sp},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sT.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sM.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sL.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sD.Z,{}),roles:sp,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sR.Z,{}),roles:sp},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sF.Z,{}),roles:sp}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sT.Z,{}),roles:sp},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp}]}];var sq=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sV.find(l=>l.page===e);if(l)return l.key;for(let l of sV)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sV.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sS.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sz,{theme:"light",width:220,children:(0,r.jsx)(sk.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sK=s(40278),sB=s(96889),sH=s(97765);console.log=function(){};var sJ=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,j.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let g=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sG=s(69907),sW=s(53003),sY=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let s$=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var sX=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,j.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,j.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),w((await (0,j.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,j.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,j.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,j.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,j.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,j.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,j.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,j.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,j.b1)(l,null,void 0,void 0),f,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,j.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(l)try{let e=await (0,j.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),s$(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(S.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(y.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mt-2",children:[(0,r.jsx)(eC.Z,{children:"All Up"}),s$(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eC.Z,{children:"Team Based Usage"}),(0,r.jsx)(eC.Z,{children:"Customer Usage"}),(0,r.jsx)(eC.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(eC.Z,{children:"Cost"}),(0,r.jsx)(eC.Z,{children:"Activity"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(S.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sJ,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Monthly Spend"}),(0,r.jsx)(sK.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top API Keys"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top Models"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sY.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Provider"}),(0,r.jsx)(eb.Z,{children:"Spend"})]})}),(0,r.jsx)(e_.Z,{children:T.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.provider}),(0,r.jsx)(ev.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"All Up"}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:e.model}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sB.Z,{data:P})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sK.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(_.Z,{numColSpan:2})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Time Range"}),(0,r.jsx)(sW.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Key"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(ek.Z,{className:"mt-4",children:(0,r.jsxs)(ef.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Customer"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Total Events"})]})}),(0,r.jsx)(e_.Z,{children:null==g?void 0:g.map((e,l)=>{var s;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.end_user}),(0,r.jsx)(ev.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(ev.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(_.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lY.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(J.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(S.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sK.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(_.Z,{numColSpan:2})]})]})]})]})})},sQ=s(51853);let s0=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s1=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s2=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sQ.Z,{className:"h-4 w-4"})})]})})})},s4=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s1(j.litellm_params)||{},_=s1(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s1(null==g?void 0:g.litellm_cache_params)||{},_=s1(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(S.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s2,{label:"Error Message",value:j.message}),(0,r.jsx)(s2,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s2,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s2,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s2,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s2,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s2,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s2,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s2,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s2,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s2,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s5=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(y.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(s0,{responseTimeMs:n})]}),s&&(0,r.jsx)(s4,{response:s})]})},s3=e=>{if(e)return e.toISOString().split("T")[0]};function s6(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s8=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[w,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[A,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&w&&((async()=>{p(await (0,j.zg)(l,s3(w.from),s3(w.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,j.zg)(l,s3(e),s3(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);f(s6(s)),b(s6(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,w,x]);let L=async()=>{try{E.ZP.info("Running cache health check..."),P("");let e=await (0,j.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Cache Analytics"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(v.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(sW.Z,{enableSelect:!0,value:w,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sK.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sK.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(s5,{accessToken:l,healthCheckResponse:A,runCachingHealthCheck:L})})]})]})},s7=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,j.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(S.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Guardrail Name"}),(0,r.jsx)(eb.Z,{children:"Mode"}),(0,r.jsx)(eb.Z,{children:"Status"})]})}),(0,r.jsx)(e_.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.guardrail_name}),(0,r.jsx)(ev.Z,{children:e.litellm_params.mode}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s9=new d.S;function te(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[_,v]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)([]),[w,S]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,C]=(0,i.useState)(!0),I=(0,n.useSearchParams)(),[A,E]=(0,i.useState)({data:[]}),[P,O]=(0,i.useState)(null),T=I.get("userID"),M=I.get("invitation_id"),[L,D]=(0,i.useState)(()=>I.get("page")||"api-keys"),[R,F]=(0,i.useState)(null);return(0,i.useEffect)(()=>{O((0,p.bW)())},[]),(0,i.useEffect)(()=>{if(!P)return;let e=(0,o.o)(P);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),F(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&D("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?C("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,j.K8)(e.auth_header_name)}},[P]),(0,i.useEffect)(()=>{R&&T&&e&&eu(T,e,R,N),R&&T&&e&&f(R,T,e,null,x),R&&lT(R,b)},[R,T,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s9,children:M?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(g,{userID:T,userRole:e,premiumUser:s,userEmail:m,setProxySettings:S,proxySettings:w}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sq,{setPage:e=>{let l=new URLSearchParams(I);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),D(e)},userRole:e,defaultSelectedKey:L})}),"api-keys"==L?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):"models"==L?(0,r.jsx)(lN,{userID:T,userRole:e,token:P,keys:_,accessToken:R,modelData:A,setModelData:E,premiumUser:s,teams:h}):"llm-playground"==L?(0,r.jsx)(sw,{userID:T,userRole:e,token:P,accessToken:R,disabledPersonalKeyCreation:a}):"users"==L?(0,r.jsx)(lI,{userID:T,userRole:e,token:P,keys:_,teams:h,accessToken:R,setKeys:v}):"teams"==L?(0,r.jsx)(lP,{teams:h,setTeams:x,searchParams:I,accessToken:R,userID:T,userRole:e,organizations:y}):"organizations"==L?(0,r.jsx)(lM,{organizations:y,setOrganizations:b,userModels:Z,accessToken:R,userRole:e,premiumUser:s}):"admin-panel"==L?(0,r.jsx)(lz,{setTeams:x,searchParams:I,accessToken:R,showSSOBanner:k,premiumUser:s}):"api_ref"==L?(0,r.jsx)(sy,{proxySettings:w}):"settings"==L?(0,r.jsx)(lG,{userID:T,userRole:e,accessToken:R,premiumUser:s}):"budgets"==L?(0,r.jsx)(sa,{accessToken:R}):"guardrails"==L?(0,r.jsx)(s7,{accessToken:R}):"general-settings"==L?(0,r.jsx)(l4,{userID:T,userRole:e,accessToken:R,modelData:A}):"model-hub"==L?(0,r.jsx)(sv.Z,{accessToken:R,publicPage:!1,premiumUser:s}):"caching"==L?(0,r.jsx)(s8,{userID:T,userRole:e,token:P,accessToken:R,premiumUser:s}):"pass-through-settings"==L?(0,r.jsx)(se,{userID:T,userRole:e,accessToken:R,modelData:A}):"logs"==L?(0,r.jsx)(sf,{userID:T,userRole:e,token:P,accessToken:R}):(0,r.jsx)(sX,{userID:T,userRole:e,token:P,accessToken:R,keys:_,premiumUser:s})]})]})})})}},3914:function(e,l,s){"use strict";function t(){let e=window.location.hostname,l=["/","/ui"],s=["Lax","Strict","None"],t=document.cookie.split("; "),a=/^token_\d+$/;t.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(t=>{l.forEach(l=>{document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,";"),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let a="None"===s?" Secure;":"";document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; SameSite=").concat(s,";").concat(a),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let l=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(l),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function r(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,l=document.cookie.split("; ").map(l=>{let s=l.split("="),t=s[0];if("token"===t)return null;let a=t.match(e);return a?{name:t,timestamp:parseInt(a[1],10),value:s.slice(1).join("=")}:null}).filter(e=>null!==e);return l.length>0?(l.sort((e,l)=>l.timestamp-e.timestamp),l[0].value):null}s.d(l,{bA:function(){return t},bW:function(){return r},uB:function(){return a}})}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js deleted file mode 100644 index 1e9a200f47..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return _}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002);function _(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));l&&l.split("=")[1]}("token");let s=l.get("invitation_id"),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(""),[Z,N]=(0,a.useState)(""),[w,S]=(0,a.useState)(null),[k,C]=(0,a.useState)(""),[I,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),C(l);let s=e.token,t=(0,g.o)(s);A(s),console.log("decoded:",t),v(t.key),console.log("decoded user email:",t.user_email),N(t.user_email),S(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",_,"token:",I,"formValues:",e),_&&I&&(e.user_email=Z,w&&s&&(0,p.m_)(_,s,w,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:Z,defaultValue:Z,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return s9}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=e=>{let{userID:l,userRole:s,premiumUser:t,proxySettings:a}=e,i=(null==a?void 0:a.PROXY_LOGOUT_URL)||"",n=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",s]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(t)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=i},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:n,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},g=s(19250);let j=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,g.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,g.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var f=s(49804),_=s(67101),v=s(20831),y=s(49566),b=s(87452),Z=s(88829),N=s(72208),w=s(84264),S=s(96761),k=s(29233),C=s(52787),I=s(13634),A=s(41021),E=s(51369),P=s(29967),O=s(73002),T=s(20577),M=s(56632);let L=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,g.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},D=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},R=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var F=s(15424),U=s(98074);let z=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,V=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},q=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return z(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var K=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),z(e,l)&&p.push({validator:async(e,l)=>{if(l&&!V(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(U.Z,{title:h,children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}):u;return t=z(e,l)?(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(C.default,{children:l.enum.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(T.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(y.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(y.Z,{placeholder:h||""}),(0,r.jsx)(I.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:q(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},B=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(C.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},H=s(57365),J=s(93192);function G(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=J.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(E.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(w.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{children:"Invitation Link"}),(0,r.jsx)(w.Z,{children:(0,r.jsx)(w.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(k.CopyToClipboard,{text:o(),onCopy:()=>A.ZP.success("Copied!"),children:(0,r.jsx)(v.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var W=s(30967),Y=s(28181),$=s(73879),X=s(3632),Q=s(15452),ee=s.n(Q),el=s(71157),es=s(44643),et=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.g)(l);j(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let y=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,g.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,g.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(E.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=new Blob([ee().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(W.Z,{beforeUpload:e=>(x(null),ee().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(X.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(v.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(w.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(w.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(es.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(w.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)(Y.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(k.CopyToClipboard,{text:l.invitation_link,onCopy:()=>A.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([ee().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:ea}=C.default;var er=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=I.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[k,P]=(0,i.useState)(!1),[T,L]=(0,i.useState)(null),R=(0,n.useRouter)(),[z,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.So)(s,l,"any"),t=[];for(let l=0;l{R&&V(new URL("/",window.location.href).toString())},[R]);let q=async e=>{var t,a,r;try{A.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,g.Ov)(s,null,e);console.log("user create Response:",a),j(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};L(e),P(!0)}else(0,g.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,L(e),P(!0)});A.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";A.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(et,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(E.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),j(null),u.resetFields()},children:[(0,r.jsx)(w.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(U.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(F.Z,{})})]}),name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(I.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(G,{isInvitationLinkModalVisible:k,setIsInvitationLinkModalVisible:P,baseUrl:z,invitationLinkData:T})]})},ei=s(7310),en=s.n(ei);let{Option:eo}=C.default,ed=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},ec=(e,l)=>R(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),em=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,g.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eu=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[L,R]=(0,i.useState)([]),[z,V]=(0,i.useState)([]),[q,H]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ed(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[ei,eu]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&em(l,a,n,R)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,g.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(A.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,g.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),j(m.soft_budget),A.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),A.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(ec($,L)),c.setFieldValue("models",[])},[$,L]);let ef=async e=>{if(!e){eu([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,g.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eu(s)}catch(e){console.error("Error fetching users:",e),A.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(en()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(E.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(I.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(U.Z,{title:"Select who will own this API key",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(P.ZP.Group,{onChange:e=>H(e.target.value),value:q,children:[(0,r.jsx)(P.ZP,{value:"you",children:"You"}),(0,r.jsx)(P.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(P.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(U.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:ei,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(O.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(U.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(B,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(U.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),z.map(e=>(0,r.jsx)(eo,{value:e,children:D(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(U.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(U.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(U.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(y.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(U.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(U.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:g.H2?"".concat(g.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(F.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(K,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(E.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(er,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(E.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Save your Key"}),(0,r.jsx)(f.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)(f.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(w.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:h})}),(0,r.jsx)(k.CopyToClipboard,{text:h,onCopy:()=>{A.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(w.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=s(7366),ex=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,g.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},ep=s(71594),eg=s(24525),ej=s(21626),ef=s(97214),e_=s(28241),ev=s(58834),ey=s(69552),eb=s(71876);function eZ(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,ep.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,eg.sC)(),getExpandedRowModel:(0,eg.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:n?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var eN=s(27281),ew=s(41649),eS=s(12514),ek=s(12485),eC=s(18135),eI=s(35242),eA=s(29706),eE=s(77991),eP=s(10900),eO=s(23628),eT=s(74998);function eM(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=I.Z.useForm(),[h,x]=(0,i.useState)([]),p=ec(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,g.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let j={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(I.Z,{form:u,onFinish:n,initialValues:j,layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(C.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(C.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(C.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsx)(I.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(M.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(v.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]})}function eL(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let j=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,g.s0)(a,l.token,e);d(s.key),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key"),p(!1)}}},b=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(E.Z,{title:"Regenerate API Key",open:s,onCancel:b,footer:o?[(0,r.jsx)(v.Z,{onClick:b,children:"Close"},"close")]:[(0,r.jsx)(v.Z,{onClick:b,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:j,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(k.CopyToClipboard,{text:o,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(I.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eD(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=I.Z.useForm(),[p,j]=(0,i.useState)(!1),[f,y]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(w.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),A.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,g.Nc)(o,e),A.ZP.success("Key updated successfully"),h(!1)}catch(e){A.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,g.I1)(o,n.token),A.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),A.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{icon:eO.Z,variant:"secondary",onClick:()=>y(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>j(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eL,{selectedToken:n,visible:f,onClose:()=>y(!1),accessToken:o}),p&&(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)(v.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>j(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(w.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(v.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eM,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(w.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(w.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(w.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(w.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(w.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(w.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(w.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eR=s(87908),eF=s(82422),eU=s(2356),ez=s(44633),eV=s(86462),eq=s(3837),eK=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let I=(0,i.useCallback)(en()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eF.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),T=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(v.Z,{icon:eU.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(eS.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(O.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==T?void 0:T.label)||m,f?(0,r.jsx)(ez.Z,{className:"h-4 w-4"}):(0,r.jsx)(eV.Z,{className:"h-4 w-4"})]})}),(null==T?void 0:T.isSearchable)?(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search ".concat(T.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),I(e,T)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:y,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eR.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(O.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(M.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eq.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(O.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(O.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eB=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eH=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eJ(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[j,f]=(0,i.useState)(null),[_,y]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,g.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.getValue(),children:(0,r.jsx)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eB(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eH(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:j?(0,r.jsx)(eD,{keyId:j,onClose:()=>f(null),keyData:l.find(e=>e.token===j),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eK,{options:w,onApplyFilters:e=>{if(y({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{y({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eZ,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eG=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,C]=(0,i.useState)(null),[P,O]=(0,i.useState)(null),[M,D]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ex({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=I.Z.useForm(),[em,eu]=(0,i.useState)(null),[ep,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await L(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,g.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),C(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){A.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,g.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eJ,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),b&&(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)(v.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),C(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(E.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(v.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(I.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(v.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(E.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(v.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(k.CopyToClipboard,{text:ei,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eW=s(12011);console.log=function(){},console.log("isLocal:",!1);var eY=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:p}=e,[v,y]=(0,i.useState)(null),[b,Z]=(0,i.useState)(null),N=(0,n.useSearchParams)(),w=function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"),S=N.get("invitation_id"),[k,C]=(0,i.useState)(null),[I,A]=(0,i.useState)(null),[E,P]=(0,i.useState)([]),[O,T]=(0,i.useState)(null),[M,L]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(w){let e=(0,o.o)(w);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),C(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&k&&s&&!a&&!v){let e=sessionStorage.getItem("userModels"+l);e?P(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(b))),(async()=>{try{let e=await (0,g.g)(k);T(e);let t=await (0,g.Br)(k,l,s,!1,null,null);y(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(v))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,g.So)(k,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),P(a),console.log("userModels:",E),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),j(k,l,s,b,u))}},[l,w,k,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(b),", accessToken: ").concat(k,", userID: ").concat(l,", userRole: ").concat(s)),k&&(console.log("fetching teams"),j(k,l,s,b,u))},[b]),(0,i.useEffect)(()=>{if(null!==a&&null!=M&&null!==M.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))M.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===M.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),A(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;A(e)}},[M]),null!=S)return(0,r.jsx)(eW.default,{});if(null==l||null==w){let e="/sso/key/generate";return document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Full URL:",e),window.location.href=e,null}if(null==k)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=J.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",M),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(f.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eu,{userID:l,team:M,teams:t,userRole:s,accessToken:k,data:a,setData:h},M?M.team_id:null),(0,r.jsx)(eG,{userID:l,userRole:s,accessToken:k,selectedTeam:M||null,setSelectedTeam:L,data:a,setData:h,premiumUser:x,teams:t,currentOrg:b,setCurrentOrg:Z,organizations:p})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let e$={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eX={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},eQ=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eX[e],displayName:e}}let l=Object.keys(e$).find(l=>e$[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eX[s],displayName:s}},e0=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e1=(e,l)=>{console.log("Provider key: ".concat(e));let s=e$[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e2=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=e$[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=e$[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,g.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){A.ZP.error("Failed to create model: "+e,10)}},e4=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e5=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,g.um)(l,i),A.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e3=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=I.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(E.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(I.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},e6=s(47323),e8=s(53410),e7=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=I.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),A.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){A.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(C.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(E.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(I.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(w.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(C.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(O.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},e9=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,g.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(en()((e,l)=>f(e,l),300),[]),v=(e,l)=>{j(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(E.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(I.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(I.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:(0,r.jsxs)(U.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},le=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,j]=(0,i.useState)(!1),[f]=I.Z.useForm(),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[k,E]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.Xm)(a,s);u(e)}catch(e){A.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.cu)(a,s,l),A.ZP.success("Team member added successfully"),j(!1),f.resetFields(),L()}catch(e){A.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},z=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.sN)(a,s,l),A.ZP.success("Team member updated successfully"),b(!1),L()}catch(e){A.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,g.Lp)(a,s,e),A.ZP.success("Team member removed successfully"),L()}catch(e){A.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,g.Gh)(a,t),A.ZP.success("Team settings updated successfully"),E(!1),L()}catch(e){A.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:K.team_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"User Email"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>V(e),icon:eT.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(v.Z,{onClick:()=>j(!0),children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Team Settings"}),P&&!k&&(0,r.jsx)(v.Z,{onClick:()=>E(!0),children:"Edit Settings"})]}),k?(0,r.jsxs)(I.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(M.Z,{type:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>E(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(ew.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e7,{visible:y,onCancel:()=>b(!1),onSubmit:z,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(e9,{isVisible:p,onCancel:()=>j(!1),onSubmit:R,accessToken:a})]})},ll=s(30150);function ls(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,j,f,b,Z,N,k,C;let{modelId:E,onClose:P,modelData:T,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=I.Z.useForm(),[V,q]=(0,i.useState)(T),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:E}};await (0,g.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),A.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),A.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!T)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(w.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,g.Og)(M,E),A.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),A.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(S.Z,{children:["Public Model Name: ",e4(T)]}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-6",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,r.jsx)("img",{src:eQ(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(S.Z,{children:T.provider||"Not Set"})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(S.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,r.jsxs)(w.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(I.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*T.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*T.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*T.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*T.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(I.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(I.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=V.litellm_params)||void 0===j?void 0:j.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(I.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(b=V.litellm_params)||void 0===b?void 0:b.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(I.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(k=V.litellm_params)||void 0===k?void 0:k.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(v.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(O.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(O.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var lt=s(67960),la=s(47451),lr=s(69410),li=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=I.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(I.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(I.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(y.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(C.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(y.Z,{placeholder:t(l)})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(I.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},ln=()=>{let e=I.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=I.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=I.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(y.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)(Y.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:lo}=J.default;var ld=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(I.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(y.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(y.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(y.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(W.Z,{...s,children:(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(X.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(C.default,{placeholder:"Select API Base",children:[(0,r.jsx)(C.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(C.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(y.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(y.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(I.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(lo,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(y.Z,{placeholder:"sk-",type:"password"})})]})},lc=s(63709),lm=s(90464);let{Link:lu}=J.default;var lh=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=I.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(b.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(I.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(B,{teams:t})}),(0,r.jsx)(I.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lc.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(I.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}):(0,r.jsx)(I.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)(I.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lc.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(I.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(la.Z,{className:"mb-4",children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(I.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lx,Link:lp}=J.default;var lg=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lx,{level:2,children:"Add new model"}),(0,r.jsx)(lt.Z,{children:(0,r.jsx)(I.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(C.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eX[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(li,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(ln,{}),(0,r.jsx)(ld,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lh,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(U.Z,{title:"Get help on our github",children:(0,r.jsx)(J.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lj=s(49084);function lf(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let l_=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:eQ(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(U.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:lv,Link:ly}=J.default,lb={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lZ=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[k,C]=(0,i.useState)([]),[E,P]=(0,i.useState)(a.OpenAI),[O,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[G,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[ew,eP]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==ew?void 0:ew.token;void 0===r&&(r=null);let i=eT;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,g.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,g.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,g.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,g.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,g.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,g.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[ew,eT]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,g.K_)(l,{router_settings:{model_group_retry_policy:ex}}),A.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),A.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let j=await (0,g.hy)(l);C(j);let f=await (0,g.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,g.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,g.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,g.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,g.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eT),S=await (0,g.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,g.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,g.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,g.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,g.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==j&&a(),eJ()},[l,s,t,n,j,y]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(j)),null!=j&&"object"==typeof j&&e in j)?j[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e8=l.litellm_params)||void 0===e8?void 0:e8.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=J.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 e7=async()=>{try{A.ZP.info("Running health check..."),M("");let e=await (0,g.EY)(l);M(e)}catch(e){console.error("Error running health check:",e),M("Error running health check")}};w.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{eP(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(H.Z,{value:String(l),disabled:!0,onClick:()=>{eP(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(H.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(E)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===E);return(e9&&k.find(e=>e.name===e$[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(le,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(ls,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"All Models"}),(0,r.jsx)(ek.Z,{children:"Add Model"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(ek.Z,{children:"Model Analytics"}),(0,r.jsx)(ek.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[y&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",y]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(H.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(lf,{columns:l_(m,ez,eB,e4,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e3,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e5(e,l,D,F)})]}),(0,r.jsx)(eA.Z,{className:"h-full",children:(0,r.jsx)(lg,{form:p,handleOk:()=>{p.validateFields().then(e=>{e2(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:E,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e1(e,j);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e0,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?A.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&A.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(v.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(S.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(w.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lb&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lb).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(T.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(v.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lN=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=I.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(E.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(I.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lw=s(15731);let lS=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(U.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(U.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lw.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(_.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(ew.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(ew.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lk(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lC=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(1),[_,y]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[E,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(E&&l)try{if(await (0,g.Eb)(l,[E]),A.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==E);h(e)}}catch(e){console.error("Error deleting user:",e),A.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,g.pf)(l,e,null),A.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(j));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,g.Br)(l,null,a,!0,j,25);sessionStorage.setItem("userList_".concat(j),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,g.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,j]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lS(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(er,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||j<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||j>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lk,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lN,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",E]})]})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(v.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lI=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,g.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,g.cu)(l,e,{user_id:s,role:"user"}),A.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),A.ZP.error("Failed to join team")}};return(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Description"}),(0,r.jsx)(ey.Z,{children:"Members"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsxs)(ef.Z,{children:[t.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.team_alias})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.description||"No description available"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ew.Z,{size:"xs",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(w.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lA=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,R(s,l)};var lE=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&j(t,n,o,u,a),eP()},[c]);let[S]=I.Z.useForm(),[k]=I.Z.useForm(),{Title:P,Paragraph:R}=J.default,[z,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[G,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lA(x,ea);console.log("models: ".concat(e)),em(e),S.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,g.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},eZ=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,g.rs)(t,eo),j(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await L(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));A.ZP.info("Creating Team");let o=await (0,g.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),A.ZP.success("Team created"),S.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),A.ZP.error("Error creating the team: "+e,20)}},eP=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:G?(0,r.jsx)(le,{teamId:G,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===G)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Your Teams"}),(0,r.jsx)(ek.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eP})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(w.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Team ID"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Organization"}),(0,r.jsx)(ey.Z,{children:"Info"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)})},l))}):null}),(0,r.jsx)(e_.Z,{children:e.organization_id}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(e_.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>eg(e.team_id),icon:eT.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(v.Z,{onClick:eZ,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(E.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),S.resetFields()},onCancel:()=>{Q(!1),S.resetFields()},children:(0,r.jsxs)(I.Z,{form:S,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(C.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{S.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(C.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(y.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lI,{accessToken:t,userID:n})})]})]})})},lP=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[k,E]=(0,i.useState)(null),P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.t$)(a,s);u(e)}catch(e){A.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.vh)(a,s,l),A.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.LY)(a,s,l),A.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,g.Sb)(a,s,e.user_id),A.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,g.VA)(a,l),A.ZP.success("Organization settings updated successfully"),f(!1),L()}catch(e){A.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:m.organization_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Created At"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{E({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(v.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Organization Settings"}),P&&!j&&(0,r.jsx)(v.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,r.jsxs)(I.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(M.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(e9,{isVisible:y,onCancel:()=>b(!1),onSubmit:R,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e7,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:k,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lO=async(e,l)=>{l(await (0,g.r6)(e))};var lT=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[k,P]=(0,i.useState)(!1),[O]=I.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lO(a,m)},[l,a]);let L=e=>{e&&(S(e),Z(!0))},R=async()=>{if(N&&a)try{await (0,g.cq)(a,N),A.ZP.success("Organization deleted successfully"),Z(!1),S(null),lO(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,g.H1)(a,e),P(!1),O.resetFields(),lO(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lP,{organizationId:h,onClose:()=>{x(null),j(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(ek.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(w.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Organization ID"}),(0,r.jsx)(ey.Z,{children:"Organization Name"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ey.Z,{children:"Info"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.organization_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{children:e.organization_alias}),(0,r.jsx)(e_.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{children:e.spend}),(0,r.jsx)(e_.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)},l))})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(e_.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{x(e.organization_id),j(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>L(e.organization_id),icon:eT.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>P(!0),children:"+ Create New Organization"}),(0,r.jsx)(E.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{P(!1),O.resetFields()},children:(0,r.jsxs)(I.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(v.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),b?(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 Organization"}),(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 organization?"})})]})})}),(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)(v.Z,{onClick:R,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),S(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(w.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lM=s(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lR=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lD[e];return l?l.fields.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(M.Z.Password,{}):(0,r.jsx)(y.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(I.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(C.default,{children:Object.entries(lL).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(I.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(E.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(w.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)(O.ZP,{onClick:n,children:"Done"})})]})]})};let lF=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lU=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=I.Z.useForm(),[d]=I.Z.useForm(),{Title:c,Paragraph:m}=J.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[P,T]=(0,i.useState)(!1),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,G]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lF(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){A.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,g.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),A.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,g.eH)(s,e.ip);let l=await (0,g.PT)(s);B(l),A.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),A.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{G(e),q(!0)},et=async()=>{if(H&&s)try{await (0,g.$I)(s,H);let e=await (0,g.PT)(s);B(e.length>0?e:[X]),A.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),A.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),G(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,g.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,g.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,g.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;A.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,g.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,g.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,g.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:()=>!0===a?T(!0):A.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lR,{isAddSSOModalVisible:P,isInstructionsModalVisible:L,handleAddSSOOk:()=>{T(!1),o.resetFields()},handleAddSSOCancel:()=>{T(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),T(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(E.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(v.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"IP Address"}),(0,r.jsx)(ey.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:K.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e}),(0,r.jsx)(e_.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(v.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(E.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(I.Z,{onFinish:el,children:[(0,r.jsx)(I.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(M.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(I.Z.Item,{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(E.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(v.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lM.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lz=s(92858),lV=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=I.Z.useForm();return(0,r.jsxs)(I.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{align:"center",children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(I.Z.Item,{name:e.field_name,children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(I.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lq=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,g.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lV,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,g.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,g.jA)(l,"alerting",["slack"]):(0,g.jA)(l,"alerting",[])),A.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lK=s(86582);let{Title:lB,Paragraph:lH}=J.default;console.log=function(){};var lJ=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=I.Z.useForm(),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)(""),[N,S]=(0,i.useState)({}),[k,P]=(0,i.useState)([]),[T,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),J=e=>{k.includes(e)?P(k.filter(l=>l!==e)):P([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),P(e.active_alerts),Z(s),S(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,g.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,g.K_)(l,{environment_variables:s}),A.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,g.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),A.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(ek.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(ek.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(ek.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(_.Z,{numItems:2,children:(0,r.jsx)(eS.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ey.Z,{children:"Callback Name"})})}),(0,r.jsx)(ef.Z,{children:n.map((e,s)=>(0,r.jsxs)(eb.Z,{className:"flex justify-between",children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(w.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)}):(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:b})})]},l)})})]}),(0,r.jsx)(v.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,g.K_)(l,s)}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lq,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Email Settings"}),(0,r.jsxs)(w.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(e_.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(_.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(w.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"mt-2",children:l}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(E.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(I.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lK.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(C.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(H.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lK.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(y.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(E.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(I.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lK.Z,{label:l,name:l,children:(0,r.jsx)(y.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lG=s(92414),lW=s(46030);let{Option:lY}=C.default;var l$=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(E.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(I.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,g.K_)(s,{router_settings:o}),a(o)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eN.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(I.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lG.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lX=s(33619);async function lQ(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lX.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});A.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l0={ttl:3600,lowest_latency_buffer:0},l1=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(Z.Z,{children:"latency-based-routing"==l?(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(w.Z,{children:"No specific settings"})})]})};var l2=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=I.Z.useForm(),[j,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[k,C]=(0,i.useState)(null),E={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,g.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,g.K_)(l,{router_settings:t}),o(t),A.ZP.success("Router settings updated successfully")}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},M=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,g.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,g.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,g.K_)(l,{router_settings:s})}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(ek.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(ek.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(S.Z,{children:"Router Settings"}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:E[l]})]}),(0,r.jsx)(e_.Z,{children:"routing_strategy"==l?(0,r.jsxs)(eN.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(H.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(H.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(H.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l1,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l0,paramExplanation:E})]}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Model Name"}),(0,r.jsx)(ey.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(ef.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:t}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{onClick:()=>lQ(t,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(l$,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"}),(0,r.jsx)(ey.Z,{children:"Status"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(e_.Z,{children:"Integer"==e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(v.Z,{onClick:()=>M(e.field_name,l),children:"Update"}),(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l4=s(93142),l5=s(45246),l3=s(96473),l6=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l4.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(y.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(y.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l5.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(O.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l3.Z,{}),children:"Add Header"})]})};let{Option:l8}=C.default;var l7=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=I.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(E.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(I.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,g.Vt)(l,e),s(r)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l6,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},l9=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,g.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,g.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),A.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Path"}),(0,r.jsx)(ey.Z,{children:"Target"}),(0,r.jsx)(ey.Z,{children:"Headers"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:n.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.path})}),(0,r.jsx)(e_.Z,{children:e.target}),(0,r.jsx)(e_.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l7,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},se=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=I.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call");let l=await (0,g.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),A.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(I.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=I.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call"),t(!0);let l=await (0,g.qI)(s,e);a(e=>e?[...e,l]:[l]),A.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(I.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},ss=s(17906),st=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,g.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;A.ZP.info("Request made"),await (0,g.NV)(l,e);let t=[...c];t.splice(s,1),m(t),A.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,g.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(v.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(se,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(sl,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Budget ID"}),(0,r.jsx)(ey.Z,{children:"Max Budget"}),(0,r.jsx)(ey.Z,{children:"TPM"}),(0,r.jsx)(ey.Z,{children:"RPM"})]})}),(0,r.jsx)(ef.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.budget_id}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(e_.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(e_.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(ek.Z,{children:"Test it (Curl)"}),(0,r.jsx)(ek.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sa=s(77398),sr=s.n(sa),si=s(20016);async function sn(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let so=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return sn(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sd=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sc=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sd(l)})},sm=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sc,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(U.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(so,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:eQ(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(U.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],su=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,g.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sh=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sx=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sp=["Internal User","Internal Viewer"],sg=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sj(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(sr()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(sr()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sp.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sp.includes(o)&&q(!0)},[o]);let B=(0,si.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=sr()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?sr()(S).utc().format("YYYY-MM-DD HH:mm:ss"):sr()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,g.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await su(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(sr()(N).format("MMM D, h:mm A")," - ").concat(sr()(S).format("MMM D, h:mm A"));let e=sr()(),l=sr()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>j(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),j(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(sr()().format("YYYY-MM-DDTHH:mm")),w(sr()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eZ,{columns:sm,data:H,renderSubComponent:sf,getRowCanExpand:()=>!0})]})]})}function sf(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sg,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sh,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var s_=s(92699),sv=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(w.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(ek.Z,{children:"LlamaIndex"}),(0,r.jsx)(ek.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sy=s(243),sb=s(94263);async function sZ(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lX.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sN=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[j,b]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[S,k]=(0,i.useState)([]),I=(0,i.useRef)(null),E=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,g.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),b(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{E.current&&setTimeout(()=>{var e;null===(e=E.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){A.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{j&&await sZ(i,(e,l)=>P("assistant",e,l),j,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=J.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)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsx)(eI.Z,{children:(0,r.jsx)(ek.Z,{children:"Chat"})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"API Key Source"}),(0,r.jsx)(C.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(f.Z,{className:"mx-2",children:[(0,r.jsx)(w.Z,{children:"Select Model:"}),(0,r.jsx)(C.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),b(e),N("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{b(e)},500)}})]})]}),(0,r.jsx)(v.Z,{onClick:()=>{p([]),A.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ej.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsxs)(ef.Z,{children:[x.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sy.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(ss.Z,{style:sb.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{ref:E,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(y.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(v.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sw=s(19226),sS=s(45937),sk=s(92403),sC=s(28595),sI=s(68208),sA=s(9775),sE=s(41361),sP=s(37527),sO=s(12660),sT=s(88009),sM=s(48231),sL=s(41169),sD=s(44625),sR=s(57400),sF=s(55322);let{Sider:sU}=sw.default,sz=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sk.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sC.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sI.Z,{}),roles:sx},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sA.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sE.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sx},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sO.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sT.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sM.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sL.Z,{}),roles:sx,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sD.Z,{}),roles:sx},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sR.Z,{}),roles:sx}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sO.Z,{}),roles:sx},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx}]}];var sV=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sz.find(l=>l.page===e);if(l)return l.key;for(let l of sz)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sz.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sw.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sU,{theme:"light",width:220,children:(0,r.jsx)(sS.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sq=s(40278),sK=s(96889),sB=s(97765);console.log=function(){};var sH=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,g.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let j=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",j]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sJ=s(69907),sG=s(53003),sW=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let sY=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var s$=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,k]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[J,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,g.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,g.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),y(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),k((await (0,g.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,g.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,g.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,g.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,g.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,g.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,g.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,g.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>k(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,g.b1)(l,null,void 0,void 0),y,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,g.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},eZ=async()=>{if(l)try{let e=await (0,g.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",J),eo(),ed(),ec(),em(),eg(),eZ(),sY(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==J?void 0:J.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(w.Z,{className:"mt-4",children:["SpendLogs in DB has ",J.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(v.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mt-2",children:[(0,r.jsx)(ek.Z,{children:"All Up"}),sY(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ek.Z,{children:"Team Based Usage"}),(0,r.jsx)(ek.Z,{children:"Customer Usage"}),(0,r.jsx)(ek.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(ek.Z,{children:"Cost"}),(0,r.jsx)(ek.Z,{children:"Activity"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(w.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sH,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Monthly Spend"}),(0,r.jsx)(sq.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top API Keys"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top Models"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Provider"}),(0,r.jsx)(ey.Z,{children:"Spend"})]})}),(0,r.jsx)(ef.Z,{children:T.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.provider}),(0,r.jsx)(e_.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"All Up"}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:e.model}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sK.Z,{data:P})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sq.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(f.Z,{numColSpan:2})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Time Range"}),(0,r.jsx)(sG.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Key"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(eS.Z,{className:"mt-4",children:(0,r.jsxs)(ej.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Customer"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Total Events"})]})}),(0,r.jsx)(ef.Z,{children:null==j?void 0:j.map((e,l)=>{var s;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(e_.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sG.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(f.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lW.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(H.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(w.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sq.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(f.Z,{numColSpan:2})]})]})]})]})})},sX=s(51853);let sQ=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s0=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s1=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sX.Z,{className:"h-4 w-4"})})]})})})},s2=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s0(j.litellm_params)||{},_=s0(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s0(null==g?void 0:g.litellm_cache_params)||{},_=s0(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(w.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s1,{label:"Error Message",value:j.message}),(0,r.jsx)(s1,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s1,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s1,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s1,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s1,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s1,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s1,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s1,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s1,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s1,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s4=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(v.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(sQ,{responseTimeMs:n})]}),s&&(0,r.jsx)(s2,{response:s})]})},s5=e=>{if(e)return e.toISOString().split("T")[0]};function s3(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s6=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,v]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[S,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[E,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&S&&((async()=>{p(await (0,g.zg)(l,s5(S.from),s5(S.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,g.zg)(l,s5(e),s5(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);v(s3(s)),b(s3(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,S,x]);let L=async()=>{try{A.ZP.info("Running cache health check..."),P("");let e=await (0,g.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Cache Analytics"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(_.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(sG.Z,{enableSelect:!0,value:S,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:j})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sq.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sq.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(s4,{accessToken:l,healthCheckResponse:E,runCachingHealthCheck:L})})]})]})},s8=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,g.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(w.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Guardrail Name"}),(0,r.jsx)(ey.Z,{children:"Mode"}),(0,r.jsx)(ey.Z,{children:"Status"})]})}),(0,r.jsx)(ef.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.guardrail_name}),(0,r.jsx)(e_.Z,{children:e.litellm_params.mode}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s7=new d.S;function s9(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[f,_]=(0,i.useState)(null),[v,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,k]=(0,i.useState)(!0),C=(0,n.useSearchParams)(),[I,A]=(0,i.useState)({data:[]}),[E,P]=(0,i.useState)(null),O=C.get("userID"),T=C.get("invitation_id"),[M,L]=(0,i.useState)(()=>C.get("page")||"api-keys"),[D,R]=(0,i.useState)(null);return(0,i.useEffect)(()=>{P(function(e){let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"))},[]),(0,i.useEffect)(()=>{if(!E)return;let e=(0,o.o)(E);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),R(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&L("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?k("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,g.K8)(e.auth_header_name)}},[E]),(0,i.useEffect)(()=>{D&&O&&e&&em(O,e,D,Z),D&&O&&e&&j(D,O,e,null,x),D&&lO(D,y)},[D,O,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s7,children:T?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(p,{userID:O,userRole:e,premiumUser:s,setProxySettings:w,proxySettings:N}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sV,{setPage:e=>{let l=new URLSearchParams(C);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),L(e)},userRole:e,defaultSelectedKey:M})}),"api-keys"==M?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):"models"==M?(0,r.jsx)(lZ,{userID:O,userRole:e,token:E,keys:f,accessToken:D,modelData:I,setModelData:A,premiumUser:s,teams:h}):"llm-playground"==M?(0,r.jsx)(sN,{userID:O,userRole:e,token:E,accessToken:D,disabledPersonalKeyCreation:a}):"users"==M?(0,r.jsx)(lC,{userID:O,userRole:e,token:E,keys:f,teams:h,accessToken:D,setKeys:_}):"teams"==M?(0,r.jsx)(lE,{teams:h,setTeams:x,searchParams:C,accessToken:D,userID:O,userRole:e,organizations:v}):"organizations"==M?(0,r.jsx)(lT,{organizations:v,setOrganizations:y,userModels:b,accessToken:D,userRole:e,premiumUser:s}):"admin-panel"==M?(0,r.jsx)(lU,{setTeams:x,searchParams:C,accessToken:D,showSSOBanner:S,premiumUser:s}):"api_ref"==M?(0,r.jsx)(sv,{proxySettings:N}):"settings"==M?(0,r.jsx)(lJ,{userID:O,userRole:e,accessToken:D,premiumUser:s}):"budgets"==M?(0,r.jsx)(st,{accessToken:D}):"guardrails"==M?(0,r.jsx)(s8,{accessToken:D}):"general-settings"==M?(0,r.jsx)(l2,{userID:O,userRole:e,accessToken:D,modelData:I}):"model-hub"==M?(0,r.jsx)(s_.Z,{accessToken:D,publicPage:!1,premiumUser:s}):"caching"==M?(0,r.jsx)(s6,{userID:O,userRole:e,token:E,accessToken:D,premiumUser:s}):"pass-through-settings"==M?(0,r.jsx)(l9,{userID:O,userRole:e,accessToken:D,modelData:I}):"logs"==M?(0,r.jsx)(sj,{userID:O,userRole:e,token:E,accessToken:D}):(0,r.jsx)(s$,{userID:O,userRole:e,token:E,accessToken:D,keys:f,premiumUser:s})]})]})})})}}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_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 ae2e51152b..07624d4899 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 32025bae5b..0830197521 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-e28453cd004ff93c.js"],"default",1] +3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-a006114359094d34.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/_experimental/out/model_hub.txt b/litellm/proxy/_experimental/out/model_hub.txt index 2bef2383df..54a3766fb8 100644 --- a/litellm/proxy/_experimental/out/model_hub.txt +++ b/litellm/proxy/_experimental/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","418","static/chunks/app/model_hub/page-6f97b95f1023b0e9.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html new file mode 100644 index 0000000000..3b4d5d430f --- /dev/null +++ b/litellm/proxy/_experimental/out/onboarding.html @@ -0,0 +1 @@ +LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/onboarding.txt b/litellm/proxy/_experimental/out/onboarding.txt index ec0568e731..e05b041088 100644 --- a/litellm/proxy/_experimental/out/onboarding.txt +++ b/litellm/proxy/_experimental/out/onboarding.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-f2e9aa9e77b66520.js"],"default",1] +3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-8ba945cf183c937c.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/404.html b/ui/litellm-dashboard/out/404.html index 8bea7c8210..6658255bbc 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/sW550-yvC4l9ZFA0scEUc/_buildManifest.js b/ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js rename to ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js b/ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js rename to ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js new file mode 100644 index 0000000000..a22da3c6fe --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,t,n){Promise.resolve().then(n.bind(n,12011))},12011:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return g}});var o=n(57437),a=n(2265),c=n(99376),s=n(20831),i=n(94789),l=n(12514),r=n(49804),u=n(67101),m=n(84264),d=n(49566),h=n(96761),p=n(84566),f=n(19250),x=n(14474),k=n(13634),_=n(73002),j=n(3914);function g(){let[e]=k.Z.useForm(),t=(0,c.useSearchParams)();(0,j.bW)();let n=t.get("invitation_id"),[g,w]=(0,a.useState)(null),[S,Z]=(0,a.useState)(""),[b,N]=(0,a.useState)(""),[v,y]=(0,a.useState)(null),[T,E]=(0,a.useState)(""),[C,U]=(0,a.useState)("");return(0,a.useEffect)(()=>{n&&(0,f.W_)(n).then(e=>{let t=e.login_url;console.log("login_url:",t),E(t);let n=e.token,o=(0,x.o)(n);U(n),console.log("decoded:",o),w(o.key),console.log("decoded user email:",o.user_email),N(o.user_email),y(o.user_id)})},[n]),(0,o.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,o.jsxs)(l.Z,{children:[(0,o.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,o.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,o.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,o.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,o.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,o.jsx)(r.Z,{children:"SSO is under the Enterprise Tirer."}),(0,o.jsx)(r.Z,{children:(0,o.jsx)(s.Z,{variant:"primary",className:"mb-2",children:(0,o.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,o.jsxs)(k.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",C,"formValues:",e),g&&C&&(e.user_email=b,v&&n&&(0,f.m_)(g,n,v,e.password).then(e=>{var t;let n="/ui/";n+="?userID="+((null===(t=e.data)||void 0===t?void 0:t.user_id)||e.user_id),(0,j.uB)(C),console.log("redirecting to:",n),window.location.href=n}))},children:[(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(k.Z.Item,{label:"Email Address",name:"user_email",children:(0,o.jsx)(d.Z,{type:"email",disabled:!0,value:b,defaultValue:b,className:"max-w-md"})}),(0,o.jsx)(k.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,o.jsx)(d.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,o.jsx)("div",{className:"mt-10",children:(0,o.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},3914:function(e,t,n){"use strict";function o(){let e=window.location.hostname,t=["/","/ui"],n=["Lax","Strict","None"],o=document.cookie.split("; "),a=/^token_\d+$/;o.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(o=>{t.forEach(t=>{document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,";"),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,";"),n.forEach(n=>{let a="None"===n?" Secure;":"";document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; SameSite=").concat(n,";").concat(a),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,"; SameSite=").concat(n,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let t=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(t),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function c(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,t=document.cookie.split("; ").map(t=>{let n=t.split("="),o=n[0];if("token"===o)return null;let a=o.match(e);return a?{name:o,timestamp:parseInt(a[1],10),value:n.slice(1).join("=")}:null}).filter(e=>null!==e);return t.length>0?(t.sort((e,t)=>t.timestamp-e.timestamp),t[0].value):null}n.d(t,{bA:function(){return o},bW:function(){return c},uB:function(){return a}})}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js deleted file mode 100644 index 2909ac65a0..0000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,s,t){Promise.resolve().then(t.bind(t,12011))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return g}});var l=t(57437),n=t(2265),a=t(99376),i=t(20831),r=t(94789),o=t(12514),c=t(49804),u=t(67101),d=t(84264),m=t(49566),h=t(96761),x=t(84566),f=t(19250),p=t(14474),j=t(13634),_=t(73002);function g(){let[e]=j.Z.useForm(),s=(0,a.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));s&&s.split("=")[1]}("token");let t=s.get("invitation_id"),[g,Z]=(0,n.useState)(null),[k,w]=(0,n.useState)(""),[S,b]=(0,n.useState)(""),[N,v]=(0,n.useState)(null),[y,E]=(0,n.useState)(""),[I,O]=(0,n.useState)("");return(0,n.useEffect)(()=>{t&&(0,f.W_)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),E(s);let t=e.token,l=(0,p.o)(t);O(t),console.log("decoded:",l),Z(l.key),console.log("decoded user email:",l.user_email),b(l.user_email),v(l.user_id)})},[t]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,l.jsx)(d.Z,{children:"Claim your user account to login to Admin UI."}),(0,l.jsx)(r.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,l.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tirer."}),(0,l.jsx)(c.Z,{children:(0,l.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,l.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,l.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",I,"formValues:",e),g&&I&&(e.user_email=S,N&&t&&(0,f.m_)(g,t,N,e.password).then(e=>{var s;let t="/ui/";t+="?userID="+((null===(s=e.data)||void 0===s?void 0:s.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",t),window.location.href=t}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(m.Z,{type:"email",disabled:!0,value:S,defaultValue:S,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,l.jsx)(m.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js new file mode 100644 index 0000000000..d7f1882c15 --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return v}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002),_=s(3914);function v(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();(0,_.bW)();let s=l.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[S,k]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[A,E]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),I(l);let s=e.token,t=(0,g.o)(s);E(s),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),k(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",A,"formValues:",e),v&&A&&(e.user_email=N,S&&s&&(0,p.m_)(v,s,S,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),(0,_.uB)(A),console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return te}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=s(3914),g=e=>{let{userID:l,userEmail:s,userRole:t,premiumUser:a,proxySettings:i}=e,n=(null==i?void 0:i.PROXY_LOGOUT_URL)||"",o=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",s||"Unknown"]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,p.bA)(),window.location.href=n},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:o,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},j=s(19250);let f=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,j.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,j.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var _=s(49804),v=s(67101),y=s(20831),b=s(49566),Z=s(87452),N=s(88829),w=s(72208),S=s(84264),k=s(96761),C=s(29233),I=s(52787),A=s(13634),E=s(41021),P=s(51369),O=s(29967),T=s(73002),M=s(20577),L=s(56632);let D=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,j.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},R=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},F=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var U=s(15424),z=s(98074);let V=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,q=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},K=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return V(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var B=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),V(e,l)&&p.push({validator:async(e,l)=>{if(l&&!q(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(z.Z,{title:h,children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}):u;return t=V(e,l)?(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(I.default,{children:l.enum.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(M.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(b.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(b.Z,{placeholder:h||""}),(0,r.jsx)(A.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:K(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},H=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(I.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},J=s(57365),G=s(93192);function W(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=G.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(P.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(S.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{children:"Invitation Link"}),(0,r.jsx)(S.Z,{children:(0,r.jsx)(S.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>E.ZP.success("Copied!"),children:(0,r.jsx)(y.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var Y=s(30967),$=s(28181),X=s(73879),Q=s(3632),ee=s(15452),el=s.n(ee),es=s(71157),et=s(44643),ea=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.g)(l);g(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let v=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,j.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,j.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(P.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=new Blob([el().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(Y.Z,{beforeUpload:e=>(x(null),el().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(Q.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(y.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(S.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(S.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(et.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(S.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)($.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(C.CopyToClipboard,{text:l.invitation_link,onCopy:()=>E.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([el().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:er}=I.default;var ei=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=A.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[v,C]=(0,i.useState)(!1),[O,M]=(0,i.useState)(null),D=(0,n.useRouter)(),[F,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.So)(s,l,"any"),t=[];for(let l=0;l{D&&V(new URL("/",window.location.href).toString())},[D]);let q=async e=>{var t,a,r;try{E.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.Ov)(s,null,e);console.log("user create Response:",a),g(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};M(e),C(!0)}else(0,j.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,M(e),C(!0)});E.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";E.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(ea,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(P.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),g(null),u.resetFields()},children:[(0,r.jsx)(S.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(z.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(U.Z,{})})]}),name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(A.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(W,{isInvitationLinkModalVisible:v,setIsInvitationLinkModalVisible:C,baseUrl:F,invitationLinkData:O})]})},en=s(7310),eo=s.n(en);let{Option:ed}=I.default,ec=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},em=(e,l)=>F(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),eu=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,j.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eh=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,D]=(0,i.useState)([]),[F,V]=(0,i.useState)([]),[q,K]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ec(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[er,en]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&eu(l,a,n,D)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,j.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(E.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,j.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),g(m.soft_budget),E.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),E.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(em($,f)),c.setFieldValue("models",[])},[$,f]);let ef=async e=>{if(!e){en([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,j.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(s)}catch(e){console.error("Error fetching users:",e),E.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(eo()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(P.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(A.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(z.Z,{title:"Select who will own this API key",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(O.ZP.Group,{onChange:e=>K(e.target.value),value:q,children:[(0,r.jsx)(O.ZP,{value:"you",children:"You"}),(0,r.jsx)(O.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(O.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(z.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:er,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(T.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(z.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(H,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(z.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),F.map(e=>(0,r.jsx)(ed,{value:e,children:R(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(z.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(z.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(z.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(b.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(z.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(z.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:j.H2?"".concat(j.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(U.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(B,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(P.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(ei,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(P.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Save your Key"}),(0,r.jsx)(_.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)(_.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(S.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:h})}),(0,r.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{E.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(S.Z,{children:"Key being created, this might take 30s"})})]})})]})},ex=s(7366),ep=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,j.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},eg=s(71594),ej=s(24525),ef=s(21626),e_=s(97214),ev=s(28241),ey=s(58834),eb=s(69552),eZ=s(71876);function eN(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,eg.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,ej.sC)(),getExpandedRowModel:(0,ej.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:n?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var ew=s(27281),eS=s(41649),ek=s(12514),eC=s(12485),eI=s(18135),eA=s(35242),eE=s(29706),eP=s(77991),eO=s(10900),eT=s(23628),eM=s(74998);function eL(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=A.Z.useForm(),[h,x]=(0,i.useState)([]),p=em(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,j.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let g={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(A.Z,{form:u,onFinish:n,initialValues:g,layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(L.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(y.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]})}function eD(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let g=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,j.s0)(a,l.token,e);d(s.key),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key"),p(!1)}}},f=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(P.Z,{title:"Regenerate API Key",open:s,onCancel:f,footer:o?[(0,r.jsx)(y.Z,{onClick:f,children:"Close"},"close")]:[(0,r.jsx)(y.Z,{onClick:f,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(C.CopyToClipboard,{text:o,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(A.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eR(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=A.Z.useForm(),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),E.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,j.Nc)(o,e),E.ZP.success("Key updated successfully"),h(!1)}catch(e){E.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,j.I1)(o,n.token),E.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),E.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(k.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{icon:eT.Z,variant:"secondary",onClick:()=>_(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>g(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eD,{selectedToken:n,visible:f,onClose:()=>_(!1),accessToken:o}),p&&(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)(y.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>g(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(S.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(y.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eL,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(S.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(S.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(S.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(S.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(S.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(S.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eF=s(87908),eU=s(82422),ez=s(2356),eV=s(44633),eq=s(86462),eK=s(3837),eB=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[v,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let C=(0,i.useCallback)(eo()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eU.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),O=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(y.Z,{icon:ez.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(ek.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(T.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==O?void 0:O.label)||m,f?(0,r.jsx)(eV.Z,{className:"h-4 w-4"}):(0,r.jsx)(eq.Z,{className:"h-4 w-4"})]})}),(null==O?void 0:O.isSearchable)?(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search ".concat(O.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),C(e,O)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:v,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eF.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(T.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(L.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eK.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(T.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(T.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eH=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eJ=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eG(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[g,f]=(0,i.useState)(null),[_,v]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,j.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.getValue(),children:(0,r.jsx)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eH(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eJ(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:g?(0,r.jsx)(eR,{keyId:g,onClose:()=>f(null),keyData:l.find(e=>e.token===g),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eB,{options:w,onApplyFilters:e=>{if(v({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{v({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eN,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eW=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[I,O]=(0,i.useState)(null),[T,L]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ep({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=A.Z.useForm(),[em,eu]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await D(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,j.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),w(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){E.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,j.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eG,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),f&&(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)(y.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(P.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(y.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(A.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(y.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(P.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(y.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(C.CopyToClipboard,{text:ei,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eY=s(12011);console.log=function(){},console.log("isLocal:",!1);var e$=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:g}=e,[y,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),w=(0,n.useSearchParams)(),S=(0,p.bW)(),k=w.get("invitation_id"),[C,I]=(0,i.useState)(null),[A,E]=(0,i.useState)(null),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)(null),[L,D]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(S){let e=(0,o.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),I(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&C&&s&&!a&&!y){let e=sessionStorage.getItem("userModels"+l);e?O(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.g)(C);M(e);let t=await (0,j.Br)(C,l,s,!1,null,null);b(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(y))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,j.So)(C,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),O(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),f(C,l,s,Z,u))}},[l,S,C,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(C,", userID: ").concat(l,", userRole: ").concat(s)),C&&(console.log("fetching teams"),f(C,l,s,Z,u))},[Z]),(0,i.useEffect)(()=>{if(null!==a&&null!=L&&null!==L.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))L.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===L.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),E(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;E(e)}},[L]),null!=k)return(0,r.jsx)(eY.default,{});if(null==l||null==S){console.log("All cookies before redirect:",document.cookie),(0,p.bA)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=G.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",L),console.log("All cookies after redirect:",document.cookie),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(_.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eh,{userID:l,team:L,teams:t,userRole:s,accessToken:C,data:a,setData:h},L?L.team_id:null),(0,r.jsx)(eW,{userID:l,userRole:s,accessToken:C,selectedTeam:L||null,setSelectedTeam:D,data:a,setData:h,premiumUser:x,teams:t,currentOrg:Z,setCurrentOrg:N,organizations:g})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let eX={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eQ={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},e0=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eQ[e],displayName:e}}let l=Object.keys(eX).find(l=>eX[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eQ[s],displayName:s}},e1=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e2=(e,l)=>{console.log("Provider key: ".concat(e));let s=eX[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e4=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=eX[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=eX[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,j.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){E.ZP.error("Failed to create model: "+e,10)}},e5=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e3=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,j.um)(l,i),E.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e6=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=A.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(P.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(A.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},e8=s(47323),e7=s(53410),e9=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),E.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){E.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(I.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(P.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(A.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(S.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(I.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(T.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},le=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,j.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(eo()((e,l)=>f(e,l),300),[]),v=(e,l)=>{g(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(P.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(A.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:(0,r.jsxs)(z.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},ll=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,g]=(0,i.useState)(!1),[f]=A.Z.useForm(),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.Xm)(a,s);u(e)}catch(e){E.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.cu)(a,s,l),E.ZP.success("Team member added successfully"),g(!1),f.resetFields(),O()}catch(e){E.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},F=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.sN)(a,s,l),E.ZP.success("Team member updated successfully"),b(!1),O()}catch(e){E.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,j.Lp)(a,s,e),E.ZP.success("Team member removed successfully"),O()}catch(e){E.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,j.Gh)(a,t),E.ZP.success("Team settings updated successfully"),C(!1),O()}catch(e){E.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:K.team_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"User Email"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>V(e),icon:eM.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(y.Z,{onClick:()=>g(!0),children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Team Settings"}),P&&!w&&(0,r.jsx)(y.Z,{onClick:()=>C(!0),children:"Edit Settings"})]}),w?(0,r.jsxs)(A.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(L.Z,{type:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>C(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(eS.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e9,{visible:_,onCancel:()=>b(!1),onSubmit:F,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(le,{isVisible:p,onCancel:()=>g(!1),onSubmit:D,accessToken:a})]})},ls=s(30150);function lt(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,g,f,_,Z,N,w,C;let{modelId:I,onClose:P,modelData:O,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=A.Z.useForm(),[V,q]=(0,i.useState)(O),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:I}};await (0,j.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),E.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),E.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!O)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(S.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,j.Og)(M,I),E.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),E.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(k.Z,{children:["Public Model Name: ",e5(O)]}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:O.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-6",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[O.provider&&(0,r.jsx)("img",{src:e0(O.provider).logo,alt:"".concat(O.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=O.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(k.Z,{children:O.provider||"Not Set"})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(k.Z,{children:O.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Input: $",O.input_cost,"/1M tokens"]}),(0,r.jsxs)(S.Z,{children:["Output: $",O.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",O.model_info.created_at?new Date(O.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",O.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(A.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*O.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*O.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*O.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*O.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=V.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=V.litellm_params)||void 0===_?void 0:_.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=V.litellm_params)||void 0===w?void 0:w.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:O.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(y.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(O,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(T.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(T.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var la=s(67960),lr=s(47451),li=s(69410),ln=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=A.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(b.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(b.Z,{placeholder:t(l)})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},lo=()=>{let e=A.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=A.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=A.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(b.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)($.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:ld}=G.default;var lc=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(A.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(b.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(b.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(b.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(Y.Z,{...s,children:(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(Q.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(I.default,{placeholder:"Select API Base",children:[(0,r.jsx)(I.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(I.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(b.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(b.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(A.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(ld,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(b.Z,{placeholder:"sk-",type:"password"})})]})},lm=s(63709),lu=s(90464);let{Link:lh}=G.default;var lx=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=A.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(Z.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(A.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(H,{teams:t})}),(0,r.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lm.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}):(0,r.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lm.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(A.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(lr.Z,{className:"mb-4",children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(A.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lp,Link:lg}=G.default;var lj=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lp,{level:2,children:"Add new model"}),(0,r.jsx)(la.Z,{children:(0,r.jsx)(A.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(I.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eQ[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(ln,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(lo,{}),(0,r.jsx)(lc,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lx,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(z.Z,{title:"Get help on our github",children:(0,r.jsx)(G.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lf=s(49084);function l_(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let lv=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:e0(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(z.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:ly,Link:lb}=G.default,lZ={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lN=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[w,C]=(0,i.useState)([]),[I,P]=(0,i.useState)(a.OpenAI),[O,T]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[H,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[eN,eS]=(0,i.useState)(null),[eO,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==eN?void 0:eN.token;void 0===r&&(r=null);let i=eO;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,j.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,j.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,j.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,j.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,j.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,j.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[eN,eO]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,j.K_)(l,{router_settings:{model_group_retry_policy:ex}}),E.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),E.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let g=await (0,j.hy)(l);C(g);let f=await (0,j.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,j.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,j.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,j.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,j.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==eN?void 0:eN.token,eO),S=await (0,j.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,j.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,j.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,j.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,j.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==g&&a(),eJ()},[l,s,t,n,g,_]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e0=l.litellm_params)||void 0===e0?void 0:e0.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=G.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 e7=async()=>{try{E.ZP.info("Running health check..."),T("");let e=await (0,j.EY)(l);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}};S.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{eS(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(J.Z,{value:String(l),disabled:!0,onClick:()=>{eS(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(J.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(I)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===I);return(e9&&w.find(e=>e.name===eX[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(ll,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(lt,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"All Models"}),(0,r.jsx)(eC.Z,{children:"Add Model"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(eC.Z,{children:"Model Analytics"}),(0,r.jsx)(eC.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",_]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(J.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(l_,{columns:lv(m,ez,eB,e5,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e6,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e3(e,l,D,F)})]}),(0,r.jsx)(eE.Z,{className:"h-full",children:(0,r.jsx)(lj,{form:p,handleOk:()=>{p.validateFields().then(e=>{e4(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:I,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e2(e,g);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e1,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?E.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&E.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(y.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(k.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(S.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lZ&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lZ).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(M.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(y.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lw=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=A.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(P.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(A.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lS=s(15731);let lk=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(z.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(z.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lS.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(v.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(eS.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(eS.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lC(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lI=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(1),[_,v]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[A,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(A&&l)try{if(await (0,j.Eb)(l,[A]),E.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==A);h(e)}}catch(e){console.error("Error deleting user:",e),E.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,j.pf)(l,e,null),E.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(g));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,j.Br)(l,null,a,!0,g,25);sessionStorage.setItem("userList_".concat(g),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,j.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,g]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lk(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(ei,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||g<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||g>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lC,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lw,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",A]})]})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lA=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,j.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,j.cu)(l,e,{user_id:s,role:"user"}),E.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),E.ZP.error("Failed to join team")}};return(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Description"}),(0,r.jsx)(eb.Z,{children:"Members"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsxs)(e_.Z,{children:[t.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.team_alias})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.description||"No description available"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eS.Z,{size:"xs",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(S.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lE=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,F(s,l)};var lP=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&f(t,n,o,u,a),ew()},[c]);let[g]=A.Z.useForm(),[k]=A.Z.useForm(),{Title:C,Paragraph:O}=G.default,[F,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[J,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lE(x,ea);console.log("models: ".concat(e)),em(e),g.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,j.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},ej=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,j.rs)(t,eo),f(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await D(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));E.ZP.info("Creating Team");let o=await (0,j.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),E.ZP.success("Team created"),g.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),E.ZP.error("Error creating the team: "+e,20)}},ew=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:J?(0,r.jsx)(ll,{teamId:J,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===J)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Your Teams"}),(0,r.jsx)(eC.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(S.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Team ID"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Organization"}),(0,r.jsx)(eb.Z,{children:"Info"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ev.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)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)})},l))}):null}),(0,r.jsx)(ev.Z,{children:e.organization_id}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(ev.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>eg(e.team_id),icon:eM.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(y.Z,{onClick:ej,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(P.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),g.resetFields()},onCancel:()=>{Q(!1),g.resetFields()},children:(0,r.jsxs)(A.Z,{form:g,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{g.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(b.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lA,{accessToken:t,userID:n})})]})]})})},lO=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(!1),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,C]=(0,i.useState)(null),P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.t$)(a,s);u(e)}catch(e){E.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.vh)(a,s,l),E.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.LY)(a,s,l),E.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,j.Sb)(a,s,e.user_id),E.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,j.VA)(a,l),E.ZP.success("Organization settings updated successfully"),f(!1),O()}catch(e){E.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:m.organization_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Created At"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{C({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(y.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Organization Settings"}),P&&!g&&(0,r.jsx)(y.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),g?(0,r.jsxs)(A.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(L.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(le,{isVisible:_,onCancel:()=>b(!1),onSubmit:D,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e9,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:w,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lT=async(e,l)=>{l(await (0,j.r6)(e))};var lM=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[k,C]=(0,i.useState)(!1),[O]=A.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lT(a,m)},[l,a]);let T=e=>{e&&(w(e),Z(!0))},D=async()=>{if(N&&a)try{await (0,j.cq)(a,N),E.ZP.success("Organization deleted successfully"),Z(!1),w(null),lT(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,j.H1)(a,e),C(!1),O.resetFields(),lT(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lO,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(eC.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(S.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Organization ID"}),(0,r.jsx)(eb.Z,{children:"Organization Name"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(eb.Z,{children:"Info"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.organization_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{children:e.organization_alias}),(0,r.jsx)(ev.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{children:e.spend}),(0,r.jsx)(ev.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(ev.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)},l))})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(ev.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>T(e.organization_id),icon:eM.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>C(!0),children:"+ Create New Organization"}),(0,r.jsx)(P.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{C(!1),O.resetFields()},children:(0,r.jsxs)(A.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(y.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),f?(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 Organization"}),(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 organization?"})})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(S.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lL=s(94789);let lD={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lR={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lF=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lR[e];return l?l.fields.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(L.Z.Password,{}):(0,r.jsx)(b.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(P.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(A.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(I.default,{children:Object.entries(lD).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(A.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(P.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(S.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)(T.ZP,{onClick:n,children:"Done"})})]})]})};let lU=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lz=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=A.Z.useForm(),[d]=A.Z.useForm(),{Title:c,Paragraph:m}=G.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[I,O]=(0,i.useState)(!1),[M,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,J]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lU(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){E.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,j.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),E.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,j.eH)(s,e.ip);let l=await (0,j.PT)(s);B(l),E.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),E.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{J(e),q(!0)},et=async()=>{if(H&&s)try{await (0,j.$I)(s,H);let e=await (0,j.PT)(s);B(e.length>0?e:[X]),E.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),E.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),J(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,j.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,j.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,j.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;E.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,j.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,j.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lR[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,j.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:()=>!0===a?O(!0):E.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lF,{isAddSSOModalVisible:I,isInstructionsModalVisible:M,handleAddSSOOk:()=>{O(!1),o.resetFields()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),O(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(P.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(y.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"IP Address"}),(0,r.jsx)(eb.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:K.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e}),(0,r.jsx)(ev.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(y.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(P.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(A.Z,{onFinish:el,children:[(0,r.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(L.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(A.Z.Item,{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(P.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(y.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lL.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lV=s(92858),lq=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=A.Z.useForm();return(0,r.jsxs)(A.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{align:"center",children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(A.Z.Item,{name:e.field_name,children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lK=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,j.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lq,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,j.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.jA)(l,"alerting",["slack"]):(0,j.jA)(l,"alerting",[])),E.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lB=s(86582);let{Title:lH,Paragraph:lJ}=G.default;console.log=function(){};var lG=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=A.Z.useForm(),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[_,Z]=(0,i.useState)(""),[N,w]=(0,i.useState)({}),[k,C]=(0,i.useState)([]),[O,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),H=e=>{k.includes(e)?C(k.filter(l=>l!==e)):C([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),C(e.active_alerts),Z(s),w(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,j.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,j.K_)(l,{environment_variables:s}),E.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,j.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),E.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eC.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(eC.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(eC.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(v.Z,{numItems:2,children:(0,r.jsx)(ek.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(eb.Z,{children:"Callback Name"})})}),(0,r.jsx)(e_.Z,{children:n.map((e,s)=>(0,r.jsxs)(eZ.Z,{className:"flex justify-between",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.name})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(S.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)}):(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:_})})]},l)})})]}),(0,r.jsx)(y.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,j.K_)(l,s)}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lK,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Email Settings"}),(0,r.jsxs)(S.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(ev.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(v.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(S.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"mt-2",children:l}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(P.Z,{title:"Add Logging Callback",visible:O,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(A.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lB.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(I.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(J.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lB.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(b.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(P.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(A.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lB.Z,{label:l,name:l,children:(0,r.jsx)(b.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lW=s(92414),lY=s(46030);let{Option:l$}=I.default;var lX=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(P.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(A.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,j.K_)(s,{router_settings:o}),a(o)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(ew.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(A.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lW.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lQ=s(33619);async function l0(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lQ.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});E.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l1={ttl:3600,lowest_latency_buffer:0},l2=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(N.Z,{children:"latency-based-routing"==l?(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(S.Z,{children:"No specific settings"})})]})};var l4=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(null),I={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,j.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,j.K_)(l,{router_settings:t}),o(t),E.ZP.success("Router settings updated successfully")}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},T=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,j.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,j.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,j.K_)(l,{router_settings:s})}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(eC.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(eC.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(k.Z,{children:"Router Settings"}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[l]})]}),(0,r.jsx)(ev.Z,{children:"routing_strategy"==l?(0,r.jsxs)(ew.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(J.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(J.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(J.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l2,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l1,paramExplanation:I})]}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Model Name"}),(0,r.jsx)(eb.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(e_.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:t}),(0,r.jsx)(ev.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{onClick:()=>l0(t,l),children:"Test Fallback"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(lX,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"}),(0,r.jsx)(eb.Z,{children:"Status"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(ev.Z,{children:"Integer"==e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(y.Z,{onClick:()=>T(e.field_name,l),children:"Update"}),(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l5=s(93142),l3=s(45246),l6=s(96473),l8=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l5.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(b.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(b.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l3.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(T.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l6.Z,{}),children:"Add Header"})]})};let{Option:l7}=I.default;var l9=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=A.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(P.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(A.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,j.Vt)(l,e),s(r)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l8,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},se=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,j.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,j.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),E.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Path"}),(0,r.jsx)(eb.Z,{children:"Target"}),(0,r.jsx)(eb.Z,{children:"Headers"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:n.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.path})}),(0,r.jsx)(ev.Z,{children:e.target}),(0,r.jsx)(ev.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l9,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=A.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call");let l=await (0,j.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),E.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(A.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ss=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=A.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call"),t(!0);let l=await (0,j.qI)(s,e);a(e=>e?[...e,l]:[l]),E.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(A.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},st=s(17906),sa=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,j.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;E.ZP.info("Request made"),await (0,j.NV)(l,e);let t=[...c];t.splice(s,1),m(t),E.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,j.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(y.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(sl,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(ss,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Budget ID"}),(0,r.jsx)(eb.Z,{children:"Max Budget"}),(0,r.jsx)(eb.Z,{children:"TPM"}),(0,r.jsx)(eb.Z,{children:"RPM"})]})}),(0,r.jsx)(e_.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.budget_id}),(0,r.jsx)(ev.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(ev.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(ev.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(eC.Z,{children:"Test it (Curl)"}),(0,r.jsx)(eC.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sr=s(77398),si=s.n(sr),sn=s(20016);async function so(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let sd=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return so(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sc=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sm=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sc(l)})},su=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sm,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(z.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(sd,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:e0(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(z.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],sh=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,j.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sx=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sp=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sg=["Internal User","Internal Viewer"],sj=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sf(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(si()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(si()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sg.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&g(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sg.includes(o)&&q(!0)},[o]);let B=(0,sn.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=si()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?si()(S).utc().format("YYYY-MM-DD HH:mm:ss"):si()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,j.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await sh(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(si()(N).format("MMM D, h:mm A")," - ").concat(si()(S).format("MMM D, h:mm A"));let e=si()(),l=si()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>g(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),g(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(si()().format("YYYY-MM-DDTHH:mm")),w(si()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eN,{columns:su,data:H,renderSubComponent:s_,getRowCanExpand:()=>!0})]})]})}function s_(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sj,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sx,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var sv=s(92699),sy=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(S.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eC.Z,{children:"LlamaIndex"}),(0,r.jsx)(eC.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sb=s(243),sZ=s(94263);async function sN(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lQ.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sw=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[w,k]=(0,i.useState)([]),C=(0,i.useRef)(null),A=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,j.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),f(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{A.current&&setTimeout(()=>{var e;null===(e=A.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){E.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{g&&await sN(i,(e,l)=>P("assistant",e,l),g,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=G.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)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eC.Z,{children:"Chat"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"API Key Source"}),(0,r.jsx)(I.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(_.Z,{className:"mx-2",children:[(0,r.jsx)(S.Z,{children:"Select Model:"}),(0,r.jsx)(I.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),N("custom"===e)},options:[...w,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{f(e)},500)}})]})]}),(0,r.jsx)(y.Z,{onClick:()=>{p([]),E.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ef.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{})})}),(0,r.jsxs)(e_.Z,{children:[x.map((e,l)=>(0,r.jsx)(eZ.Z,{children:(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sb.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(st.Z,{style:sZ.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{ref:A,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(b.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(y.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sS=s(19226),sk=s(45937),sC=s(92403),sI=s(28595),sA=s(68208),sE=s(9775),sP=s(41361),sO=s(37527),sT=s(12660),sM=s(88009),sL=s(48231),sD=s(41169),sR=s(44625),sF=s(57400),sU=s(55322);let{Sider:sz}=sS.default,sV=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sC.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sI.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sA.Z,{}),roles:sp},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sE.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sP.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sp},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sT.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sM.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sL.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sD.Z,{}),roles:sp,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sR.Z,{}),roles:sp},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sF.Z,{}),roles:sp}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sT.Z,{}),roles:sp},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp}]}];var sq=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sV.find(l=>l.page===e);if(l)return l.key;for(let l of sV)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sV.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sS.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sz,{theme:"light",width:220,children:(0,r.jsx)(sk.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sK=s(40278),sB=s(96889),sH=s(97765);console.log=function(){};var sJ=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,j.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let g=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sG=s(69907),sW=s(53003),sY=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let s$=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var sX=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,j.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,j.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),w((await (0,j.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,j.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,j.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,j.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,j.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,j.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,j.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,j.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,j.b1)(l,null,void 0,void 0),f,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,j.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(l)try{let e=await (0,j.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),s$(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(S.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(y.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mt-2",children:[(0,r.jsx)(eC.Z,{children:"All Up"}),s$(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eC.Z,{children:"Team Based Usage"}),(0,r.jsx)(eC.Z,{children:"Customer Usage"}),(0,r.jsx)(eC.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(eC.Z,{children:"Cost"}),(0,r.jsx)(eC.Z,{children:"Activity"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(S.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sJ,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Monthly Spend"}),(0,r.jsx)(sK.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top API Keys"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top Models"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sY.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Provider"}),(0,r.jsx)(eb.Z,{children:"Spend"})]})}),(0,r.jsx)(e_.Z,{children:T.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.provider}),(0,r.jsx)(ev.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"All Up"}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:e.model}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sB.Z,{data:P})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sK.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(_.Z,{numColSpan:2})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Time Range"}),(0,r.jsx)(sW.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Key"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(ek.Z,{className:"mt-4",children:(0,r.jsxs)(ef.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Customer"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Total Events"})]})}),(0,r.jsx)(e_.Z,{children:null==g?void 0:g.map((e,l)=>{var s;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.end_user}),(0,r.jsx)(ev.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(ev.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(_.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lY.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(J.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(S.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sK.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(_.Z,{numColSpan:2})]})]})]})]})})},sQ=s(51853);let s0=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s1=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s2=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sQ.Z,{className:"h-4 w-4"})})]})})})},s4=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s1(j.litellm_params)||{},_=s1(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s1(null==g?void 0:g.litellm_cache_params)||{},_=s1(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(S.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s2,{label:"Error Message",value:j.message}),(0,r.jsx)(s2,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s2,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s2,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s2,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s2,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s2,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s2,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s2,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s2,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s2,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s5=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(y.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(s0,{responseTimeMs:n})]}),s&&(0,r.jsx)(s4,{response:s})]})},s3=e=>{if(e)return e.toISOString().split("T")[0]};function s6(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s8=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[w,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[A,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&w&&((async()=>{p(await (0,j.zg)(l,s3(w.from),s3(w.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,j.zg)(l,s3(e),s3(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);f(s6(s)),b(s6(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,w,x]);let L=async()=>{try{E.ZP.info("Running cache health check..."),P("");let e=await (0,j.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Cache Analytics"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(v.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(sW.Z,{enableSelect:!0,value:w,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sK.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sK.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(s5,{accessToken:l,healthCheckResponse:A,runCachingHealthCheck:L})})]})]})},s7=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,j.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(S.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Guardrail Name"}),(0,r.jsx)(eb.Z,{children:"Mode"}),(0,r.jsx)(eb.Z,{children:"Status"})]})}),(0,r.jsx)(e_.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.guardrail_name}),(0,r.jsx)(ev.Z,{children:e.litellm_params.mode}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s9=new d.S;function te(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[_,v]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)([]),[w,S]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,C]=(0,i.useState)(!0),I=(0,n.useSearchParams)(),[A,E]=(0,i.useState)({data:[]}),[P,O]=(0,i.useState)(null),T=I.get("userID"),M=I.get("invitation_id"),[L,D]=(0,i.useState)(()=>I.get("page")||"api-keys"),[R,F]=(0,i.useState)(null);return(0,i.useEffect)(()=>{O((0,p.bW)())},[]),(0,i.useEffect)(()=>{if(!P)return;let e=(0,o.o)(P);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),F(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&D("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?C("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,j.K8)(e.auth_header_name)}},[P]),(0,i.useEffect)(()=>{R&&T&&e&&eu(T,e,R,N),R&&T&&e&&f(R,T,e,null,x),R&&lT(R,b)},[R,T,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s9,children:M?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(g,{userID:T,userRole:e,premiumUser:s,userEmail:m,setProxySettings:S,proxySettings:w}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sq,{setPage:e=>{let l=new URLSearchParams(I);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),D(e)},userRole:e,defaultSelectedKey:L})}),"api-keys"==L?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):"models"==L?(0,r.jsx)(lN,{userID:T,userRole:e,token:P,keys:_,accessToken:R,modelData:A,setModelData:E,premiumUser:s,teams:h}):"llm-playground"==L?(0,r.jsx)(sw,{userID:T,userRole:e,token:P,accessToken:R,disabledPersonalKeyCreation:a}):"users"==L?(0,r.jsx)(lI,{userID:T,userRole:e,token:P,keys:_,teams:h,accessToken:R,setKeys:v}):"teams"==L?(0,r.jsx)(lP,{teams:h,setTeams:x,searchParams:I,accessToken:R,userID:T,userRole:e,organizations:y}):"organizations"==L?(0,r.jsx)(lM,{organizations:y,setOrganizations:b,userModels:Z,accessToken:R,userRole:e,premiumUser:s}):"admin-panel"==L?(0,r.jsx)(lz,{setTeams:x,searchParams:I,accessToken:R,showSSOBanner:k,premiumUser:s}):"api_ref"==L?(0,r.jsx)(sy,{proxySettings:w}):"settings"==L?(0,r.jsx)(lG,{userID:T,userRole:e,accessToken:R,premiumUser:s}):"budgets"==L?(0,r.jsx)(sa,{accessToken:R}):"guardrails"==L?(0,r.jsx)(s7,{accessToken:R}):"general-settings"==L?(0,r.jsx)(l4,{userID:T,userRole:e,accessToken:R,modelData:A}):"model-hub"==L?(0,r.jsx)(sv.Z,{accessToken:R,publicPage:!1,premiumUser:s}):"caching"==L?(0,r.jsx)(s8,{userID:T,userRole:e,token:P,accessToken:R,premiumUser:s}):"pass-through-settings"==L?(0,r.jsx)(se,{userID:T,userRole:e,accessToken:R,modelData:A}):"logs"==L?(0,r.jsx)(sf,{userID:T,userRole:e,token:P,accessToken:R}):(0,r.jsx)(sX,{userID:T,userRole:e,token:P,accessToken:R,keys:_,premiumUser:s})]})]})})})}},3914:function(e,l,s){"use strict";function t(){let e=window.location.hostname,l=["/","/ui"],s=["Lax","Strict","None"],t=document.cookie.split("; "),a=/^token_\d+$/;t.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(t=>{l.forEach(l=>{document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,";"),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let a="None"===s?" Secure;":"";document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; SameSite=").concat(s,";").concat(a),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let l=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(l),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function r(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,l=document.cookie.split("; ").map(l=>{let s=l.split("="),t=s[0];if("token"===t)return null;let a=t.match(e);return a?{name:t,timestamp:parseInt(a[1],10),value:s.slice(1).join("=")}:null}).filter(e=>null!==e);return l.length>0?(l.sort((e,l)=>l.timestamp-e.timestamp),l[0].value):null}s.d(l,{bA:function(){return t},bW:function(){return r},uB:function(){return a}})}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js deleted file mode 100644 index 1e9a200f47..0000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return _}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002);function _(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));l&&l.split("=")[1]}("token");let s=l.get("invitation_id"),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(""),[Z,N]=(0,a.useState)(""),[w,S]=(0,a.useState)(null),[k,C]=(0,a.useState)(""),[I,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),C(l);let s=e.token,t=(0,g.o)(s);A(s),console.log("decoded:",t),v(t.key),console.log("decoded user email:",t.user_email),N(t.user_email),S(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",_,"token:",I,"formValues:",e),_&&I&&(e.user_email=Z,w&&s&&(0,p.m_)(_,s,w,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:Z,defaultValue:Z,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return s9}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=e=>{let{userID:l,userRole:s,premiumUser:t,proxySettings:a}=e,i=(null==a?void 0:a.PROXY_LOGOUT_URL)||"",n=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",s]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(t)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=i},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:n,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},g=s(19250);let j=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,g.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,g.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var f=s(49804),_=s(67101),v=s(20831),y=s(49566),b=s(87452),Z=s(88829),N=s(72208),w=s(84264),S=s(96761),k=s(29233),C=s(52787),I=s(13634),A=s(41021),E=s(51369),P=s(29967),O=s(73002),T=s(20577),M=s(56632);let L=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,g.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},D=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},R=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var F=s(15424),U=s(98074);let z=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,V=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},q=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return z(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var K=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),z(e,l)&&p.push({validator:async(e,l)=>{if(l&&!V(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(U.Z,{title:h,children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}):u;return t=z(e,l)?(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(C.default,{children:l.enum.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(T.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(y.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(y.Z,{placeholder:h||""}),(0,r.jsx)(I.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:q(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},B=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(C.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},H=s(57365),J=s(93192);function G(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=J.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(E.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(w.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{children:"Invitation Link"}),(0,r.jsx)(w.Z,{children:(0,r.jsx)(w.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(k.CopyToClipboard,{text:o(),onCopy:()=>A.ZP.success("Copied!"),children:(0,r.jsx)(v.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var W=s(30967),Y=s(28181),$=s(73879),X=s(3632),Q=s(15452),ee=s.n(Q),el=s(71157),es=s(44643),et=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.g)(l);j(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let y=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,g.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,g.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(E.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=new Blob([ee().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(W.Z,{beforeUpload:e=>(x(null),ee().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(X.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(v.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(w.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(w.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(es.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(w.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)(Y.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(k.CopyToClipboard,{text:l.invitation_link,onCopy:()=>A.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([ee().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:ea}=C.default;var er=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=I.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[k,P]=(0,i.useState)(!1),[T,L]=(0,i.useState)(null),R=(0,n.useRouter)(),[z,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.So)(s,l,"any"),t=[];for(let l=0;l{R&&V(new URL("/",window.location.href).toString())},[R]);let q=async e=>{var t,a,r;try{A.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,g.Ov)(s,null,e);console.log("user create Response:",a),j(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};L(e),P(!0)}else(0,g.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,L(e),P(!0)});A.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";A.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(et,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(E.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),j(null),u.resetFields()},children:[(0,r.jsx)(w.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(U.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(F.Z,{})})]}),name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(I.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(G,{isInvitationLinkModalVisible:k,setIsInvitationLinkModalVisible:P,baseUrl:z,invitationLinkData:T})]})},ei=s(7310),en=s.n(ei);let{Option:eo}=C.default,ed=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},ec=(e,l)=>R(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),em=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,g.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eu=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[L,R]=(0,i.useState)([]),[z,V]=(0,i.useState)([]),[q,H]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ed(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[ei,eu]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&em(l,a,n,R)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,g.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(A.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,g.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),j(m.soft_budget),A.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),A.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(ec($,L)),c.setFieldValue("models",[])},[$,L]);let ef=async e=>{if(!e){eu([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,g.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eu(s)}catch(e){console.error("Error fetching users:",e),A.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(en()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(E.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(I.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(U.Z,{title:"Select who will own this API key",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(P.ZP.Group,{onChange:e=>H(e.target.value),value:q,children:[(0,r.jsx)(P.ZP,{value:"you",children:"You"}),(0,r.jsx)(P.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(P.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(U.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:ei,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(O.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(U.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(B,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(U.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),z.map(e=>(0,r.jsx)(eo,{value:e,children:D(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(U.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(U.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(U.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(y.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(U.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(U.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:g.H2?"".concat(g.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(F.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(K,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(E.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(er,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(E.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Save your Key"}),(0,r.jsx)(f.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)(f.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(w.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:h})}),(0,r.jsx)(k.CopyToClipboard,{text:h,onCopy:()=>{A.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(w.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=s(7366),ex=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,g.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},ep=s(71594),eg=s(24525),ej=s(21626),ef=s(97214),e_=s(28241),ev=s(58834),ey=s(69552),eb=s(71876);function eZ(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,ep.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,eg.sC)(),getExpandedRowModel:(0,eg.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:n?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var eN=s(27281),ew=s(41649),eS=s(12514),ek=s(12485),eC=s(18135),eI=s(35242),eA=s(29706),eE=s(77991),eP=s(10900),eO=s(23628),eT=s(74998);function eM(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=I.Z.useForm(),[h,x]=(0,i.useState)([]),p=ec(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,g.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let j={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(I.Z,{form:u,onFinish:n,initialValues:j,layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(C.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(C.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(C.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsx)(I.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(M.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(v.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]})}function eL(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let j=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,g.s0)(a,l.token,e);d(s.key),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key"),p(!1)}}},b=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(E.Z,{title:"Regenerate API Key",open:s,onCancel:b,footer:o?[(0,r.jsx)(v.Z,{onClick:b,children:"Close"},"close")]:[(0,r.jsx)(v.Z,{onClick:b,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:j,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(k.CopyToClipboard,{text:o,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(I.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eD(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=I.Z.useForm(),[p,j]=(0,i.useState)(!1),[f,y]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(w.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),A.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,g.Nc)(o,e),A.ZP.success("Key updated successfully"),h(!1)}catch(e){A.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,g.I1)(o,n.token),A.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),A.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{icon:eO.Z,variant:"secondary",onClick:()=>y(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>j(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eL,{selectedToken:n,visible:f,onClose:()=>y(!1),accessToken:o}),p&&(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)(v.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>j(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(w.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(v.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eM,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(w.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(w.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(w.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(w.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(w.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(w.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(w.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eR=s(87908),eF=s(82422),eU=s(2356),ez=s(44633),eV=s(86462),eq=s(3837),eK=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let I=(0,i.useCallback)(en()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eF.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),T=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(v.Z,{icon:eU.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(eS.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(O.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==T?void 0:T.label)||m,f?(0,r.jsx)(ez.Z,{className:"h-4 w-4"}):(0,r.jsx)(eV.Z,{className:"h-4 w-4"})]})}),(null==T?void 0:T.isSearchable)?(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search ".concat(T.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),I(e,T)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:y,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eR.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(O.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(M.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eq.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(O.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(O.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eB=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eH=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eJ(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[j,f]=(0,i.useState)(null),[_,y]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,g.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.getValue(),children:(0,r.jsx)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eB(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eH(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:j?(0,r.jsx)(eD,{keyId:j,onClose:()=>f(null),keyData:l.find(e=>e.token===j),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eK,{options:w,onApplyFilters:e=>{if(y({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{y({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eZ,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eG=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,C]=(0,i.useState)(null),[P,O]=(0,i.useState)(null),[M,D]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ex({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=I.Z.useForm(),[em,eu]=(0,i.useState)(null),[ep,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await L(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,g.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),C(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){A.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,g.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eJ,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),b&&(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)(v.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),C(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(E.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(v.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(I.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(v.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(E.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(v.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(k.CopyToClipboard,{text:ei,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eW=s(12011);console.log=function(){},console.log("isLocal:",!1);var eY=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:p}=e,[v,y]=(0,i.useState)(null),[b,Z]=(0,i.useState)(null),N=(0,n.useSearchParams)(),w=function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"),S=N.get("invitation_id"),[k,C]=(0,i.useState)(null),[I,A]=(0,i.useState)(null),[E,P]=(0,i.useState)([]),[O,T]=(0,i.useState)(null),[M,L]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(w){let e=(0,o.o)(w);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),C(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&k&&s&&!a&&!v){let e=sessionStorage.getItem("userModels"+l);e?P(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(b))),(async()=>{try{let e=await (0,g.g)(k);T(e);let t=await (0,g.Br)(k,l,s,!1,null,null);y(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(v))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,g.So)(k,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),P(a),console.log("userModels:",E),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),j(k,l,s,b,u))}},[l,w,k,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(b),", accessToken: ").concat(k,", userID: ").concat(l,", userRole: ").concat(s)),k&&(console.log("fetching teams"),j(k,l,s,b,u))},[b]),(0,i.useEffect)(()=>{if(null!==a&&null!=M&&null!==M.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))M.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===M.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),A(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;A(e)}},[M]),null!=S)return(0,r.jsx)(eW.default,{});if(null==l||null==w){let e="/sso/key/generate";return document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Full URL:",e),window.location.href=e,null}if(null==k)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=J.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",M),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(f.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eu,{userID:l,team:M,teams:t,userRole:s,accessToken:k,data:a,setData:h},M?M.team_id:null),(0,r.jsx)(eG,{userID:l,userRole:s,accessToken:k,selectedTeam:M||null,setSelectedTeam:L,data:a,setData:h,premiumUser:x,teams:t,currentOrg:b,setCurrentOrg:Z,organizations:p})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let e$={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eX={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},eQ=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eX[e],displayName:e}}let l=Object.keys(e$).find(l=>e$[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eX[s],displayName:s}},e0=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e1=(e,l)=>{console.log("Provider key: ".concat(e));let s=e$[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e2=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=e$[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=e$[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,g.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){A.ZP.error("Failed to create model: "+e,10)}},e4=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e5=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,g.um)(l,i),A.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e3=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=I.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(E.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(I.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},e6=s(47323),e8=s(53410),e7=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=I.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),A.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){A.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(C.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(E.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(I.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(w.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(C.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(O.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},e9=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,g.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(en()((e,l)=>f(e,l),300),[]),v=(e,l)=>{j(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(E.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(I.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(I.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:(0,r.jsxs)(U.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},le=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,j]=(0,i.useState)(!1),[f]=I.Z.useForm(),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[k,E]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.Xm)(a,s);u(e)}catch(e){A.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.cu)(a,s,l),A.ZP.success("Team member added successfully"),j(!1),f.resetFields(),L()}catch(e){A.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},z=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.sN)(a,s,l),A.ZP.success("Team member updated successfully"),b(!1),L()}catch(e){A.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,g.Lp)(a,s,e),A.ZP.success("Team member removed successfully"),L()}catch(e){A.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,g.Gh)(a,t),A.ZP.success("Team settings updated successfully"),E(!1),L()}catch(e){A.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:K.team_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"User Email"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>V(e),icon:eT.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(v.Z,{onClick:()=>j(!0),children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Team Settings"}),P&&!k&&(0,r.jsx)(v.Z,{onClick:()=>E(!0),children:"Edit Settings"})]}),k?(0,r.jsxs)(I.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(M.Z,{type:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>E(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(ew.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e7,{visible:y,onCancel:()=>b(!1),onSubmit:z,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(e9,{isVisible:p,onCancel:()=>j(!1),onSubmit:R,accessToken:a})]})},ll=s(30150);function ls(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,j,f,b,Z,N,k,C;let{modelId:E,onClose:P,modelData:T,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=I.Z.useForm(),[V,q]=(0,i.useState)(T),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:E}};await (0,g.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),A.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),A.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!T)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(w.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,g.Og)(M,E),A.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),A.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(S.Z,{children:["Public Model Name: ",e4(T)]}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-6",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,r.jsx)("img",{src:eQ(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(S.Z,{children:T.provider||"Not Set"})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(S.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,r.jsxs)(w.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(I.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*T.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*T.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*T.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*T.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(I.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(I.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=V.litellm_params)||void 0===j?void 0:j.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(I.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(b=V.litellm_params)||void 0===b?void 0:b.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(I.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(k=V.litellm_params)||void 0===k?void 0:k.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(v.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(O.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(O.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var lt=s(67960),la=s(47451),lr=s(69410),li=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=I.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(I.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(I.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(y.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(C.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(y.Z,{placeholder:t(l)})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(I.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},ln=()=>{let e=I.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=I.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=I.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(y.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)(Y.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:lo}=J.default;var ld=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(I.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(y.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(y.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(y.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(W.Z,{...s,children:(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(X.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(C.default,{placeholder:"Select API Base",children:[(0,r.jsx)(C.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(C.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(y.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(y.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(I.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(lo,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(y.Z,{placeholder:"sk-",type:"password"})})]})},lc=s(63709),lm=s(90464);let{Link:lu}=J.default;var lh=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=I.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(b.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(I.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(B,{teams:t})}),(0,r.jsx)(I.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lc.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(I.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}):(0,r.jsx)(I.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)(I.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lc.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(I.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(la.Z,{className:"mb-4",children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(I.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lx,Link:lp}=J.default;var lg=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lx,{level:2,children:"Add new model"}),(0,r.jsx)(lt.Z,{children:(0,r.jsx)(I.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(C.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eX[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(li,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(ln,{}),(0,r.jsx)(ld,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lh,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(U.Z,{title:"Get help on our github",children:(0,r.jsx)(J.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lj=s(49084);function lf(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let l_=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:eQ(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(U.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:lv,Link:ly}=J.default,lb={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lZ=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[k,C]=(0,i.useState)([]),[E,P]=(0,i.useState)(a.OpenAI),[O,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[G,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[ew,eP]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==ew?void 0:ew.token;void 0===r&&(r=null);let i=eT;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,g.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,g.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,g.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,g.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,g.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,g.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[ew,eT]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,g.K_)(l,{router_settings:{model_group_retry_policy:ex}}),A.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),A.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let j=await (0,g.hy)(l);C(j);let f=await (0,g.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,g.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,g.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,g.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,g.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eT),S=await (0,g.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,g.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,g.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,g.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,g.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==j&&a(),eJ()},[l,s,t,n,j,y]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(j)),null!=j&&"object"==typeof j&&e in j)?j[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e8=l.litellm_params)||void 0===e8?void 0:e8.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=J.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 e7=async()=>{try{A.ZP.info("Running health check..."),M("");let e=await (0,g.EY)(l);M(e)}catch(e){console.error("Error running health check:",e),M("Error running health check")}};w.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{eP(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(H.Z,{value:String(l),disabled:!0,onClick:()=>{eP(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(H.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(E)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===E);return(e9&&k.find(e=>e.name===e$[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(le,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(ls,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"All Models"}),(0,r.jsx)(ek.Z,{children:"Add Model"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(ek.Z,{children:"Model Analytics"}),(0,r.jsx)(ek.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[y&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",y]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(H.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(lf,{columns:l_(m,ez,eB,e4,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e3,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e5(e,l,D,F)})]}),(0,r.jsx)(eA.Z,{className:"h-full",children:(0,r.jsx)(lg,{form:p,handleOk:()=>{p.validateFields().then(e=>{e2(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:E,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e1(e,j);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e0,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?A.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&A.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(v.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(S.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(w.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lb&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lb).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(T.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(v.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lN=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=I.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(E.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(I.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lw=s(15731);let lS=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(U.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(U.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lw.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(_.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(ew.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(ew.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lk(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lC=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(1),[_,y]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[E,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(E&&l)try{if(await (0,g.Eb)(l,[E]),A.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==E);h(e)}}catch(e){console.error("Error deleting user:",e),A.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,g.pf)(l,e,null),A.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(j));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,g.Br)(l,null,a,!0,j,25);sessionStorage.setItem("userList_".concat(j),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,g.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,j]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lS(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(er,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||j<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||j>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lk,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lN,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",E]})]})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(v.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lI=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,g.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,g.cu)(l,e,{user_id:s,role:"user"}),A.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),A.ZP.error("Failed to join team")}};return(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Description"}),(0,r.jsx)(ey.Z,{children:"Members"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsxs)(ef.Z,{children:[t.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.team_alias})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.description||"No description available"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ew.Z,{size:"xs",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(w.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lA=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,R(s,l)};var lE=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&j(t,n,o,u,a),eP()},[c]);let[S]=I.Z.useForm(),[k]=I.Z.useForm(),{Title:P,Paragraph:R}=J.default,[z,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[G,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lA(x,ea);console.log("models: ".concat(e)),em(e),S.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,g.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},eZ=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,g.rs)(t,eo),j(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await L(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));A.ZP.info("Creating Team");let o=await (0,g.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),A.ZP.success("Team created"),S.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),A.ZP.error("Error creating the team: "+e,20)}},eP=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:G?(0,r.jsx)(le,{teamId:G,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===G)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Your Teams"}),(0,r.jsx)(ek.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eP})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(w.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Team ID"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Organization"}),(0,r.jsx)(ey.Z,{children:"Info"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)})},l))}):null}),(0,r.jsx)(e_.Z,{children:e.organization_id}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(e_.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>eg(e.team_id),icon:eT.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(v.Z,{onClick:eZ,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(E.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),S.resetFields()},onCancel:()=>{Q(!1),S.resetFields()},children:(0,r.jsxs)(I.Z,{form:S,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(C.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{S.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(C.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(y.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lI,{accessToken:t,userID:n})})]})]})})},lP=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[k,E]=(0,i.useState)(null),P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.t$)(a,s);u(e)}catch(e){A.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.vh)(a,s,l),A.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.LY)(a,s,l),A.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,g.Sb)(a,s,e.user_id),A.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,g.VA)(a,l),A.ZP.success("Organization settings updated successfully"),f(!1),L()}catch(e){A.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:m.organization_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Created At"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{E({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(v.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Organization Settings"}),P&&!j&&(0,r.jsx)(v.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,r.jsxs)(I.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(M.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(e9,{isVisible:y,onCancel:()=>b(!1),onSubmit:R,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e7,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:k,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lO=async(e,l)=>{l(await (0,g.r6)(e))};var lT=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[k,P]=(0,i.useState)(!1),[O]=I.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lO(a,m)},[l,a]);let L=e=>{e&&(S(e),Z(!0))},R=async()=>{if(N&&a)try{await (0,g.cq)(a,N),A.ZP.success("Organization deleted successfully"),Z(!1),S(null),lO(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,g.H1)(a,e),P(!1),O.resetFields(),lO(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lP,{organizationId:h,onClose:()=>{x(null),j(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(ek.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(w.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Organization ID"}),(0,r.jsx)(ey.Z,{children:"Organization Name"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ey.Z,{children:"Info"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.organization_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{children:e.organization_alias}),(0,r.jsx)(e_.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{children:e.spend}),(0,r.jsx)(e_.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)},l))})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(e_.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{x(e.organization_id),j(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>L(e.organization_id),icon:eT.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>P(!0),children:"+ Create New Organization"}),(0,r.jsx)(E.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{P(!1),O.resetFields()},children:(0,r.jsxs)(I.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(v.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),b?(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 Organization"}),(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 organization?"})})]})})}),(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)(v.Z,{onClick:R,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),S(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(w.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lM=s(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lR=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lD[e];return l?l.fields.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(M.Z.Password,{}):(0,r.jsx)(y.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(I.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(C.default,{children:Object.entries(lL).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(I.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(E.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(w.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)(O.ZP,{onClick:n,children:"Done"})})]})]})};let lF=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lU=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=I.Z.useForm(),[d]=I.Z.useForm(),{Title:c,Paragraph:m}=J.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[P,T]=(0,i.useState)(!1),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,G]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lF(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){A.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,g.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),A.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,g.eH)(s,e.ip);let l=await (0,g.PT)(s);B(l),A.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),A.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{G(e),q(!0)},et=async()=>{if(H&&s)try{await (0,g.$I)(s,H);let e=await (0,g.PT)(s);B(e.length>0?e:[X]),A.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),A.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),G(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,g.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,g.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,g.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;A.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,g.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,g.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,g.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:()=>!0===a?T(!0):A.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lR,{isAddSSOModalVisible:P,isInstructionsModalVisible:L,handleAddSSOOk:()=>{T(!1),o.resetFields()},handleAddSSOCancel:()=>{T(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),T(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(E.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(v.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"IP Address"}),(0,r.jsx)(ey.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:K.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e}),(0,r.jsx)(e_.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(v.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(E.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(I.Z,{onFinish:el,children:[(0,r.jsx)(I.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(M.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(I.Z.Item,{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(E.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(v.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lM.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lz=s(92858),lV=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=I.Z.useForm();return(0,r.jsxs)(I.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{align:"center",children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(I.Z.Item,{name:e.field_name,children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(I.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lq=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,g.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lV,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,g.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,g.jA)(l,"alerting",["slack"]):(0,g.jA)(l,"alerting",[])),A.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lK=s(86582);let{Title:lB,Paragraph:lH}=J.default;console.log=function(){};var lJ=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=I.Z.useForm(),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)(""),[N,S]=(0,i.useState)({}),[k,P]=(0,i.useState)([]),[T,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),J=e=>{k.includes(e)?P(k.filter(l=>l!==e)):P([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),P(e.active_alerts),Z(s),S(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,g.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,g.K_)(l,{environment_variables:s}),A.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,g.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),A.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(ek.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(ek.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(ek.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(_.Z,{numItems:2,children:(0,r.jsx)(eS.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ey.Z,{children:"Callback Name"})})}),(0,r.jsx)(ef.Z,{children:n.map((e,s)=>(0,r.jsxs)(eb.Z,{className:"flex justify-between",children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(w.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)}):(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:b})})]},l)})})]}),(0,r.jsx)(v.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,g.K_)(l,s)}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lq,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Email Settings"}),(0,r.jsxs)(w.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(e_.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(_.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(w.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"mt-2",children:l}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(E.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(I.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lK.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(C.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(H.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lK.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(y.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(E.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(I.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lK.Z,{label:l,name:l,children:(0,r.jsx)(y.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lG=s(92414),lW=s(46030);let{Option:lY}=C.default;var l$=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(E.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(I.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,g.K_)(s,{router_settings:o}),a(o)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eN.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(I.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lG.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lX=s(33619);async function lQ(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lX.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});A.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l0={ttl:3600,lowest_latency_buffer:0},l1=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(Z.Z,{children:"latency-based-routing"==l?(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(w.Z,{children:"No specific settings"})})]})};var l2=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=I.Z.useForm(),[j,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[k,C]=(0,i.useState)(null),E={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,g.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,g.K_)(l,{router_settings:t}),o(t),A.ZP.success("Router settings updated successfully")}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},M=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,g.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,g.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,g.K_)(l,{router_settings:s})}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(ek.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(ek.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(S.Z,{children:"Router Settings"}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:E[l]})]}),(0,r.jsx)(e_.Z,{children:"routing_strategy"==l?(0,r.jsxs)(eN.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(H.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(H.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(H.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l1,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l0,paramExplanation:E})]}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Model Name"}),(0,r.jsx)(ey.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(ef.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:t}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{onClick:()=>lQ(t,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(l$,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"}),(0,r.jsx)(ey.Z,{children:"Status"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(e_.Z,{children:"Integer"==e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(v.Z,{onClick:()=>M(e.field_name,l),children:"Update"}),(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l4=s(93142),l5=s(45246),l3=s(96473),l6=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l4.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(y.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(y.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l5.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(O.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l3.Z,{}),children:"Add Header"})]})};let{Option:l8}=C.default;var l7=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=I.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(E.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(I.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,g.Vt)(l,e),s(r)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l6,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},l9=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,g.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,g.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),A.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Path"}),(0,r.jsx)(ey.Z,{children:"Target"}),(0,r.jsx)(ey.Z,{children:"Headers"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:n.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.path})}),(0,r.jsx)(e_.Z,{children:e.target}),(0,r.jsx)(e_.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l7,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},se=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=I.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call");let l=await (0,g.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),A.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(I.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=I.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call"),t(!0);let l=await (0,g.qI)(s,e);a(e=>e?[...e,l]:[l]),A.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(I.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},ss=s(17906),st=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,g.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;A.ZP.info("Request made"),await (0,g.NV)(l,e);let t=[...c];t.splice(s,1),m(t),A.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,g.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(v.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(se,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(sl,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Budget ID"}),(0,r.jsx)(ey.Z,{children:"Max Budget"}),(0,r.jsx)(ey.Z,{children:"TPM"}),(0,r.jsx)(ey.Z,{children:"RPM"})]})}),(0,r.jsx)(ef.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.budget_id}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(e_.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(e_.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(ek.Z,{children:"Test it (Curl)"}),(0,r.jsx)(ek.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sa=s(77398),sr=s.n(sa),si=s(20016);async function sn(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let so=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return sn(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sd=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sc=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sd(l)})},sm=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sc,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(U.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(so,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:eQ(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(U.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],su=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,g.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sh=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sx=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sp=["Internal User","Internal Viewer"],sg=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sj(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(sr()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(sr()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sp.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sp.includes(o)&&q(!0)},[o]);let B=(0,si.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=sr()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?sr()(S).utc().format("YYYY-MM-DD HH:mm:ss"):sr()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,g.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await su(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(sr()(N).format("MMM D, h:mm A")," - ").concat(sr()(S).format("MMM D, h:mm A"));let e=sr()(),l=sr()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>j(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),j(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(sr()().format("YYYY-MM-DDTHH:mm")),w(sr()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eZ,{columns:sm,data:H,renderSubComponent:sf,getRowCanExpand:()=>!0})]})]})}function sf(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sg,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sh,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var s_=s(92699),sv=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(w.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(ek.Z,{children:"LlamaIndex"}),(0,r.jsx)(ek.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sy=s(243),sb=s(94263);async function sZ(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lX.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sN=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[j,b]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[S,k]=(0,i.useState)([]),I=(0,i.useRef)(null),E=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,g.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),b(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{E.current&&setTimeout(()=>{var e;null===(e=E.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){A.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{j&&await sZ(i,(e,l)=>P("assistant",e,l),j,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=J.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)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsx)(eI.Z,{children:(0,r.jsx)(ek.Z,{children:"Chat"})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"API Key Source"}),(0,r.jsx)(C.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(f.Z,{className:"mx-2",children:[(0,r.jsx)(w.Z,{children:"Select Model:"}),(0,r.jsx)(C.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),b(e),N("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{b(e)},500)}})]})]}),(0,r.jsx)(v.Z,{onClick:()=>{p([]),A.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ej.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsxs)(ef.Z,{children:[x.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sy.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(ss.Z,{style:sb.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{ref:E,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(y.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(v.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sw=s(19226),sS=s(45937),sk=s(92403),sC=s(28595),sI=s(68208),sA=s(9775),sE=s(41361),sP=s(37527),sO=s(12660),sT=s(88009),sM=s(48231),sL=s(41169),sD=s(44625),sR=s(57400),sF=s(55322);let{Sider:sU}=sw.default,sz=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sk.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sC.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sI.Z,{}),roles:sx},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sA.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sE.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sx},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sO.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sT.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sM.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sL.Z,{}),roles:sx,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sD.Z,{}),roles:sx},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sR.Z,{}),roles:sx}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sO.Z,{}),roles:sx},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx}]}];var sV=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sz.find(l=>l.page===e);if(l)return l.key;for(let l of sz)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sz.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sw.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sU,{theme:"light",width:220,children:(0,r.jsx)(sS.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sq=s(40278),sK=s(96889),sB=s(97765);console.log=function(){};var sH=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,g.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let j=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",j]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sJ=s(69907),sG=s(53003),sW=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let sY=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var s$=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,k]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[J,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,g.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,g.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),y(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),k((await (0,g.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,g.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,g.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,g.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,g.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,g.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,g.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,g.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>k(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,g.b1)(l,null,void 0,void 0),y,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,g.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},eZ=async()=>{if(l)try{let e=await (0,g.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",J),eo(),ed(),ec(),em(),eg(),eZ(),sY(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==J?void 0:J.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(w.Z,{className:"mt-4",children:["SpendLogs in DB has ",J.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(v.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mt-2",children:[(0,r.jsx)(ek.Z,{children:"All Up"}),sY(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ek.Z,{children:"Team Based Usage"}),(0,r.jsx)(ek.Z,{children:"Customer Usage"}),(0,r.jsx)(ek.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(ek.Z,{children:"Cost"}),(0,r.jsx)(ek.Z,{children:"Activity"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(w.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sH,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Monthly Spend"}),(0,r.jsx)(sq.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top API Keys"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top Models"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Provider"}),(0,r.jsx)(ey.Z,{children:"Spend"})]})}),(0,r.jsx)(ef.Z,{children:T.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.provider}),(0,r.jsx)(e_.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"All Up"}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:e.model}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sK.Z,{data:P})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sq.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(f.Z,{numColSpan:2})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Time Range"}),(0,r.jsx)(sG.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Key"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(eS.Z,{className:"mt-4",children:(0,r.jsxs)(ej.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Customer"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Total Events"})]})}),(0,r.jsx)(ef.Z,{children:null==j?void 0:j.map((e,l)=>{var s;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(e_.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sG.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(f.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lW.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(H.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(w.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sq.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(f.Z,{numColSpan:2})]})]})]})]})})},sX=s(51853);let sQ=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s0=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s1=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sX.Z,{className:"h-4 w-4"})})]})})})},s2=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s0(j.litellm_params)||{},_=s0(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s0(null==g?void 0:g.litellm_cache_params)||{},_=s0(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(w.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s1,{label:"Error Message",value:j.message}),(0,r.jsx)(s1,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s1,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s1,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s1,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s1,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s1,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s1,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s1,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s1,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s1,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s4=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(v.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(sQ,{responseTimeMs:n})]}),s&&(0,r.jsx)(s2,{response:s})]})},s5=e=>{if(e)return e.toISOString().split("T")[0]};function s3(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s6=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,v]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[S,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[E,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&S&&((async()=>{p(await (0,g.zg)(l,s5(S.from),s5(S.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,g.zg)(l,s5(e),s5(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);v(s3(s)),b(s3(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,S,x]);let L=async()=>{try{A.ZP.info("Running cache health check..."),P("");let e=await (0,g.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Cache Analytics"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(_.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(sG.Z,{enableSelect:!0,value:S,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:j})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sq.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sq.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(s4,{accessToken:l,healthCheckResponse:E,runCachingHealthCheck:L})})]})]})},s8=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,g.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(w.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Guardrail Name"}),(0,r.jsx)(ey.Z,{children:"Mode"}),(0,r.jsx)(ey.Z,{children:"Status"})]})}),(0,r.jsx)(ef.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.guardrail_name}),(0,r.jsx)(e_.Z,{children:e.litellm_params.mode}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s7=new d.S;function s9(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[f,_]=(0,i.useState)(null),[v,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,k]=(0,i.useState)(!0),C=(0,n.useSearchParams)(),[I,A]=(0,i.useState)({data:[]}),[E,P]=(0,i.useState)(null),O=C.get("userID"),T=C.get("invitation_id"),[M,L]=(0,i.useState)(()=>C.get("page")||"api-keys"),[D,R]=(0,i.useState)(null);return(0,i.useEffect)(()=>{P(function(e){let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"))},[]),(0,i.useEffect)(()=>{if(!E)return;let e=(0,o.o)(E);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),R(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&L("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?k("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,g.K8)(e.auth_header_name)}},[E]),(0,i.useEffect)(()=>{D&&O&&e&&em(O,e,D,Z),D&&O&&e&&j(D,O,e,null,x),D&&lO(D,y)},[D,O,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s7,children:T?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(p,{userID:O,userRole:e,premiumUser:s,setProxySettings:w,proxySettings:N}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sV,{setPage:e=>{let l=new URLSearchParams(C);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),L(e)},userRole:e,defaultSelectedKey:M})}),"api-keys"==M?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):"models"==M?(0,r.jsx)(lZ,{userID:O,userRole:e,token:E,keys:f,accessToken:D,modelData:I,setModelData:A,premiumUser:s,teams:h}):"llm-playground"==M?(0,r.jsx)(sN,{userID:O,userRole:e,token:E,accessToken:D,disabledPersonalKeyCreation:a}):"users"==M?(0,r.jsx)(lC,{userID:O,userRole:e,token:E,keys:f,teams:h,accessToken:D,setKeys:_}):"teams"==M?(0,r.jsx)(lE,{teams:h,setTeams:x,searchParams:C,accessToken:D,userID:O,userRole:e,organizations:v}):"organizations"==M?(0,r.jsx)(lT,{organizations:v,setOrganizations:y,userModels:b,accessToken:D,userRole:e,premiumUser:s}):"admin-panel"==M?(0,r.jsx)(lU,{setTeams:x,searchParams:C,accessToken:D,showSSOBanner:S,premiumUser:s}):"api_ref"==M?(0,r.jsx)(sv,{proxySettings:N}):"settings"==M?(0,r.jsx)(lJ,{userID:O,userRole:e,accessToken:D,premiumUser:s}):"budgets"==M?(0,r.jsx)(st,{accessToken:D}):"guardrails"==M?(0,r.jsx)(s8,{accessToken:D}):"general-settings"==M?(0,r.jsx)(l2,{userID:O,userRole:e,accessToken:D,modelData:I}):"model-hub"==M?(0,r.jsx)(s_.Z,{accessToken:D,publicPage:!1,premiumUser:s}):"caching"==M?(0,r.jsx)(s6,{userID:O,userRole:e,token:E,accessToken:D,premiumUser:s}):"pass-through-settings"==M?(0,r.jsx)(l9,{userID:O,userRole:e,accessToken:D,modelData:I}):"logs"==M?(0,r.jsx)(sj,{userID:O,userRole:e,token:E,accessToken:D}):(0,r.jsx)(s$,{userID:O,userRole:e,token:E,accessToken:D,keys:f,premiumUser:s})]})]})})})}}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_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 ae2e51152b..07624d4899 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 32025bae5b..0830197521 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-e28453cd004ff93c.js"],"default",1] +3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-a006114359094d34.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/model_hub.html b/ui/litellm-dashboard/out/model_hub.html index c379b2e0cc..3633aad3e7 100644 --- a/ui/litellm-dashboard/out/model_hub.html +++ b/ui/litellm-dashboard/out/model_hub.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/model_hub.txt b/ui/litellm-dashboard/out/model_hub.txt index 2bef2383df..54a3766fb8 100644 --- a/ui/litellm-dashboard/out/model_hub.txt +++ b/ui/litellm-dashboard/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","418","static/chunks/app/model_hub/page-6f97b95f1023b0e9.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/onboarding.html b/ui/litellm-dashboard/out/onboarding.html index 11decf6639..3b4d5d430f 100644 --- a/ui/litellm-dashboard/out/onboarding.html +++ b/ui/litellm-dashboard/out/onboarding.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/onboarding.txt b/ui/litellm-dashboard/out/onboarding.txt index ec0568e731..e05b041088 100644 --- a/ui/litellm-dashboard/out/onboarding.txt +++ b/ui/litellm-dashboard/out/onboarding.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-f2e9aa9e77b66520.js"],"default",1] +3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-8ba945cf183c937c.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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 From 2fc62626755fe711ffcd1661398a838362e8bba3 Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Mon, 3 Mar 2025 22:57:08 -0800 Subject: [PATCH 04/12] =?UTF-8?q?fix(route=5Fllm=5Frequest.py):=20move=20t?= =?UTF-8?q?o=20using=20common=20router,=20even=20for=20clie=E2=80=A6=20(#8?= =?UTF-8?q?966)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route_llm_request.py): move to using common router, even for client-side credentials ensures fallbacks / cooldown logic still works * test(test_route_llm_request.py): add unit test for route request * feat(router.py): generate unique model id when clientside credential passed in Prevents cooldowns for api key 1 from impacting api key 2 * test(test_router.py): update testing to ensure original litellm params not mutated * fix(router.py): upsert clientside call into llm router model list enables cooldown logic to work accurately * fix: fix linting error * test(test_router_utils.py): add direct test for new util on router --- litellm/proxy/_new_secret_config.yaml | 39 +++---------- litellm/proxy/route_llm_request.py | 2 +- litellm/router.py | 57 +++++++++++++++++-- .../clientside_credential_handler.py | 37 ++++++++++++ litellm/router_utils/cooldown_handlers.py | 16 ++++++ tests/litellm/proxy/test_route_llm_request.py | 46 +++++++++++++++ tests/local_testing/test_router.py | 43 ++++++++++++++ tests/local_testing/test_router_cooldowns.py | 47 +++++++++++++++ tests/local_testing/test_router_utils.py | 22 +++++++ 9 files changed, 273 insertions(+), 36 deletions(-) create mode 100644 litellm/router_utils/clientside_credential_handler.py create mode 100644 tests/litellm/proxy/test_route_llm_request.py diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index 649d5a25d0..ba355c0dc4 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -1,34 +1,11 @@ model_list: - - model_name: claude-3.7 + - model_name: openai-gpt-4o-mini-2024-07-18 litellm_params: - model: openai/gpt-3.5-turbo - api_key: os.environ/OPENAI_API_KEY - api_base: http://0.0.0.0:8090 - - model_name: deepseek-r1 - litellm_params: - model: bedrock/deepseek_r1/arn:aws:bedrock:us-west-2:888602223428:imported-model/bnnr6463ejgf - - model_name: deepseek-r1-api - litellm_params: - model: deepseek/deepseek-reasoner - - model_name: cohere.embed-english-v3 - litellm_params: - model: bedrock/cohere.embed-english-v3 - api_key: os.environ/COHERE_API_KEY - - model_name: bedrock-claude-3-7 - litellm_params: - model: bedrock/invoke/us.anthropic.claude-3-7-sonnet-20250219-v1:0 - - model_name: bedrock-claude-3-5-sonnet - litellm_params: - model: bedrock/invoke/us.anthropic.claude-3-5-sonnet-20240620-v1:0 - - model_name: bedrock-nova - litellm_params: - model: bedrock/us.amazon.nova-pro-v1:0 - - model_name: gpt-4o - litellm_params: - model: openai/gpt-4o + model: openai/gpt-4o-mini-2024-07-18 + configurable_clientside_auth_params: ["api_key"] + api_key: "my-bad-key" + # - model_name: openai-fallback-model + # litellm_params: + # model: openai/gpt-3.5-turbo + -litellm_settings: - cache: true - cache_params: # set cache params for redis - type: redis - namespace: "litellm.caching" diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py index 6102a26b23..6683a18b9a 100644 --- a/litellm/proxy/route_llm_request.py +++ b/litellm/proxy/route_llm_request.py @@ -53,7 +53,7 @@ async def route_request( """ router_model_names = llm_router.model_names if llm_router is not None else [] if "api_key" in data or "api_base" in data: - return getattr(litellm, f"{route_type}")(**data) + return getattr(llm_router, f"{route_type}")(**data) elif "user_config" in data: router_config = data.pop("user_config") diff --git a/litellm/router.py b/litellm/router.py index 4e93baf328..880950b227 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -67,6 +67,10 @@ from litellm.router_utils.batch_utils import ( replace_model_in_jsonl, ) from litellm.router_utils.client_initalization_utils import InitalizeOpenAISDKClient +from litellm.router_utils.clientside_credential_handler import ( + get_dynamic_litellm_params, + is_clientside_credential, +) from litellm.router_utils.cooldown_cache import CooldownCache from litellm.router_utils.cooldown_handlers import ( DEFAULT_COOLDOWN_TIME_SECONDS, @@ -1067,20 +1071,61 @@ class Router: elif k == "metadata": kwargs[k].update(v) + def _handle_clientside_credential( + self, deployment: dict, kwargs: dict + ) -> Deployment: + """ + Handle clientside credential + """ + model_info = deployment.get("model_info", {}).copy() + litellm_params = deployment["litellm_params"].copy() + dynamic_litellm_params = get_dynamic_litellm_params( + litellm_params=litellm_params, request_kwargs=kwargs + ) + metadata = kwargs.get("metadata", {}) + model_group = cast(str, metadata.get("model_group")) + _model_id = self._generate_model_id( + model_group=model_group, litellm_params=dynamic_litellm_params + ) + original_model_id = model_info.get("id") + model_info["id"] = _model_id + model_info["original_model_id"] = original_model_id + deployment_pydantic_obj = Deployment( + model_name=model_group, + litellm_params=LiteLLM_Params(**dynamic_litellm_params), + model_info=model_info, + ) + self.upsert_deployment( + deployment=deployment_pydantic_obj + ) # add new deployment to router + return deployment_pydantic_obj + def _update_kwargs_with_deployment(self, deployment: dict, kwargs: dict) -> None: """ 2 jobs: - Adds selected deployment, model_info and api_base to kwargs["metadata"] (used for logging) - Adds default litellm params to kwargs, if set. """ + model_info = deployment.get("model_info", {}).copy() + deployment_model_name = deployment["litellm_params"]["model"] + deployment_api_base = deployment["litellm_params"].get("api_base") + if is_clientside_credential(request_kwargs=kwargs): + deployment_pydantic_obj = self._handle_clientside_credential( + deployment=deployment, kwargs=kwargs + ) + model_info = deployment_pydantic_obj.model_info.model_dump() + deployment_model_name = deployment_pydantic_obj.litellm_params.model + deployment_api_base = deployment_pydantic_obj.litellm_params.api_base + kwargs.setdefault("metadata", {}).update( { - "deployment": deployment["litellm_params"]["model"], - "model_info": deployment.get("model_info", {}), - "api_base": deployment.get("litellm_params", {}).get("api_base"), + "deployment": deployment_model_name, + "model_info": model_info, + "api_base": deployment_api_base, } ) - kwargs["model_info"] = deployment.get("model_info", {}) + kwargs["model_info"] = model_info + kwargs["timeout"] = self._get_timeout( kwargs=kwargs, data=deployment["litellm_params"] ) @@ -3601,6 +3646,7 @@ class Router: - True if the deployment should be put in cooldown - False if the deployment should not be put in cooldown """ + verbose_router_logger.debug("Router: Entering 'deployment_callback_on_failure'") try: exception = kwargs.get("exception", None) exception_status = getattr(exception, "status_code", "") @@ -3642,6 +3688,9 @@ class Router: return result else: + verbose_router_logger.debug( + "Router: Exiting 'deployment_callback_on_failure' without cooldown. No model_info found." + ) return False except Exception as e: diff --git a/litellm/router_utils/clientside_credential_handler.py b/litellm/router_utils/clientside_credential_handler.py new file mode 100644 index 0000000000..c98f614335 --- /dev/null +++ b/litellm/router_utils/clientside_credential_handler.py @@ -0,0 +1,37 @@ +""" +Utils for handling clientside credentials + +Supported clientside credentials: +- api_key +- api_base +- base_url + +If given, generate a unique model_id for the deployment. + +Ensures cooldowns are applied correctly. +""" + +clientside_credential_keys = ["api_key", "api_base", "base_url"] + + +def is_clientside_credential(request_kwargs: dict) -> bool: + """ + Check if the credential is a clientside credential. + """ + return any(key in request_kwargs for key in clientside_credential_keys) + + +def get_dynamic_litellm_params(litellm_params: dict, request_kwargs: dict) -> dict: + """ + Generate a unique model_id for the deployment. + + Returns + - litellm_params: dict + + for generating a unique model_id. + """ + # update litellm_params with clientside credentials + for key in clientside_credential_keys: + if key in request_kwargs: + litellm_params[key] = request_kwargs[key] + return litellm_params diff --git a/litellm/router_utils/cooldown_handlers.py b/litellm/router_utils/cooldown_handlers.py index 64a6d56a77..52babc27f2 100644 --- a/litellm/router_utils/cooldown_handlers.py +++ b/litellm/router_utils/cooldown_handlers.py @@ -112,12 +112,19 @@ def _should_run_cooldown_logic( deployment is None or litellm_router_instance.get_model_group(id=deployment) is None ): + verbose_router_logger.debug( + "Should Not Run Cooldown Logic: deployment id is none or model group can't be found." + ) return False if litellm_router_instance.disable_cooldowns: + verbose_router_logger.debug( + "Should Not Run Cooldown Logic: disable_cooldowns is True" + ) return False if deployment is None: + verbose_router_logger.debug("Should Not Run Cooldown Logic: deployment is None") return False if not _is_cooldown_required( @@ -126,9 +133,15 @@ def _should_run_cooldown_logic( exception_status=exception_status, exception_str=str(original_exception), ): + verbose_router_logger.debug( + "Should Not Run Cooldown Logic: _is_cooldown_required returned False" + ) return False if deployment in litellm_router_instance.provider_default_deployment_ids: + verbose_router_logger.debug( + "Should Not Run Cooldown Logic: deployment is in provider_default_deployment_ids" + ) return False return True @@ -244,6 +257,8 @@ def _set_cooldown_deployments( - True if the deployment should be put in cooldown - False if the deployment should not be put in cooldown """ + verbose_router_logger.debug("checks 'should_run_cooldown_logic'") + if ( _should_run_cooldown_logic( litellm_router_instance, deployment, exception_status, original_exception @@ -251,6 +266,7 @@ def _set_cooldown_deployments( is False or deployment is None ): + verbose_router_logger.debug("should_run_cooldown_logic returned False") return False exception_status_int = cast_exception_status_to_int(exception_status) diff --git a/tests/litellm/proxy/test_route_llm_request.py b/tests/litellm/proxy/test_route_llm_request.py new file mode 100644 index 0000000000..6e8fedf0cb --- /dev/null +++ b/tests/litellm/proxy/test_route_llm_request.py @@ -0,0 +1,46 @@ +import json +import os +import sys + +import pytest +from fastapi.testclient import TestClient + +sys.path.insert( + 0, os.path.abspath("../../..") +) # Adds the parent directory to the system path + + +from unittest.mock import MagicMock + +from litellm.proxy.route_llm_request import route_request + + +@pytest.mark.parametrize( + "route_type", + [ + "atext_completion", + "acompletion", + "aembedding", + "aimage_generation", + "aspeech", + "atranscription", + "amoderation", + "arerank", + ], +) +@pytest.mark.asyncio +async def test_route_request_dynamic_credentials(route_type): + data = { + "model": "openai/gpt-4o-mini-2024-07-18", + "api_key": "my-bad-key", + "api_base": "https://api.openai.com/v1 ", + } + llm_router = MagicMock() + # Ensure that the dynamic method exists on the llm_router mock. + getattr(llm_router, route_type).return_value = "fake_response" + + response = await route_request(data, llm_router, None, route_type) + # Optionally verify the response if needed: + assert response == "fake_response" + # Now assert that the dynamic method was called once with the expected kwargs. + getattr(llm_router, route_type).assert_called_once_with(**data) diff --git a/tests/local_testing/test_router.py b/tests/local_testing/test_router.py index 698f779b78..0f690a94f2 100644 --- a/tests/local_testing/test_router.py +++ b/tests/local_testing/test_router.py @@ -2777,3 +2777,46 @@ def test_router_get_model_list_from_model_alias(): model_name="gpt-3.5-turbo" ) assert len(model_alias_list) == 0 + + +def test_router_dynamic_credentials(): + """ + Assert model id for dynamic api key 1 != model id for dynamic api key 2 + """ + original_model_id = "123" + original_api_key = "my-bad-key" + router = Router( + model_list=[ + { + "model_name": "gpt-3.5-turbo", + "litellm_params": { + "model": "openai/gpt-3.5-turbo", + "api_key": original_api_key, + "mock_response": "fake_response", + }, + "model_info": {"id": original_model_id}, + } + ] + ) + + deployment = router.get_deployment(model_id=original_model_id) + assert deployment is not None + assert deployment.litellm_params.api_key == original_api_key + + response = router.completion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hi"}], + api_key="my-bad-key-2", + ) + + response_2 = router.completion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hi"}], + api_key="my-bad-key-3", + ) + + assert response_2._hidden_params["model_id"] != response._hidden_params["model_id"] + + deployment = router.get_deployment(model_id=original_model_id) + assert deployment is not None + assert deployment.litellm_params.api_key == original_api_key diff --git a/tests/local_testing/test_router_cooldowns.py b/tests/local_testing/test_router_cooldowns.py index 38d4133afd..80ceb33c01 100644 --- a/tests/local_testing/test_router_cooldowns.py +++ b/tests/local_testing/test_router_cooldowns.py @@ -692,3 +692,50 @@ def test_router_fallbacks_with_cooldowns_and_model_id(): model="gpt-3.5-turbo", messages=[{"role": "user", "content": "hi"}], ) + + +@pytest.mark.asyncio() +async def test_router_fallbacks_with_cooldowns_and_dynamic_credentials(): + """ + Ensure cooldown on credential 1 does not affect credential 2 + """ + from litellm.router_utils.cooldown_handlers import _async_get_cooldown_deployments + + litellm._turn_on_debug() + router = Router( + model_list=[ + { + "model_name": "gpt-3.5-turbo", + "litellm_params": {"model": "gpt-3.5-turbo", "rpm": 1}, + "model_info": { + "id": "123", + }, + } + ] + ) + + ## trigger ratelimit + try: + await router.acompletion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hi"}], + api_key="my-bad-key-1", + mock_response="litellm.RateLimitError", + ) + pytest.fail("Expected RateLimitError") + except litellm.RateLimitError: + pass + + await asyncio.sleep(1) + + cooldown_list = await _async_get_cooldown_deployments( + litellm_router_instance=router, parent_otel_span=None + ) + print("cooldown_list: ", cooldown_list) + assert len(cooldown_list) == 1 + + await router.acompletion( + model="gpt-3.5-turbo", + api_key=os.getenv("OPENAI_API_KEY"), + messages=[{"role": "user", "content": "hi"}], + ) diff --git a/tests/local_testing/test_router_utils.py b/tests/local_testing/test_router_utils.py index 7de9707579..7c2bbdc2a1 100644 --- a/tests/local_testing/test_router_utils.py +++ b/tests/local_testing/test_router_utils.py @@ -396,3 +396,25 @@ def test_router_redis_cache(): router._update_redis_cache(cache=redis_cache) assert router.cache.redis_cache == redis_cache + + +def test_router_handle_clientside_credential(): + deployment = { + "model_name": "gemini/*", + "litellm_params": {"model": "gemini/*"}, + "model_info": { + "id": "1", + }, + } + router = Router(model_list=[deployment]) + + new_deployment = router._handle_clientside_credential( + deployment=deployment, + kwargs={ + "api_key": "123", + "metadata": {"model_group": "gemini/gemini-1.5-flash"}, + }, + ) + + assert new_deployment.litellm_params.api_key == "123" + assert len(router.get_model_list()) == 2 From 87dd195b51afad1315b5064585311c06057fb725 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 3 Mar 2025 23:00:24 -0800 Subject: [PATCH 05/12] =?UTF-8?q?bump:=20version=201.62.2=20=E2=86=92=201.?= =?UTF-8?q?62.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 44d08c6757..4f5b42b604 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,7 +96,7 @@ requires = ["poetry-core", "wheel"] build-backend = "poetry.core.masonry.api" [tool.commitizen] -version = "1.62.2" +version = "1.62.3" version_files = [ "pyproject.toml:^version" ] From 8ea3d4c046bfdebe6ac08e29be8addee45a62b22 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 3 Mar 2025 23:05:41 -0800 Subject: [PATCH 06/12] build: merge litellm_dev_03_01_2025_p2 --- .../langfuse/langfuse_prompt_management.py | 8 ++- .../proxy/_experimental/out/onboarding.html | 1 - litellm/proxy/_new_secret_config.yaml | 16 ++--- litellm/proxy/_types.py | 5 ++ litellm/proxy/litellm_pre_call_utils.py | 9 ++- litellm/router.py | 15 +++- litellm/utils.py | 21 +++++- .../local_testing/test_least_busy_routing.py | 2 +- .../test_router_get_deployments.py | 2 +- .../local_testing/test_router_tag_routing.py | 68 +++++++++++++++++-- .../local_testing/test_tpm_rpm_routing_v2.py | 1 + 11 files changed, 124 insertions(+), 24 deletions(-) delete mode 100644 litellm/proxy/_experimental/out/onboarding.html diff --git a/litellm/integrations/langfuse/langfuse_prompt_management.py b/litellm/integrations/langfuse/langfuse_prompt_management.py index cc2a6cf80d..1f4ca84db3 100644 --- a/litellm/integrations/langfuse/langfuse_prompt_management.py +++ b/litellm/integrations/langfuse/langfuse_prompt_management.py @@ -40,6 +40,7 @@ in_memory_dynamic_logger_cache = DynamicLoggingCache() def langfuse_client_init( langfuse_public_key=None, langfuse_secret=None, + langfuse_secret_key=None, langfuse_host=None, flush_interval=1, ) -> LangfuseClass: @@ -67,7 +68,10 @@ def langfuse_client_init( ) # Instance variables - secret_key = langfuse_secret or os.getenv("LANGFUSE_SECRET_KEY") + + secret_key = ( + langfuse_secret or langfuse_secret_key or os.getenv("LANGFUSE_SECRET_KEY") + ) public_key = langfuse_public_key or os.getenv("LANGFUSE_PUBLIC_KEY") langfuse_host = langfuse_host or os.getenv( "LANGFUSE_HOST", "https://cloud.langfuse.com" @@ -190,6 +194,7 @@ class LangfusePromptManagement(LangFuseLogger, PromptManagementBase, CustomLogge langfuse_client = langfuse_client_init( langfuse_public_key=dynamic_callback_params.get("langfuse_public_key"), langfuse_secret=dynamic_callback_params.get("langfuse_secret"), + langfuse_secret_key=dynamic_callback_params.get("langfuse_secret_key"), langfuse_host=dynamic_callback_params.get("langfuse_host"), ) langfuse_prompt_client = self._get_prompt_from_id( @@ -206,6 +211,7 @@ class LangfusePromptManagement(LangFuseLogger, PromptManagementBase, CustomLogge langfuse_client = langfuse_client_init( langfuse_public_key=dynamic_callback_params.get("langfuse_public_key"), langfuse_secret=dynamic_callback_params.get("langfuse_secret"), + langfuse_secret_key=dynamic_callback_params.get("langfuse_secret_key"), langfuse_host=dynamic_callback_params.get("langfuse_host"), ) langfuse_prompt_client = self._get_prompt_from_id( diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html deleted file mode 100644 index 3b4d5d430f..0000000000 --- a/litellm/proxy/_experimental/out/onboarding.html +++ /dev/null @@ -1 +0,0 @@ -LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index ba355c0dc4..c01d2e7751 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -1,11 +1,9 @@ model_list: - - model_name: openai-gpt-4o-mini-2024-07-18 + - model_name: my-langfuse-model litellm_params: - model: openai/gpt-4o-mini-2024-07-18 - configurable_clientside_auth_params: ["api_key"] - api_key: "my-bad-key" - # - model_name: openai-fallback-model - # litellm_params: - # model: openai/gpt-3.5-turbo - - + model: langfuse/openai-model + api_key: os.environ/OPENAI_API_KEY + - model_name: openai-model + litellm_params: + model: openai/gpt-3.5-turbo + api_key: os.environ/OPENAI_API_KEY diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 6a427fed8a..ba27de78be 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -1003,6 +1003,7 @@ class AddTeamCallback(LiteLLMPydanticObjectBase): class TeamCallbackMetadata(LiteLLMPydanticObjectBase): success_callback: Optional[List[str]] = [] failure_callback: Optional[List[str]] = [] + callbacks: Optional[List[str]] = [] # for now - only supported for langfuse callback_vars: Optional[Dict[str, str]] = {} @@ -1015,6 +1016,9 @@ class TeamCallbackMetadata(LiteLLMPydanticObjectBase): failure_callback = values.get("failure_callback", []) if failure_callback is None: values.pop("failure_callback", None) + callbacks = values.get("callbacks", []) + if callbacks is None: + values.pop("callbacks", None) callback_vars = values.get("callback_vars", {}) if callback_vars is None: @@ -1023,6 +1027,7 @@ class TeamCallbackMetadata(LiteLLMPydanticObjectBase): return { "success_callback": [], "failure_callback": [], + "callbacks": [], "callback_vars": {}, } valid_keys = set(StandardCallbackDynamicParams.__annotations__.keys()) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index c15bbbd4a7..693e44ac77 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -102,11 +102,15 @@ def convert_key_logging_metadata_to_callback( if data.callback_name not in team_callback_settings_obj.failure_callback: team_callback_settings_obj.failure_callback.append(data.callback_name) - elif data.callback_type == "success_and_failure": + elif ( + not data.callback_type or data.callback_type == "success_and_failure" + ): # assume 'success_and_failure' = litellm.callbacks if team_callback_settings_obj.success_callback is None: team_callback_settings_obj.success_callback = [] if team_callback_settings_obj.failure_callback is None: team_callback_settings_obj.failure_callback = [] + if team_callback_settings_obj.callbacks is None: + team_callback_settings_obj.callbacks = [] if data.callback_name not in team_callback_settings_obj.success_callback: team_callback_settings_obj.success_callback.append(data.callback_name) @@ -114,6 +118,9 @@ def convert_key_logging_metadata_to_callback( if data.callback_name not in team_callback_settings_obj.failure_callback: team_callback_settings_obj.failure_callback.append(data.callback_name) + if data.callback_name not in team_callback_settings_obj.callbacks: + team_callback_settings_obj.callbacks.append(data.callback_name) + for var, value in data.callback_vars.items(): if team_callback_settings_obj.callback_vars is None: team_callback_settings_obj.callback_vars = {} diff --git a/litellm/router.py b/litellm/router.py index 880950b227..8b0bbd6b9f 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -1750,6 +1750,7 @@ class Router: model=model, messages=[{"role": "user", "content": "prompt"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) @@ -1863,6 +1864,7 @@ class Router: model=model, messages=[{"role": "user", "content": "prompt"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) @@ -1961,6 +1963,7 @@ class Router: model=model, messages=[{"role": "user", "content": "prompt"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_before_fallbacks(model=model, kwargs=kwargs) data = deployment["litellm_params"].copy() @@ -2036,6 +2039,7 @@ class Router: deployment = await self.async_get_available_deployment( model=model, specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) data = deployment["litellm_params"].copy() @@ -2080,6 +2084,7 @@ class Router: model=model, messages=messages, specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) data = deployment["litellm_params"].copy() @@ -2185,6 +2190,7 @@ class Router: model=model, messages=[{"role": "user", "content": prompt}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) @@ -2283,6 +2289,7 @@ class Router: model=model, messages=[{"role": "user", "content": "default text"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) @@ -2452,6 +2459,7 @@ class Router: model=model, input=input, specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) data = deployment["litellm_params"].copy() @@ -2549,6 +2557,7 @@ class Router: model=model, messages=[{"role": "user", "content": "files-api-fake-text"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) self._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) @@ -2654,6 +2663,7 @@ class Router: model=model, messages=[{"role": "user", "content": "files-api-fake-text"}], specific_deployment=kwargs.pop("specific_deployment", None), + request_kwargs=kwargs, ) metadata_variable_name = _get_router_metadata_variable_name( function_name="_acreate_batch" @@ -2850,7 +2860,8 @@ class Router: ): if kwargs.get("model") and self.get_model_list(model_name=kwargs["model"]): deployment = await self.async_get_available_deployment( - model=kwargs["model"] + model=kwargs["model"], + request_kwargs=kwargs, ) kwargs["model"] = deployment["litellm_params"]["model"] return await original_function(**kwargs) @@ -5590,10 +5601,10 @@ class Router: async def async_get_available_deployment( self, model: str, + request_kwargs: Dict, messages: Optional[List[Dict[str, str]]] = None, input: Optional[Union[str, List]] = None, specific_deployment: Optional[bool] = False, - request_kwargs: Optional[Dict] = None, ): """ Async implementation of 'get_available_deployments'. diff --git a/litellm/utils.py b/litellm/utils.py index 495b0d45a6..cbd5e2d0d3 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -451,6 +451,15 @@ def get_applied_guardrails(kwargs: Dict[str, Any]) -> List[str]: return applied_guardrails +def get_dynamic_callbacks( + dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] +) -> List: + returned_callbacks = litellm.callbacks.copy() + if dynamic_callbacks: + returned_callbacks.extend(dynamic_callbacks) # type: ignore + return returned_callbacks + + def function_setup( # noqa: PLR0915 original_function: str, rules_obj, start_time, *args, **kwargs ): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc. @@ -475,12 +484,18 @@ def function_setup( # noqa: PLR0915 ## LOGGING SETUP function_id: Optional[str] = kwargs["id"] if "id" in kwargs else None - if len(litellm.callbacks) > 0: - for callback in litellm.callbacks: + ## DYNAMIC CALLBACKS ## + dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = ( + kwargs.pop("callbacks", None) + ) + all_callbacks = get_dynamic_callbacks(dynamic_callbacks=dynamic_callbacks) + + if len(all_callbacks) > 0: + for callback in all_callbacks: # check if callback is a string - e.g. "lago", "openmeter" if isinstance(callback, str): callback = litellm.litellm_core_utils.litellm_logging._init_custom_logger_compatible_class( # type: ignore - callback, internal_usage_cache=None, llm_router=None + callback, internal_usage_cache=None, llm_router=None # type: ignore ) if callback is None or any( isinstance(cb, type(callback)) diff --git a/tests/local_testing/test_least_busy_routing.py b/tests/local_testing/test_least_busy_routing.py index c9c6eb6093..cf69f596d9 100644 --- a/tests/local_testing/test_least_busy_routing.py +++ b/tests/local_testing/test_least_busy_routing.py @@ -119,7 +119,7 @@ async def test_router_get_available_deployments(async_test): if async_test is True: await router.cache.async_set_cache(key=cache_key, value=request_count_dict) deployment = await router.async_get_available_deployment( - model=model_group, messages=None + model=model_group, messages=None, request_kwargs={} ) else: router.cache.set_cache(key=cache_key, value=request_count_dict) diff --git a/tests/local_testing/test_router_get_deployments.py b/tests/local_testing/test_router_get_deployments.py index d57ef0b81d..efbb5d16e7 100644 --- a/tests/local_testing/test_router_get_deployments.py +++ b/tests/local_testing/test_router_get_deployments.py @@ -569,7 +569,7 @@ async def test_weighted_selection_router_async(rpm_list, tpm_list): # call get_available_deployment 1k times, it should pick azure/chatgpt-v-2 about 90% of the time for _ in range(1000): selected_model = await router.async_get_available_deployment( - "gpt-3.5-turbo" + "gpt-3.5-turbo", request_kwargs={} ) selected_model_id = selected_model["litellm_params"]["model"] selected_model_name = selected_model_id diff --git a/tests/local_testing/test_router_tag_routing.py b/tests/local_testing/test_router_tag_routing.py index 47f2a0a8f9..4e30e1d8b6 100644 --- a/tests/local_testing/test_router_tag_routing.py +++ b/tests/local_testing/test_router_tag_routing.py @@ -26,11 +26,6 @@ import litellm from litellm import Router from litellm._logging import verbose_logger -verbose_logger.setLevel(logging.DEBUG) - - -load_dotenv() - @pytest.mark.asyncio() async def test_router_free_paid_tier(): @@ -93,6 +88,69 @@ async def test_router_free_paid_tier(): assert response_extra_info["model_id"] == "very-expensive-model" +@pytest.mark.asyncio() +async def test_router_free_paid_tier_embeddings(): + """ + Pass list of orgs in 1 model definition, + expect a unique deployment for each to be created + """ + router = litellm.Router( + model_list=[ + { + "model_name": "gpt-4", + "litellm_params": { + "model": "gpt-4o", + "api_base": "https://exampleopenaiendpoint-production.up.railway.app/", + "tags": ["free"], + "mock_response": ["1", "2", "3"], + }, + "model_info": {"id": "very-cheap-model"}, + }, + { + "model_name": "gpt-4", + "litellm_params": { + "model": "gpt-4o-mini", + "api_base": "https://exampleopenaiendpoint-production.up.railway.app/", + "tags": ["paid"], + "mock_response": ["1", "2", "3"], + }, + "model_info": {"id": "very-expensive-model"}, + }, + ], + enable_tag_filtering=True, + ) + + for _ in range(1): + # this should pick model with id == very-cheap-model + response = await router.aembedding( + model="gpt-4", + input="Tell me a joke.", + metadata={"tags": ["free"]}, + ) + + print("Response: ", response) + + response_extra_info = response._hidden_params + print("response_extra_info: ", response_extra_info) + + assert response_extra_info["model_id"] == "very-cheap-model" + + for _ in range(5): + # this should pick model with id == very-cheap-model + response = await router.aembedding( + model="gpt-4", + input="Tell me a joke.", + metadata={"tags": ["paid"]}, + ) + + print("Response: ", response) + + response_extra_info = response._hidden_params + print("response_extra_info: ", response_extra_info) + + assert response_extra_info["model_id"] == "very-expensive-model" + + @pytest.mark.asyncio() async def test_default_tagged_deployments(): """ diff --git a/tests/local_testing/test_tpm_rpm_routing_v2.py b/tests/local_testing/test_tpm_rpm_routing_v2.py index 879e8ee5dd..a7073b4acd 100644 --- a/tests/local_testing/test_tpm_rpm_routing_v2.py +++ b/tests/local_testing/test_tpm_rpm_routing_v2.py @@ -377,6 +377,7 @@ async def test_multiple_potential_deployments(sync_mode): deployment = await router.async_get_available_deployment( model="azure-model", messages=[{"role": "user", "content": "Hey, how's it going?"}], + request_kwargs={}, ) ## get id ## From b5beed5812649b3ca17b6681bb51644ac5f02edb Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Mon, 3 Mar 2025 23:06:11 -0800 Subject: [PATCH 07/12] Litellm dev 03 01 2025 p2 (#8944) * test(test_router_tag_routing.py): add unit test for tag-based routing on embeddings * fix(router.py): pass request kwargs on async embeddings to async_get_available_deployment function * fix(router.py): require request kwargs to always be passed in ensures tag-based routing always works, across endpoints * feat(langfuse_prompt_management.py): support using prompt management per langfuse project with key/team based logging * fix: fix linting error * fix: fix test * fix: fix test * fix: fix test * fix: fix linting error --- litellm/proxy/_new_secret_config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index c01d2e7751..7c3caf74ff 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -6,4 +6,4 @@ model_list: - model_name: openai-model litellm_params: model: openai/gpt-3.5-turbo - api_key: os.environ/OPENAI_API_KEY + api_key: os.environ/OPENAI_API_KEY \ No newline at end of file From 9baf4f7e563915d3b5fb4c8eace3300bd2158658 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 3 Mar 2025 23:31:45 -0800 Subject: [PATCH 08/12] fix: fix linting errors --- litellm/proxy/management_endpoints/ui_sso.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index d903e2665c..d092fd8800 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -7,12 +7,10 @@ Has all /sso/* routes import asyncio import os -import time import uuid from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast from fastapi import APIRouter, Depends, HTTPException, Request, status -from fastapi.responses import RedirectResponse import litellm from litellm._logging import verbose_proxy_logger From 5f1cac893015f3c53e2319ebb58e50a40b7dd2ae Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 4 Mar 2025 06:14:54 -0800 Subject: [PATCH 09/12] docs(data_security.md): update docs --- docs/my-website/docs/data_security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/my-website/docs/data_security.md b/docs/my-website/docs/data_security.md index 13cde26d5d..04ea97894f 100644 --- a/docs/my-website/docs/data_security.md +++ b/docs/my-website/docs/data_security.md @@ -46,7 +46,7 @@ For security inquiries, please contact us at support@berri.ai |-------------------|-------------------------------------------------------------------------------------------------| | SOC 2 Type I | Certified. Report available upon request on Enterprise plan. | | SOC 2 Type II | In progress. Certificate available by April 15th, 2025 | -| ISO27001 | In progress. Certificate available by February 7th, 2025 | +| ISO 27001 | Certified. Report available upon request on Enterprise | ## Supported Data Regions for LiteLLM Cloud From e40218513b7a5bd39e66d479eb14478b18f36360 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 4 Mar 2025 06:15:15 -0800 Subject: [PATCH 10/12] docs(data_security.md): cleanup docs --- docs/my-website/docs/data_security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/my-website/docs/data_security.md b/docs/my-website/docs/data_security.md index 04ea97894f..30128760f2 100644 --- a/docs/my-website/docs/data_security.md +++ b/docs/my-website/docs/data_security.md @@ -137,7 +137,7 @@ Point of contact email address for general security-related questions: krrish@be Has the Vendor been audited / certified? - SOC 2 Type I. Certified. Report available upon request on Enterprise plan. - SOC 2 Type II. In progress. Certificate available by April 15th, 2025. -- ISO27001. In progress. Certificate available by February 7th, 2025. +- ISO 27001. Certified. Report available upon request on Enterprise plan. Has an information security management system been implemented? - Yes - [CodeQL](https://codeql.github.com/) and a comprehensive ISMS covering multiple security domains. From 772c2b1fff02165aad116b796eb52fe6c10632cb Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 4 Mar 2025 13:28:54 -0800 Subject: [PATCH 11/12] Revert "ui new build" This reverts commit 94563ab1e73c143a592cfa7988031e82e1fe90cd. --- .../static/chunks/app/onboarding/page-8ba945cf183c937c.js | 1 - .../static/chunks/app/onboarding/page-f2e9aa9e77b66520.js | 1 + .../out/_next/static/chunks/app/page-a006114359094d34.js | 1 - .../out/_next/static/chunks/app/page-e28453cd004ff93c.js | 1 + .../_buildManifest.js | 0 .../_ssgManifest.js | 0 litellm/proxy/_experimental/out/index.html | 2 +- litellm/proxy/_experimental/out/index.txt | 4 ++-- litellm/proxy/_experimental/out/model_hub.txt | 2 +- litellm/proxy/_experimental/out/onboarding.txt | 4 ++-- ui/litellm-dashboard/out/404.html | 2 +- .../static/chunks/app/onboarding/page-8ba945cf183c937c.js | 1 - .../static/chunks/app/onboarding/page-f2e9aa9e77b66520.js | 1 + .../out/_next/static/chunks/app/page-a006114359094d34.js | 1 - .../out/_next/static/chunks/app/page-e28453cd004ff93c.js | 1 + .../_buildManifest.js | 0 .../_ssgManifest.js | 0 ui/litellm-dashboard/out/index.html | 2 +- ui/litellm-dashboard/out/index.txt | 4 ++-- ui/litellm-dashboard/out/model_hub.html | 2 +- ui/litellm-dashboard/out/model_hub.txt | 2 +- ui/litellm-dashboard/out/onboarding.html | 2 +- ui/litellm-dashboard/out/onboarding.txt | 4 ++-- 23 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js create mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js delete mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js create mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js rename litellm/proxy/_experimental/out/_next/static/{FMvuTRMhZEulJpWx99WMb => sW550-yvC4l9ZFA0scEUc}/_buildManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/{FMvuTRMhZEulJpWx99WMb => sW550-yvC4l9ZFA0scEUc}/_ssgManifest.js (100%) delete mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js create mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js delete mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js create mode 100644 ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js rename ui/litellm-dashboard/out/_next/static/{FMvuTRMhZEulJpWx99WMb => sW550-yvC4l9ZFA0scEUc}/_buildManifest.js (100%) rename ui/litellm-dashboard/out/_next/static/{FMvuTRMhZEulJpWx99WMb => sW550-yvC4l9ZFA0scEUc}/_ssgManifest.js (100%) diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js deleted file mode 100644 index a22da3c6fe..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,t,n){Promise.resolve().then(n.bind(n,12011))},12011:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return g}});var o=n(57437),a=n(2265),c=n(99376),s=n(20831),i=n(94789),l=n(12514),r=n(49804),u=n(67101),m=n(84264),d=n(49566),h=n(96761),p=n(84566),f=n(19250),x=n(14474),k=n(13634),_=n(73002),j=n(3914);function g(){let[e]=k.Z.useForm(),t=(0,c.useSearchParams)();(0,j.bW)();let n=t.get("invitation_id"),[g,w]=(0,a.useState)(null),[S,Z]=(0,a.useState)(""),[b,N]=(0,a.useState)(""),[v,y]=(0,a.useState)(null),[T,E]=(0,a.useState)(""),[C,U]=(0,a.useState)("");return(0,a.useEffect)(()=>{n&&(0,f.W_)(n).then(e=>{let t=e.login_url;console.log("login_url:",t),E(t);let n=e.token,o=(0,x.o)(n);U(n),console.log("decoded:",o),w(o.key),console.log("decoded user email:",o.user_email),N(o.user_email),y(o.user_id)})},[n]),(0,o.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,o.jsxs)(l.Z,{children:[(0,o.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,o.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,o.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,o.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,o.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,o.jsx)(r.Z,{children:"SSO is under the Enterprise Tirer."}),(0,o.jsx)(r.Z,{children:(0,o.jsx)(s.Z,{variant:"primary",className:"mb-2",children:(0,o.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,o.jsxs)(k.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",C,"formValues:",e),g&&C&&(e.user_email=b,v&&n&&(0,f.m_)(g,n,v,e.password).then(e=>{var t;let n="/ui/";n+="?userID="+((null===(t=e.data)||void 0===t?void 0:t.user_id)||e.user_id),(0,j.uB)(C),console.log("redirecting to:",n),window.location.href=n}))},children:[(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(k.Z.Item,{label:"Email Address",name:"user_email",children:(0,o.jsx)(d.Z,{type:"email",disabled:!0,value:b,defaultValue:b,className:"max-w-md"})}),(0,o.jsx)(k.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,o.jsx)(d.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,o.jsx)("div",{className:"mt-10",children:(0,o.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},3914:function(e,t,n){"use strict";function o(){let e=window.location.hostname,t=["/","/ui"],n=["Lax","Strict","None"],o=document.cookie.split("; "),a=/^token_\d+$/;o.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(o=>{t.forEach(t=>{document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,";"),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,";"),n.forEach(n=>{let a="None"===n?" Secure;":"";document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; SameSite=").concat(n,";").concat(a),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,"; SameSite=").concat(n,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let t=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(t),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function c(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,t=document.cookie.split("; ").map(t=>{let n=t.split("="),o=n[0];if("token"===o)return null;let a=o.match(e);return a?{name:o,timestamp:parseInt(a[1],10),value:n.slice(1).join("=")}:null}).filter(e=>null!==e);return t.length>0?(t.sort((e,t)=>t.timestamp-e.timestamp),t[0].value):null}n.d(t,{bA:function(){return o},bW:function(){return c},uB:function(){return a}})}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js new file mode 100644 index 0000000000..2909ac65a0 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,s,t){Promise.resolve().then(t.bind(t,12011))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return g}});var l=t(57437),n=t(2265),a=t(99376),i=t(20831),r=t(94789),o=t(12514),c=t(49804),u=t(67101),d=t(84264),m=t(49566),h=t(96761),x=t(84566),f=t(19250),p=t(14474),j=t(13634),_=t(73002);function g(){let[e]=j.Z.useForm(),s=(0,a.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));s&&s.split("=")[1]}("token");let t=s.get("invitation_id"),[g,Z]=(0,n.useState)(null),[k,w]=(0,n.useState)(""),[S,b]=(0,n.useState)(""),[N,v]=(0,n.useState)(null),[y,E]=(0,n.useState)(""),[I,O]=(0,n.useState)("");return(0,n.useEffect)(()=>{t&&(0,f.W_)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),E(s);let t=e.token,l=(0,p.o)(t);O(t),console.log("decoded:",l),Z(l.key),console.log("decoded user email:",l.user_email),b(l.user_email),v(l.user_id)})},[t]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,l.jsx)(d.Z,{children:"Claim your user account to login to Admin UI."}),(0,l.jsx)(r.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,l.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tirer."}),(0,l.jsx)(c.Z,{children:(0,l.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,l.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,l.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",I,"formValues:",e),g&&I&&(e.user_email=S,N&&t&&(0,f.m_)(g,t,N,e.password).then(e=>{var s;let t="/ui/";t+="?userID="+((null===(s=e.data)||void 0===s?void 0:s.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",t),window.location.href=t}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(m.Z,{type:"email",disabled:!0,value:S,defaultValue:S,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,l.jsx)(m.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js deleted file mode 100644 index d7f1882c15..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a006114359094d34.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return v}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002),_=s(3914);function v(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();(0,_.bW)();let s=l.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[S,k]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[A,E]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),I(l);let s=e.token,t=(0,g.o)(s);E(s),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),k(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",A,"formValues:",e),v&&A&&(e.user_email=N,S&&s&&(0,p.m_)(v,s,S,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),(0,_.uB)(A),console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return te}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=s(3914),g=e=>{let{userID:l,userEmail:s,userRole:t,premiumUser:a,proxySettings:i}=e,n=(null==i?void 0:i.PROXY_LOGOUT_URL)||"",o=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",s||"Unknown"]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,p.bA)(),window.location.href=n},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:o,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},j=s(19250);let f=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,j.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,j.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var _=s(49804),v=s(67101),y=s(20831),b=s(49566),Z=s(87452),N=s(88829),w=s(72208),S=s(84264),k=s(96761),C=s(29233),I=s(52787),A=s(13634),E=s(41021),P=s(51369),O=s(29967),T=s(73002),M=s(20577),L=s(56632);let D=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,j.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},R=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},F=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var U=s(15424),z=s(98074);let V=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,q=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},K=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return V(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var B=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),V(e,l)&&p.push({validator:async(e,l)=>{if(l&&!q(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(z.Z,{title:h,children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}):u;return t=V(e,l)?(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(I.default,{children:l.enum.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(M.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(b.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(b.Z,{placeholder:h||""}),(0,r.jsx)(A.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:K(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},H=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(I.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},J=s(57365),G=s(93192);function W(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=G.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(P.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(S.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{children:"Invitation Link"}),(0,r.jsx)(S.Z,{children:(0,r.jsx)(S.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>E.ZP.success("Copied!"),children:(0,r.jsx)(y.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var Y=s(30967),$=s(28181),X=s(73879),Q=s(3632),ee=s(15452),el=s.n(ee),es=s(71157),et=s(44643),ea=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.g)(l);g(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let v=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,j.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,j.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(P.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=new Blob([el().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(Y.Z,{beforeUpload:e=>(x(null),el().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(Q.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(y.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(S.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(S.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(et.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(S.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)($.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(C.CopyToClipboard,{text:l.invitation_link,onCopy:()=>E.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([el().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:er}=I.default;var ei=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=A.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[v,C]=(0,i.useState)(!1),[O,M]=(0,i.useState)(null),D=(0,n.useRouter)(),[F,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.So)(s,l,"any"),t=[];for(let l=0;l{D&&V(new URL("/",window.location.href).toString())},[D]);let q=async e=>{var t,a,r;try{E.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.Ov)(s,null,e);console.log("user create Response:",a),g(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};M(e),C(!0)}else(0,j.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,M(e),C(!0)});E.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";E.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(ea,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(P.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),g(null),u.resetFields()},children:[(0,r.jsx)(S.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(z.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(U.Z,{})})]}),name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(A.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(W,{isInvitationLinkModalVisible:v,setIsInvitationLinkModalVisible:C,baseUrl:F,invitationLinkData:O})]})},en=s(7310),eo=s.n(en);let{Option:ed}=I.default,ec=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},em=(e,l)=>F(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),eu=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,j.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eh=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,D]=(0,i.useState)([]),[F,V]=(0,i.useState)([]),[q,K]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ec(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[er,en]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&eu(l,a,n,D)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,j.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(E.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,j.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),g(m.soft_budget),E.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),E.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(em($,f)),c.setFieldValue("models",[])},[$,f]);let ef=async e=>{if(!e){en([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,j.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(s)}catch(e){console.error("Error fetching users:",e),E.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(eo()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(P.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(A.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(z.Z,{title:"Select who will own this API key",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(O.ZP.Group,{onChange:e=>K(e.target.value),value:q,children:[(0,r.jsx)(O.ZP,{value:"you",children:"You"}),(0,r.jsx)(O.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(O.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(z.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:er,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(T.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(z.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(H,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(z.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),F.map(e=>(0,r.jsx)(ed,{value:e,children:R(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(z.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(z.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(z.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(b.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(z.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(z.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:j.H2?"".concat(j.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(U.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(B,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(P.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(ei,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(P.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Save your Key"}),(0,r.jsx)(_.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)(_.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(S.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:h})}),(0,r.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{E.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(S.Z,{children:"Key being created, this might take 30s"})})]})})]})},ex=s(7366),ep=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,j.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},eg=s(71594),ej=s(24525),ef=s(21626),e_=s(97214),ev=s(28241),ey=s(58834),eb=s(69552),eZ=s(71876);function eN(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,eg.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,ej.sC)(),getExpandedRowModel:(0,ej.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:n?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var ew=s(27281),eS=s(41649),ek=s(12514),eC=s(12485),eI=s(18135),eA=s(35242),eE=s(29706),eP=s(77991),eO=s(10900),eT=s(23628),eM=s(74998);function eL(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=A.Z.useForm(),[h,x]=(0,i.useState)([]),p=em(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,j.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let g={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(A.Z,{form:u,onFinish:n,initialValues:g,layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(L.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(y.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]})}function eD(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let g=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,j.s0)(a,l.token,e);d(s.key),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key"),p(!1)}}},f=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(P.Z,{title:"Regenerate API Key",open:s,onCancel:f,footer:o?[(0,r.jsx)(y.Z,{onClick:f,children:"Close"},"close")]:[(0,r.jsx)(y.Z,{onClick:f,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(C.CopyToClipboard,{text:o,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(A.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eR(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=A.Z.useForm(),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),E.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,j.Nc)(o,e),E.ZP.success("Key updated successfully"),h(!1)}catch(e){E.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,j.I1)(o,n.token),E.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),E.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(k.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{icon:eT.Z,variant:"secondary",onClick:()=>_(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>g(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eD,{selectedToken:n,visible:f,onClose:()=>_(!1),accessToken:o}),p&&(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)(y.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>g(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(S.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(y.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eL,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(S.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(S.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(S.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(S.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(S.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(S.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eF=s(87908),eU=s(82422),ez=s(2356),eV=s(44633),eq=s(86462),eK=s(3837),eB=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[v,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let C=(0,i.useCallback)(eo()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eU.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),O=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(y.Z,{icon:ez.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(ek.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(T.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==O?void 0:O.label)||m,f?(0,r.jsx)(eV.Z,{className:"h-4 w-4"}):(0,r.jsx)(eq.Z,{className:"h-4 w-4"})]})}),(null==O?void 0:O.isSearchable)?(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search ".concat(O.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),C(e,O)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:v,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eF.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(T.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(L.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eK.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(T.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(T.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eH=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eJ=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eG(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[g,f]=(0,i.useState)(null),[_,v]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,j.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.getValue(),children:(0,r.jsx)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eH(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eJ(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:g?(0,r.jsx)(eR,{keyId:g,onClose:()=>f(null),keyData:l.find(e=>e.token===g),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eB,{options:w,onApplyFilters:e=>{if(v({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{v({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eN,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eW=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[I,O]=(0,i.useState)(null),[T,L]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ep({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=A.Z.useForm(),[em,eu]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await D(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,j.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),w(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){E.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,j.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eG,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),f&&(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)(y.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(P.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(y.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(A.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(y.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(P.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(y.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(C.CopyToClipboard,{text:ei,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eY=s(12011);console.log=function(){},console.log("isLocal:",!1);var e$=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:g}=e,[y,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),w=(0,n.useSearchParams)(),S=(0,p.bW)(),k=w.get("invitation_id"),[C,I]=(0,i.useState)(null),[A,E]=(0,i.useState)(null),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)(null),[L,D]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(S){let e=(0,o.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),I(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&C&&s&&!a&&!y){let e=sessionStorage.getItem("userModels"+l);e?O(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.g)(C);M(e);let t=await (0,j.Br)(C,l,s,!1,null,null);b(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(y))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,j.So)(C,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),O(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),f(C,l,s,Z,u))}},[l,S,C,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(C,", userID: ").concat(l,", userRole: ").concat(s)),C&&(console.log("fetching teams"),f(C,l,s,Z,u))},[Z]),(0,i.useEffect)(()=>{if(null!==a&&null!=L&&null!==L.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))L.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===L.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),E(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;E(e)}},[L]),null!=k)return(0,r.jsx)(eY.default,{});if(null==l||null==S){console.log("All cookies before redirect:",document.cookie),(0,p.bA)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=G.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",L),console.log("All cookies after redirect:",document.cookie),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(_.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eh,{userID:l,team:L,teams:t,userRole:s,accessToken:C,data:a,setData:h},L?L.team_id:null),(0,r.jsx)(eW,{userID:l,userRole:s,accessToken:C,selectedTeam:L||null,setSelectedTeam:D,data:a,setData:h,premiumUser:x,teams:t,currentOrg:Z,setCurrentOrg:N,organizations:g})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let eX={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eQ={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},e0=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eQ[e],displayName:e}}let l=Object.keys(eX).find(l=>eX[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eQ[s],displayName:s}},e1=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e2=(e,l)=>{console.log("Provider key: ".concat(e));let s=eX[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e4=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=eX[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=eX[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,j.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){E.ZP.error("Failed to create model: "+e,10)}},e5=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e3=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,j.um)(l,i),E.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e6=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=A.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(P.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(A.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},e8=s(47323),e7=s(53410),e9=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),E.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){E.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(I.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(P.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(A.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(S.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(I.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(T.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},le=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,j.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(eo()((e,l)=>f(e,l),300),[]),v=(e,l)=>{g(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(P.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(A.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:(0,r.jsxs)(z.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},ll=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,g]=(0,i.useState)(!1),[f]=A.Z.useForm(),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.Xm)(a,s);u(e)}catch(e){E.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.cu)(a,s,l),E.ZP.success("Team member added successfully"),g(!1),f.resetFields(),O()}catch(e){E.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},F=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.sN)(a,s,l),E.ZP.success("Team member updated successfully"),b(!1),O()}catch(e){E.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,j.Lp)(a,s,e),E.ZP.success("Team member removed successfully"),O()}catch(e){E.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,j.Gh)(a,t),E.ZP.success("Team settings updated successfully"),C(!1),O()}catch(e){E.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:K.team_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"User Email"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>V(e),icon:eM.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(y.Z,{onClick:()=>g(!0),children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Team Settings"}),P&&!w&&(0,r.jsx)(y.Z,{onClick:()=>C(!0),children:"Edit Settings"})]}),w?(0,r.jsxs)(A.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(L.Z,{type:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>C(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(eS.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e9,{visible:_,onCancel:()=>b(!1),onSubmit:F,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(le,{isVisible:p,onCancel:()=>g(!1),onSubmit:D,accessToken:a})]})},ls=s(30150);function lt(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,g,f,_,Z,N,w,C;let{modelId:I,onClose:P,modelData:O,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=A.Z.useForm(),[V,q]=(0,i.useState)(O),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:I}};await (0,j.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),E.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),E.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!O)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(S.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,j.Og)(M,I),E.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),E.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(k.Z,{children:["Public Model Name: ",e5(O)]}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:O.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-6",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[O.provider&&(0,r.jsx)("img",{src:e0(O.provider).logo,alt:"".concat(O.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=O.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(k.Z,{children:O.provider||"Not Set"})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(k.Z,{children:O.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Input: $",O.input_cost,"/1M tokens"]}),(0,r.jsxs)(S.Z,{children:["Output: $",O.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",O.model_info.created_at?new Date(O.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",O.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(A.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*O.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*O.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*O.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*O.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=V.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=V.litellm_params)||void 0===_?void 0:_.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=V.litellm_params)||void 0===w?void 0:w.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:O.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(y.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(O,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(T.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(T.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var la=s(67960),lr=s(47451),li=s(69410),ln=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=A.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(b.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(b.Z,{placeholder:t(l)})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},lo=()=>{let e=A.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=A.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=A.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(b.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)($.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:ld}=G.default;var lc=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(A.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(b.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(b.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(b.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(Y.Z,{...s,children:(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(Q.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(I.default,{placeholder:"Select API Base",children:[(0,r.jsx)(I.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(I.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(b.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(b.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(A.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(ld,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(b.Z,{placeholder:"sk-",type:"password"})})]})},lm=s(63709),lu=s(90464);let{Link:lh}=G.default;var lx=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=A.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(Z.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(A.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(H,{teams:t})}),(0,r.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lm.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}):(0,r.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lm.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(A.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(lr.Z,{className:"mb-4",children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(A.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lp,Link:lg}=G.default;var lj=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lp,{level:2,children:"Add new model"}),(0,r.jsx)(la.Z,{children:(0,r.jsx)(A.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(I.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eQ[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(ln,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(lo,{}),(0,r.jsx)(lc,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lx,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(z.Z,{title:"Get help on our github",children:(0,r.jsx)(G.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lf=s(49084);function l_(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let lv=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:e0(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(z.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:ly,Link:lb}=G.default,lZ={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lN=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[w,C]=(0,i.useState)([]),[I,P]=(0,i.useState)(a.OpenAI),[O,T]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[H,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[eN,eS]=(0,i.useState)(null),[eO,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==eN?void 0:eN.token;void 0===r&&(r=null);let i=eO;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,j.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,j.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,j.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,j.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,j.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,j.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[eN,eO]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,j.K_)(l,{router_settings:{model_group_retry_policy:ex}}),E.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),E.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let g=await (0,j.hy)(l);C(g);let f=await (0,j.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,j.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,j.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,j.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,j.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==eN?void 0:eN.token,eO),S=await (0,j.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,j.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,j.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,j.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,j.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==g&&a(),eJ()},[l,s,t,n,g,_]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e0=l.litellm_params)||void 0===e0?void 0:e0.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=G.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 e7=async()=>{try{E.ZP.info("Running health check..."),T("");let e=await (0,j.EY)(l);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}};S.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{eS(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(J.Z,{value:String(l),disabled:!0,onClick:()=>{eS(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(J.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(I)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===I);return(e9&&w.find(e=>e.name===eX[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(ll,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(lt,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"All Models"}),(0,r.jsx)(eC.Z,{children:"Add Model"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(eC.Z,{children:"Model Analytics"}),(0,r.jsx)(eC.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",_]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(J.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(l_,{columns:lv(m,ez,eB,e5,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e6,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e3(e,l,D,F)})]}),(0,r.jsx)(eE.Z,{className:"h-full",children:(0,r.jsx)(lj,{form:p,handleOk:()=>{p.validateFields().then(e=>{e4(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:I,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e2(e,g);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e1,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?E.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&E.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(y.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(k.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(S.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lZ&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lZ).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(M.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(y.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lw=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=A.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(P.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(A.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lS=s(15731);let lk=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(z.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(z.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lS.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(v.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(eS.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(eS.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lC(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lI=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(1),[_,v]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[A,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(A&&l)try{if(await (0,j.Eb)(l,[A]),E.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==A);h(e)}}catch(e){console.error("Error deleting user:",e),E.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,j.pf)(l,e,null),E.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(g));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,j.Br)(l,null,a,!0,g,25);sessionStorage.setItem("userList_".concat(g),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,j.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,g]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lk(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(ei,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||g<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||g>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lC,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lw,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",A]})]})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lA=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,j.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,j.cu)(l,e,{user_id:s,role:"user"}),E.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),E.ZP.error("Failed to join team")}};return(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Description"}),(0,r.jsx)(eb.Z,{children:"Members"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsxs)(e_.Z,{children:[t.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.team_alias})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.description||"No description available"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eS.Z,{size:"xs",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(S.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lE=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,F(s,l)};var lP=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&f(t,n,o,u,a),ew()},[c]);let[g]=A.Z.useForm(),[k]=A.Z.useForm(),{Title:C,Paragraph:O}=G.default,[F,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[J,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lE(x,ea);console.log("models: ".concat(e)),em(e),g.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,j.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},ej=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,j.rs)(t,eo),f(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await D(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));E.ZP.info("Creating Team");let o=await (0,j.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),E.ZP.success("Team created"),g.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),E.ZP.error("Error creating the team: "+e,20)}},ew=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:J?(0,r.jsx)(ll,{teamId:J,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===J)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Your Teams"}),(0,r.jsx)(eC.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(S.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Team ID"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Organization"}),(0,r.jsx)(eb.Z,{children:"Info"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ev.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)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)})},l))}):null}),(0,r.jsx)(ev.Z,{children:e.organization_id}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(ev.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>eg(e.team_id),icon:eM.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(y.Z,{onClick:ej,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(P.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),g.resetFields()},onCancel:()=>{Q(!1),g.resetFields()},children:(0,r.jsxs)(A.Z,{form:g,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{g.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(b.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lA,{accessToken:t,userID:n})})]})]})})},lO=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(!1),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,C]=(0,i.useState)(null),P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.t$)(a,s);u(e)}catch(e){E.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.vh)(a,s,l),E.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.LY)(a,s,l),E.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,j.Sb)(a,s,e.user_id),E.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,j.VA)(a,l),E.ZP.success("Organization settings updated successfully"),f(!1),O()}catch(e){E.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:m.organization_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Created At"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{C({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(y.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Organization Settings"}),P&&!g&&(0,r.jsx)(y.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),g?(0,r.jsxs)(A.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(L.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(le,{isVisible:_,onCancel:()=>b(!1),onSubmit:D,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e9,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:w,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lT=async(e,l)=>{l(await (0,j.r6)(e))};var lM=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[k,C]=(0,i.useState)(!1),[O]=A.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lT(a,m)},[l,a]);let T=e=>{e&&(w(e),Z(!0))},D=async()=>{if(N&&a)try{await (0,j.cq)(a,N),E.ZP.success("Organization deleted successfully"),Z(!1),w(null),lT(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,j.H1)(a,e),C(!1),O.resetFields(),lT(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lO,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(eC.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(S.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Organization ID"}),(0,r.jsx)(eb.Z,{children:"Organization Name"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(eb.Z,{children:"Info"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.organization_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{children:e.organization_alias}),(0,r.jsx)(ev.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{children:e.spend}),(0,r.jsx)(ev.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(ev.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)},l))})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(ev.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>T(e.organization_id),icon:eM.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>C(!0),children:"+ Create New Organization"}),(0,r.jsx)(P.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{C(!1),O.resetFields()},children:(0,r.jsxs)(A.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(y.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),f?(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 Organization"}),(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 organization?"})})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(S.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lL=s(94789);let lD={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lR={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lF=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lR[e];return l?l.fields.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(L.Z.Password,{}):(0,r.jsx)(b.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(P.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(A.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(I.default,{children:Object.entries(lD).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(A.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(P.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(S.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)(T.ZP,{onClick:n,children:"Done"})})]})]})};let lU=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lz=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=A.Z.useForm(),[d]=A.Z.useForm(),{Title:c,Paragraph:m}=G.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[I,O]=(0,i.useState)(!1),[M,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,J]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lU(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){E.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,j.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),E.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,j.eH)(s,e.ip);let l=await (0,j.PT)(s);B(l),E.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),E.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{J(e),q(!0)},et=async()=>{if(H&&s)try{await (0,j.$I)(s,H);let e=await (0,j.PT)(s);B(e.length>0?e:[X]),E.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),E.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),J(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,j.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,j.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,j.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;E.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,j.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,j.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lR[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,j.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:()=>!0===a?O(!0):E.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lF,{isAddSSOModalVisible:I,isInstructionsModalVisible:M,handleAddSSOOk:()=>{O(!1),o.resetFields()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),O(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(P.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(y.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"IP Address"}),(0,r.jsx)(eb.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:K.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e}),(0,r.jsx)(ev.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(y.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(P.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(A.Z,{onFinish:el,children:[(0,r.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(L.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(A.Z.Item,{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(P.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(y.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lL.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lV=s(92858),lq=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=A.Z.useForm();return(0,r.jsxs)(A.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{align:"center",children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(A.Z.Item,{name:e.field_name,children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lK=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,j.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lq,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,j.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.jA)(l,"alerting",["slack"]):(0,j.jA)(l,"alerting",[])),E.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lB=s(86582);let{Title:lH,Paragraph:lJ}=G.default;console.log=function(){};var lG=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=A.Z.useForm(),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[_,Z]=(0,i.useState)(""),[N,w]=(0,i.useState)({}),[k,C]=(0,i.useState)([]),[O,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),H=e=>{k.includes(e)?C(k.filter(l=>l!==e)):C([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),C(e.active_alerts),Z(s),w(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,j.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,j.K_)(l,{environment_variables:s}),E.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,j.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),E.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eC.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(eC.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(eC.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(v.Z,{numItems:2,children:(0,r.jsx)(ek.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(eb.Z,{children:"Callback Name"})})}),(0,r.jsx)(e_.Z,{children:n.map((e,s)=>(0,r.jsxs)(eZ.Z,{className:"flex justify-between",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.name})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(S.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)}):(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:_})})]},l)})})]}),(0,r.jsx)(y.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,j.K_)(l,s)}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lK,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Email Settings"}),(0,r.jsxs)(S.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(ev.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(v.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(S.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"mt-2",children:l}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(P.Z,{title:"Add Logging Callback",visible:O,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(A.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lB.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(I.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(J.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lB.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(b.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(P.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(A.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lB.Z,{label:l,name:l,children:(0,r.jsx)(b.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lW=s(92414),lY=s(46030);let{Option:l$}=I.default;var lX=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(P.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(A.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,j.K_)(s,{router_settings:o}),a(o)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(ew.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(A.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lW.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lQ=s(33619);async function l0(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lQ.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});E.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l1={ttl:3600,lowest_latency_buffer:0},l2=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(N.Z,{children:"latency-based-routing"==l?(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(S.Z,{children:"No specific settings"})})]})};var l4=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(null),I={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,j.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,j.K_)(l,{router_settings:t}),o(t),E.ZP.success("Router settings updated successfully")}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},T=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,j.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,j.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,j.K_)(l,{router_settings:s})}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(eC.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(eC.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(k.Z,{children:"Router Settings"}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[l]})]}),(0,r.jsx)(ev.Z,{children:"routing_strategy"==l?(0,r.jsxs)(ew.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(J.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(J.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(J.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l2,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l1,paramExplanation:I})]}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Model Name"}),(0,r.jsx)(eb.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(e_.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:t}),(0,r.jsx)(ev.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{onClick:()=>l0(t,l),children:"Test Fallback"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(lX,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"}),(0,r.jsx)(eb.Z,{children:"Status"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(ev.Z,{children:"Integer"==e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(y.Z,{onClick:()=>T(e.field_name,l),children:"Update"}),(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l5=s(93142),l3=s(45246),l6=s(96473),l8=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l5.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(b.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(b.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l3.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(T.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l6.Z,{}),children:"Add Header"})]})};let{Option:l7}=I.default;var l9=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=A.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(P.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(A.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,j.Vt)(l,e),s(r)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l8,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},se=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,j.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,j.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),E.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Path"}),(0,r.jsx)(eb.Z,{children:"Target"}),(0,r.jsx)(eb.Z,{children:"Headers"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:n.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.path})}),(0,r.jsx)(ev.Z,{children:e.target}),(0,r.jsx)(ev.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l9,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=A.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call");let l=await (0,j.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),E.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(A.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ss=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=A.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call"),t(!0);let l=await (0,j.qI)(s,e);a(e=>e?[...e,l]:[l]),E.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(A.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},st=s(17906),sa=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,j.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;E.ZP.info("Request made"),await (0,j.NV)(l,e);let t=[...c];t.splice(s,1),m(t),E.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,j.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(y.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(sl,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(ss,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Budget ID"}),(0,r.jsx)(eb.Z,{children:"Max Budget"}),(0,r.jsx)(eb.Z,{children:"TPM"}),(0,r.jsx)(eb.Z,{children:"RPM"})]})}),(0,r.jsx)(e_.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.budget_id}),(0,r.jsx)(ev.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(ev.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(ev.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(eC.Z,{children:"Test it (Curl)"}),(0,r.jsx)(eC.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sr=s(77398),si=s.n(sr),sn=s(20016);async function so(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let sd=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return so(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sc=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sm=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sc(l)})},su=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sm,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(z.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(sd,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:e0(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(z.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],sh=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,j.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sx=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sp=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sg=["Internal User","Internal Viewer"],sj=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sf(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(si()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(si()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sg.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&g(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sg.includes(o)&&q(!0)},[o]);let B=(0,sn.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=si()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?si()(S).utc().format("YYYY-MM-DD HH:mm:ss"):si()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,j.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await sh(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(si()(N).format("MMM D, h:mm A")," - ").concat(si()(S).format("MMM D, h:mm A"));let e=si()(),l=si()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>g(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),g(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(si()().format("YYYY-MM-DDTHH:mm")),w(si()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eN,{columns:su,data:H,renderSubComponent:s_,getRowCanExpand:()=>!0})]})]})}function s_(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sj,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sx,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var sv=s(92699),sy=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(S.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eC.Z,{children:"LlamaIndex"}),(0,r.jsx)(eC.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sb=s(243),sZ=s(94263);async function sN(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lQ.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sw=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[w,k]=(0,i.useState)([]),C=(0,i.useRef)(null),A=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,j.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),f(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{A.current&&setTimeout(()=>{var e;null===(e=A.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){E.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{g&&await sN(i,(e,l)=>P("assistant",e,l),g,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=G.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)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eC.Z,{children:"Chat"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"API Key Source"}),(0,r.jsx)(I.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(_.Z,{className:"mx-2",children:[(0,r.jsx)(S.Z,{children:"Select Model:"}),(0,r.jsx)(I.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),N("custom"===e)},options:[...w,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{f(e)},500)}})]})]}),(0,r.jsx)(y.Z,{onClick:()=>{p([]),E.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ef.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{})})}),(0,r.jsxs)(e_.Z,{children:[x.map((e,l)=>(0,r.jsx)(eZ.Z,{children:(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sb.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(st.Z,{style:sZ.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{ref:A,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(b.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(y.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sS=s(19226),sk=s(45937),sC=s(92403),sI=s(28595),sA=s(68208),sE=s(9775),sP=s(41361),sO=s(37527),sT=s(12660),sM=s(88009),sL=s(48231),sD=s(41169),sR=s(44625),sF=s(57400),sU=s(55322);let{Sider:sz}=sS.default,sV=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sC.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sI.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sA.Z,{}),roles:sp},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sE.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sP.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sp},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sT.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sM.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sL.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sD.Z,{}),roles:sp,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sR.Z,{}),roles:sp},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sF.Z,{}),roles:sp}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sT.Z,{}),roles:sp},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp}]}];var sq=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sV.find(l=>l.page===e);if(l)return l.key;for(let l of sV)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sV.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sS.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sz,{theme:"light",width:220,children:(0,r.jsx)(sk.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sK=s(40278),sB=s(96889),sH=s(97765);console.log=function(){};var sJ=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,j.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let g=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sG=s(69907),sW=s(53003),sY=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let s$=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var sX=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,j.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,j.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),w((await (0,j.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,j.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,j.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,j.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,j.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,j.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,j.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,j.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,j.b1)(l,null,void 0,void 0),f,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,j.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(l)try{let e=await (0,j.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),s$(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(S.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(y.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mt-2",children:[(0,r.jsx)(eC.Z,{children:"All Up"}),s$(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eC.Z,{children:"Team Based Usage"}),(0,r.jsx)(eC.Z,{children:"Customer Usage"}),(0,r.jsx)(eC.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(eC.Z,{children:"Cost"}),(0,r.jsx)(eC.Z,{children:"Activity"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(S.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sJ,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Monthly Spend"}),(0,r.jsx)(sK.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top API Keys"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top Models"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sY.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Provider"}),(0,r.jsx)(eb.Z,{children:"Spend"})]})}),(0,r.jsx)(e_.Z,{children:T.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.provider}),(0,r.jsx)(ev.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"All Up"}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:e.model}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sB.Z,{data:P})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sK.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(_.Z,{numColSpan:2})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Time Range"}),(0,r.jsx)(sW.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Key"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(ek.Z,{className:"mt-4",children:(0,r.jsxs)(ef.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Customer"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Total Events"})]})}),(0,r.jsx)(e_.Z,{children:null==g?void 0:g.map((e,l)=>{var s;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.end_user}),(0,r.jsx)(ev.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(ev.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(_.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lY.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(J.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(S.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sK.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(_.Z,{numColSpan:2})]})]})]})]})})},sQ=s(51853);let s0=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s1=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s2=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sQ.Z,{className:"h-4 w-4"})})]})})})},s4=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s1(j.litellm_params)||{},_=s1(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s1(null==g?void 0:g.litellm_cache_params)||{},_=s1(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(S.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s2,{label:"Error Message",value:j.message}),(0,r.jsx)(s2,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s2,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s2,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s2,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s2,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s2,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s2,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s2,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s2,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s2,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s5=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(y.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(s0,{responseTimeMs:n})]}),s&&(0,r.jsx)(s4,{response:s})]})},s3=e=>{if(e)return e.toISOString().split("T")[0]};function s6(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s8=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[w,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[A,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&w&&((async()=>{p(await (0,j.zg)(l,s3(w.from),s3(w.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,j.zg)(l,s3(e),s3(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);f(s6(s)),b(s6(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,w,x]);let L=async()=>{try{E.ZP.info("Running cache health check..."),P("");let e=await (0,j.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Cache Analytics"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(v.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(sW.Z,{enableSelect:!0,value:w,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sK.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sK.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(s5,{accessToken:l,healthCheckResponse:A,runCachingHealthCheck:L})})]})]})},s7=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,j.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(S.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Guardrail Name"}),(0,r.jsx)(eb.Z,{children:"Mode"}),(0,r.jsx)(eb.Z,{children:"Status"})]})}),(0,r.jsx)(e_.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.guardrail_name}),(0,r.jsx)(ev.Z,{children:e.litellm_params.mode}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s9=new d.S;function te(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[_,v]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)([]),[w,S]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,C]=(0,i.useState)(!0),I=(0,n.useSearchParams)(),[A,E]=(0,i.useState)({data:[]}),[P,O]=(0,i.useState)(null),T=I.get("userID"),M=I.get("invitation_id"),[L,D]=(0,i.useState)(()=>I.get("page")||"api-keys"),[R,F]=(0,i.useState)(null);return(0,i.useEffect)(()=>{O((0,p.bW)())},[]),(0,i.useEffect)(()=>{if(!P)return;let e=(0,o.o)(P);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),F(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&D("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?C("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,j.K8)(e.auth_header_name)}},[P]),(0,i.useEffect)(()=>{R&&T&&e&&eu(T,e,R,N),R&&T&&e&&f(R,T,e,null,x),R&&lT(R,b)},[R,T,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s9,children:M?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(g,{userID:T,userRole:e,premiumUser:s,userEmail:m,setProxySettings:S,proxySettings:w}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sq,{setPage:e=>{let l=new URLSearchParams(I);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),D(e)},userRole:e,defaultSelectedKey:L})}),"api-keys"==L?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):"models"==L?(0,r.jsx)(lN,{userID:T,userRole:e,token:P,keys:_,accessToken:R,modelData:A,setModelData:E,premiumUser:s,teams:h}):"llm-playground"==L?(0,r.jsx)(sw,{userID:T,userRole:e,token:P,accessToken:R,disabledPersonalKeyCreation:a}):"users"==L?(0,r.jsx)(lI,{userID:T,userRole:e,token:P,keys:_,teams:h,accessToken:R,setKeys:v}):"teams"==L?(0,r.jsx)(lP,{teams:h,setTeams:x,searchParams:I,accessToken:R,userID:T,userRole:e,organizations:y}):"organizations"==L?(0,r.jsx)(lM,{organizations:y,setOrganizations:b,userModels:Z,accessToken:R,userRole:e,premiumUser:s}):"admin-panel"==L?(0,r.jsx)(lz,{setTeams:x,searchParams:I,accessToken:R,showSSOBanner:k,premiumUser:s}):"api_ref"==L?(0,r.jsx)(sy,{proxySettings:w}):"settings"==L?(0,r.jsx)(lG,{userID:T,userRole:e,accessToken:R,premiumUser:s}):"budgets"==L?(0,r.jsx)(sa,{accessToken:R}):"guardrails"==L?(0,r.jsx)(s7,{accessToken:R}):"general-settings"==L?(0,r.jsx)(l4,{userID:T,userRole:e,accessToken:R,modelData:A}):"model-hub"==L?(0,r.jsx)(sv.Z,{accessToken:R,publicPage:!1,premiumUser:s}):"caching"==L?(0,r.jsx)(s8,{userID:T,userRole:e,token:P,accessToken:R,premiumUser:s}):"pass-through-settings"==L?(0,r.jsx)(se,{userID:T,userRole:e,accessToken:R,modelData:A}):"logs"==L?(0,r.jsx)(sf,{userID:T,userRole:e,token:P,accessToken:R}):(0,r.jsx)(sX,{userID:T,userRole:e,token:P,accessToken:R,keys:_,premiumUser:s})]})]})})})}},3914:function(e,l,s){"use strict";function t(){let e=window.location.hostname,l=["/","/ui"],s=["Lax","Strict","None"],t=document.cookie.split("; "),a=/^token_\d+$/;t.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(t=>{l.forEach(l=>{document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,";"),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let a="None"===s?" Secure;":"";document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; SameSite=").concat(s,";").concat(a),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let l=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(l),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function r(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,l=document.cookie.split("; ").map(l=>{let s=l.split("="),t=s[0];if("token"===t)return null;let a=t.match(e);return a?{name:t,timestamp:parseInt(a[1],10),value:s.slice(1).join("=")}:null}).filter(e=>null!==e);return l.length>0?(l.sort((e,l)=>l.timestamp-e.timestamp),l[0].value):null}s.d(l,{bA:function(){return t},bW:function(){return r},uB:function(){return a}})}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js new file mode 100644 index 0000000000..1e9a200f47 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-e28453cd004ff93c.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return _}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002);function _(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));l&&l.split("=")[1]}("token");let s=l.get("invitation_id"),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(""),[Z,N]=(0,a.useState)(""),[w,S]=(0,a.useState)(null),[k,C]=(0,a.useState)(""),[I,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),C(l);let s=e.token,t=(0,g.o)(s);A(s),console.log("decoded:",t),v(t.key),console.log("decoded user email:",t.user_email),N(t.user_email),S(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",_,"token:",I,"formValues:",e),_&&I&&(e.user_email=Z,w&&s&&(0,p.m_)(_,s,w,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:Z,defaultValue:Z,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return s9}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=e=>{let{userID:l,userRole:s,premiumUser:t,proxySettings:a}=e,i=(null==a?void 0:a.PROXY_LOGOUT_URL)||"",n=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",s]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(t)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=i},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:n,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},g=s(19250);let j=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,g.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,g.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var f=s(49804),_=s(67101),v=s(20831),y=s(49566),b=s(87452),Z=s(88829),N=s(72208),w=s(84264),S=s(96761),k=s(29233),C=s(52787),I=s(13634),A=s(41021),E=s(51369),P=s(29967),O=s(73002),T=s(20577),M=s(56632);let L=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,g.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},D=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},R=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var F=s(15424),U=s(98074);let z=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,V=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},q=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return z(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var K=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),z(e,l)&&p.push({validator:async(e,l)=>{if(l&&!V(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(U.Z,{title:h,children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}):u;return t=z(e,l)?(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(C.default,{children:l.enum.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(T.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(y.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(y.Z,{placeholder:h||""}),(0,r.jsx)(I.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:q(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},B=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(C.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},H=s(57365),J=s(93192);function G(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=J.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(E.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(w.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{children:"Invitation Link"}),(0,r.jsx)(w.Z,{children:(0,r.jsx)(w.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(k.CopyToClipboard,{text:o(),onCopy:()=>A.ZP.success("Copied!"),children:(0,r.jsx)(v.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var W=s(30967),Y=s(28181),$=s(73879),X=s(3632),Q=s(15452),ee=s.n(Q),el=s(71157),es=s(44643),et=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.g)(l);j(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let y=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,g.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,g.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(E.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=new Blob([ee().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(W.Z,{beforeUpload:e=>(x(null),ee().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(X.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(v.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(w.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(w.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(es.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(w.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)(Y.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(k.CopyToClipboard,{text:l.invitation_link,onCopy:()=>A.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([ee().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:ea}=C.default;var er=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=I.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[k,P]=(0,i.useState)(!1),[T,L]=(0,i.useState)(null),R=(0,n.useRouter)(),[z,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.So)(s,l,"any"),t=[];for(let l=0;l{R&&V(new URL("/",window.location.href).toString())},[R]);let q=async e=>{var t,a,r;try{A.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,g.Ov)(s,null,e);console.log("user create Response:",a),j(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};L(e),P(!0)}else(0,g.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,L(e),P(!0)});A.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";A.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(et,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(E.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),j(null),u.resetFields()},children:[(0,r.jsx)(w.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(U.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(F.Z,{})})]}),name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(I.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(G,{isInvitationLinkModalVisible:k,setIsInvitationLinkModalVisible:P,baseUrl:z,invitationLinkData:T})]})},ei=s(7310),en=s.n(ei);let{Option:eo}=C.default,ed=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},ec=(e,l)=>R(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),em=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,g.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eu=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[L,R]=(0,i.useState)([]),[z,V]=(0,i.useState)([]),[q,H]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ed(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[ei,eu]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&em(l,a,n,R)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,g.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(A.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,g.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),j(m.soft_budget),A.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),A.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(ec($,L)),c.setFieldValue("models",[])},[$,L]);let ef=async e=>{if(!e){eu([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,g.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eu(s)}catch(e){console.error("Error fetching users:",e),A.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(en()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(E.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(I.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(U.Z,{title:"Select who will own this API key",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(P.ZP.Group,{onChange:e=>H(e.target.value),value:q,children:[(0,r.jsx)(P.ZP,{value:"you",children:"You"}),(0,r.jsx)(P.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(P.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(U.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:ei,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(O.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(U.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(B,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(U.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),z.map(e=>(0,r.jsx)(eo,{value:e,children:D(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(U.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(U.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(U.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(y.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(U.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(U.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:g.H2?"".concat(g.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(F.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(K,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(E.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(er,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(E.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Save your Key"}),(0,r.jsx)(f.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)(f.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(w.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:h})}),(0,r.jsx)(k.CopyToClipboard,{text:h,onCopy:()=>{A.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(w.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=s(7366),ex=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,g.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},ep=s(71594),eg=s(24525),ej=s(21626),ef=s(97214),e_=s(28241),ev=s(58834),ey=s(69552),eb=s(71876);function eZ(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,ep.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,eg.sC)(),getExpandedRowModel:(0,eg.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:n?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var eN=s(27281),ew=s(41649),eS=s(12514),ek=s(12485),eC=s(18135),eI=s(35242),eA=s(29706),eE=s(77991),eP=s(10900),eO=s(23628),eT=s(74998);function eM(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=I.Z.useForm(),[h,x]=(0,i.useState)([]),p=ec(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,g.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let j={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(I.Z,{form:u,onFinish:n,initialValues:j,layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(C.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(C.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(C.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsx)(I.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(M.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(v.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]})}function eL(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let j=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,g.s0)(a,l.token,e);d(s.key),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key"),p(!1)}}},b=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(E.Z,{title:"Regenerate API Key",open:s,onCancel:b,footer:o?[(0,r.jsx)(v.Z,{onClick:b,children:"Close"},"close")]:[(0,r.jsx)(v.Z,{onClick:b,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:j,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(k.CopyToClipboard,{text:o,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(I.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eD(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=I.Z.useForm(),[p,j]=(0,i.useState)(!1),[f,y]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(w.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),A.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,g.Nc)(o,e),A.ZP.success("Key updated successfully"),h(!1)}catch(e){A.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,g.I1)(o,n.token),A.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),A.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{icon:eO.Z,variant:"secondary",onClick:()=>y(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>j(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eL,{selectedToken:n,visible:f,onClose:()=>y(!1),accessToken:o}),p&&(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)(v.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>j(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(w.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(v.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eM,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(w.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(w.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(w.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(w.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(w.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(w.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(w.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eR=s(87908),eF=s(82422),eU=s(2356),ez=s(44633),eV=s(86462),eq=s(3837),eK=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let I=(0,i.useCallback)(en()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eF.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),T=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(v.Z,{icon:eU.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(eS.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(O.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==T?void 0:T.label)||m,f?(0,r.jsx)(ez.Z,{className:"h-4 w-4"}):(0,r.jsx)(eV.Z,{className:"h-4 w-4"})]})}),(null==T?void 0:T.isSearchable)?(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search ".concat(T.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),I(e,T)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:y,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eR.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(O.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(M.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eq.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(O.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(O.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eB=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eH=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eJ(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[j,f]=(0,i.useState)(null),[_,y]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,g.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.getValue(),children:(0,r.jsx)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eB(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eH(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:j?(0,r.jsx)(eD,{keyId:j,onClose:()=>f(null),keyData:l.find(e=>e.token===j),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eK,{options:w,onApplyFilters:e=>{if(y({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{y({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eZ,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eG=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,C]=(0,i.useState)(null),[P,O]=(0,i.useState)(null),[M,D]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ex({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=I.Z.useForm(),[em,eu]=(0,i.useState)(null),[ep,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await L(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,g.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),C(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){A.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,g.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eJ,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),b&&(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)(v.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),C(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(E.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(v.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(I.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(v.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(E.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(v.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(k.CopyToClipboard,{text:ei,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eW=s(12011);console.log=function(){},console.log("isLocal:",!1);var eY=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:p}=e,[v,y]=(0,i.useState)(null),[b,Z]=(0,i.useState)(null),N=(0,n.useSearchParams)(),w=function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"),S=N.get("invitation_id"),[k,C]=(0,i.useState)(null),[I,A]=(0,i.useState)(null),[E,P]=(0,i.useState)([]),[O,T]=(0,i.useState)(null),[M,L]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(w){let e=(0,o.o)(w);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),C(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&k&&s&&!a&&!v){let e=sessionStorage.getItem("userModels"+l);e?P(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(b))),(async()=>{try{let e=await (0,g.g)(k);T(e);let t=await (0,g.Br)(k,l,s,!1,null,null);y(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(v))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,g.So)(k,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),P(a),console.log("userModels:",E),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),j(k,l,s,b,u))}},[l,w,k,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(b),", accessToken: ").concat(k,", userID: ").concat(l,", userRole: ").concat(s)),k&&(console.log("fetching teams"),j(k,l,s,b,u))},[b]),(0,i.useEffect)(()=>{if(null!==a&&null!=M&&null!==M.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))M.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===M.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),A(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;A(e)}},[M]),null!=S)return(0,r.jsx)(eW.default,{});if(null==l||null==w){let e="/sso/key/generate";return document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Full URL:",e),window.location.href=e,null}if(null==k)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=J.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",M),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(f.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eu,{userID:l,team:M,teams:t,userRole:s,accessToken:k,data:a,setData:h},M?M.team_id:null),(0,r.jsx)(eG,{userID:l,userRole:s,accessToken:k,selectedTeam:M||null,setSelectedTeam:L,data:a,setData:h,premiumUser:x,teams:t,currentOrg:b,setCurrentOrg:Z,organizations:p})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let e$={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eX={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},eQ=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eX[e],displayName:e}}let l=Object.keys(e$).find(l=>e$[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eX[s],displayName:s}},e0=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e1=(e,l)=>{console.log("Provider key: ".concat(e));let s=e$[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e2=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=e$[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=e$[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,g.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){A.ZP.error("Failed to create model: "+e,10)}},e4=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e5=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,g.um)(l,i),A.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e3=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=I.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(E.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(I.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},e6=s(47323),e8=s(53410),e7=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=I.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),A.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){A.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(C.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(E.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(I.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(w.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(C.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(O.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},e9=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,g.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(en()((e,l)=>f(e,l),300),[]),v=(e,l)=>{j(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(E.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(I.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(I.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:(0,r.jsxs)(U.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},le=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,j]=(0,i.useState)(!1),[f]=I.Z.useForm(),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[k,E]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.Xm)(a,s);u(e)}catch(e){A.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.cu)(a,s,l),A.ZP.success("Team member added successfully"),j(!1),f.resetFields(),L()}catch(e){A.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},z=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.sN)(a,s,l),A.ZP.success("Team member updated successfully"),b(!1),L()}catch(e){A.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,g.Lp)(a,s,e),A.ZP.success("Team member removed successfully"),L()}catch(e){A.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,g.Gh)(a,t),A.ZP.success("Team settings updated successfully"),E(!1),L()}catch(e){A.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:K.team_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"User Email"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>V(e),icon:eT.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(v.Z,{onClick:()=>j(!0),children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Team Settings"}),P&&!k&&(0,r.jsx)(v.Z,{onClick:()=>E(!0),children:"Edit Settings"})]}),k?(0,r.jsxs)(I.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(M.Z,{type:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>E(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(ew.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e7,{visible:y,onCancel:()=>b(!1),onSubmit:z,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(e9,{isVisible:p,onCancel:()=>j(!1),onSubmit:R,accessToken:a})]})},ll=s(30150);function ls(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,j,f,b,Z,N,k,C;let{modelId:E,onClose:P,modelData:T,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=I.Z.useForm(),[V,q]=(0,i.useState)(T),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:E}};await (0,g.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),A.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),A.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!T)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(w.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,g.Og)(M,E),A.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),A.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(S.Z,{children:["Public Model Name: ",e4(T)]}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-6",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,r.jsx)("img",{src:eQ(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(S.Z,{children:T.provider||"Not Set"})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(S.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,r.jsxs)(w.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(I.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*T.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*T.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*T.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*T.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(I.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(I.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=V.litellm_params)||void 0===j?void 0:j.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(I.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(b=V.litellm_params)||void 0===b?void 0:b.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(I.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(k=V.litellm_params)||void 0===k?void 0:k.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(v.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(O.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(O.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var lt=s(67960),la=s(47451),lr=s(69410),li=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=I.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(I.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(I.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(y.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(C.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(y.Z,{placeholder:t(l)})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(I.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},ln=()=>{let e=I.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=I.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=I.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(y.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)(Y.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:lo}=J.default;var ld=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(I.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(y.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(y.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(y.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(W.Z,{...s,children:(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(X.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(C.default,{placeholder:"Select API Base",children:[(0,r.jsx)(C.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(C.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(y.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(y.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(I.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(lo,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(y.Z,{placeholder:"sk-",type:"password"})})]})},lc=s(63709),lm=s(90464);let{Link:lu}=J.default;var lh=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=I.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(b.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(I.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(B,{teams:t})}),(0,r.jsx)(I.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lc.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(I.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}):(0,r.jsx)(I.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)(I.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lc.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(I.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(la.Z,{className:"mb-4",children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(I.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lx,Link:lp}=J.default;var lg=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lx,{level:2,children:"Add new model"}),(0,r.jsx)(lt.Z,{children:(0,r.jsx)(I.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(C.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eX[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(li,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(ln,{}),(0,r.jsx)(ld,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lh,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(U.Z,{title:"Get help on our github",children:(0,r.jsx)(J.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lj=s(49084);function lf(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let l_=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:eQ(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(U.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:lv,Link:ly}=J.default,lb={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lZ=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[k,C]=(0,i.useState)([]),[E,P]=(0,i.useState)(a.OpenAI),[O,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[G,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[ew,eP]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==ew?void 0:ew.token;void 0===r&&(r=null);let i=eT;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,g.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,g.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,g.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,g.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,g.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,g.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[ew,eT]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,g.K_)(l,{router_settings:{model_group_retry_policy:ex}}),A.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),A.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let j=await (0,g.hy)(l);C(j);let f=await (0,g.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,g.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,g.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,g.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,g.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eT),S=await (0,g.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,g.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,g.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,g.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,g.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==j&&a(),eJ()},[l,s,t,n,j,y]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(j)),null!=j&&"object"==typeof j&&e in j)?j[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e8=l.litellm_params)||void 0===e8?void 0:e8.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=J.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 e7=async()=>{try{A.ZP.info("Running health check..."),M("");let e=await (0,g.EY)(l);M(e)}catch(e){console.error("Error running health check:",e),M("Error running health check")}};w.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{eP(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(H.Z,{value:String(l),disabled:!0,onClick:()=>{eP(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(H.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(E)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===E);return(e9&&k.find(e=>e.name===e$[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(le,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(ls,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"All Models"}),(0,r.jsx)(ek.Z,{children:"Add Model"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(ek.Z,{children:"Model Analytics"}),(0,r.jsx)(ek.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[y&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",y]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(H.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(lf,{columns:l_(m,ez,eB,e4,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e3,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e5(e,l,D,F)})]}),(0,r.jsx)(eA.Z,{className:"h-full",children:(0,r.jsx)(lg,{form:p,handleOk:()=>{p.validateFields().then(e=>{e2(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:E,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e1(e,j);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e0,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?A.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&A.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(v.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(S.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(w.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lb&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lb).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(T.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(v.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lN=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=I.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(E.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(I.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lw=s(15731);let lS=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(U.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(U.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lw.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(_.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(ew.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(ew.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lk(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lC=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(1),[_,y]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[E,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(E&&l)try{if(await (0,g.Eb)(l,[E]),A.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==E);h(e)}}catch(e){console.error("Error deleting user:",e),A.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,g.pf)(l,e,null),A.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(j));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,g.Br)(l,null,a,!0,j,25);sessionStorage.setItem("userList_".concat(j),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,g.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,j]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lS(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(er,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||j<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||j>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lk,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lN,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",E]})]})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(v.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lI=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,g.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,g.cu)(l,e,{user_id:s,role:"user"}),A.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),A.ZP.error("Failed to join team")}};return(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Description"}),(0,r.jsx)(ey.Z,{children:"Members"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsxs)(ef.Z,{children:[t.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.team_alias})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.description||"No description available"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ew.Z,{size:"xs",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(w.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lA=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,R(s,l)};var lE=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&j(t,n,o,u,a),eP()},[c]);let[S]=I.Z.useForm(),[k]=I.Z.useForm(),{Title:P,Paragraph:R}=J.default,[z,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[G,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lA(x,ea);console.log("models: ".concat(e)),em(e),S.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,g.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},eZ=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,g.rs)(t,eo),j(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await L(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));A.ZP.info("Creating Team");let o=await (0,g.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),A.ZP.success("Team created"),S.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),A.ZP.error("Error creating the team: "+e,20)}},eP=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:G?(0,r.jsx)(le,{teamId:G,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===G)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Your Teams"}),(0,r.jsx)(ek.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eP})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(w.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Team ID"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Organization"}),(0,r.jsx)(ey.Z,{children:"Info"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)})},l))}):null}),(0,r.jsx)(e_.Z,{children:e.organization_id}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(e_.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>eg(e.team_id),icon:eT.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(v.Z,{onClick:eZ,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(E.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),S.resetFields()},onCancel:()=>{Q(!1),S.resetFields()},children:(0,r.jsxs)(I.Z,{form:S,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(C.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{S.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(C.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(y.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lI,{accessToken:t,userID:n})})]})]})})},lP=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[k,E]=(0,i.useState)(null),P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.t$)(a,s);u(e)}catch(e){A.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.vh)(a,s,l),A.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.LY)(a,s,l),A.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,g.Sb)(a,s,e.user_id),A.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,g.VA)(a,l),A.ZP.success("Organization settings updated successfully"),f(!1),L()}catch(e){A.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:m.organization_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Created At"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{E({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(v.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Organization Settings"}),P&&!j&&(0,r.jsx)(v.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,r.jsxs)(I.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(M.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(e9,{isVisible:y,onCancel:()=>b(!1),onSubmit:R,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e7,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:k,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lO=async(e,l)=>{l(await (0,g.r6)(e))};var lT=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[k,P]=(0,i.useState)(!1),[O]=I.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lO(a,m)},[l,a]);let L=e=>{e&&(S(e),Z(!0))},R=async()=>{if(N&&a)try{await (0,g.cq)(a,N),A.ZP.success("Organization deleted successfully"),Z(!1),S(null),lO(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,g.H1)(a,e),P(!1),O.resetFields(),lO(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lP,{organizationId:h,onClose:()=>{x(null),j(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(ek.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(w.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Organization ID"}),(0,r.jsx)(ey.Z,{children:"Organization Name"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ey.Z,{children:"Info"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.organization_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{children:e.organization_alias}),(0,r.jsx)(e_.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{children:e.spend}),(0,r.jsx)(e_.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)},l))})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(e_.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{x(e.organization_id),j(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>L(e.organization_id),icon:eT.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>P(!0),children:"+ Create New Organization"}),(0,r.jsx)(E.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{P(!1),O.resetFields()},children:(0,r.jsxs)(I.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(v.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),b?(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 Organization"}),(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 organization?"})})]})})}),(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)(v.Z,{onClick:R,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),S(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(w.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lM=s(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lR=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lD[e];return l?l.fields.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(M.Z.Password,{}):(0,r.jsx)(y.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(I.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(C.default,{children:Object.entries(lL).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(I.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(E.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(w.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)(O.ZP,{onClick:n,children:"Done"})})]})]})};let lF=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lU=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=I.Z.useForm(),[d]=I.Z.useForm(),{Title:c,Paragraph:m}=J.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[P,T]=(0,i.useState)(!1),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,G]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lF(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){A.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,g.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),A.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,g.eH)(s,e.ip);let l=await (0,g.PT)(s);B(l),A.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),A.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{G(e),q(!0)},et=async()=>{if(H&&s)try{await (0,g.$I)(s,H);let e=await (0,g.PT)(s);B(e.length>0?e:[X]),A.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),A.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),G(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,g.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,g.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,g.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;A.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,g.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,g.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,g.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:()=>!0===a?T(!0):A.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lR,{isAddSSOModalVisible:P,isInstructionsModalVisible:L,handleAddSSOOk:()=>{T(!1),o.resetFields()},handleAddSSOCancel:()=>{T(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),T(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(E.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(v.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"IP Address"}),(0,r.jsx)(ey.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:K.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e}),(0,r.jsx)(e_.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(v.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(E.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(I.Z,{onFinish:el,children:[(0,r.jsx)(I.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(M.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(I.Z.Item,{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(E.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(v.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lM.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lz=s(92858),lV=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=I.Z.useForm();return(0,r.jsxs)(I.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{align:"center",children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(I.Z.Item,{name:e.field_name,children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(I.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lq=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,g.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lV,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,g.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,g.jA)(l,"alerting",["slack"]):(0,g.jA)(l,"alerting",[])),A.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lK=s(86582);let{Title:lB,Paragraph:lH}=J.default;console.log=function(){};var lJ=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=I.Z.useForm(),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)(""),[N,S]=(0,i.useState)({}),[k,P]=(0,i.useState)([]),[T,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),J=e=>{k.includes(e)?P(k.filter(l=>l!==e)):P([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),P(e.active_alerts),Z(s),S(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,g.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,g.K_)(l,{environment_variables:s}),A.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,g.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),A.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(ek.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(ek.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(ek.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(_.Z,{numItems:2,children:(0,r.jsx)(eS.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ey.Z,{children:"Callback Name"})})}),(0,r.jsx)(ef.Z,{children:n.map((e,s)=>(0,r.jsxs)(eb.Z,{className:"flex justify-between",children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(w.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)}):(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:b})})]},l)})})]}),(0,r.jsx)(v.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,g.K_)(l,s)}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lq,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Email Settings"}),(0,r.jsxs)(w.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(e_.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(_.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(w.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"mt-2",children:l}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(E.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(I.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lK.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(C.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(H.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lK.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(y.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(E.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(I.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lK.Z,{label:l,name:l,children:(0,r.jsx)(y.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lG=s(92414),lW=s(46030);let{Option:lY}=C.default;var l$=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(E.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(I.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,g.K_)(s,{router_settings:o}),a(o)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eN.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(I.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lG.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lX=s(33619);async function lQ(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lX.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});A.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l0={ttl:3600,lowest_latency_buffer:0},l1=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(Z.Z,{children:"latency-based-routing"==l?(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(w.Z,{children:"No specific settings"})})]})};var l2=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=I.Z.useForm(),[j,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[k,C]=(0,i.useState)(null),E={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,g.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,g.K_)(l,{router_settings:t}),o(t),A.ZP.success("Router settings updated successfully")}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},M=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,g.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,g.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,g.K_)(l,{router_settings:s})}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(ek.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(ek.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(S.Z,{children:"Router Settings"}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:E[l]})]}),(0,r.jsx)(e_.Z,{children:"routing_strategy"==l?(0,r.jsxs)(eN.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(H.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(H.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(H.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l1,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l0,paramExplanation:E})]}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Model Name"}),(0,r.jsx)(ey.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(ef.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:t}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{onClick:()=>lQ(t,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(l$,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"}),(0,r.jsx)(ey.Z,{children:"Status"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(e_.Z,{children:"Integer"==e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(v.Z,{onClick:()=>M(e.field_name,l),children:"Update"}),(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l4=s(93142),l5=s(45246),l3=s(96473),l6=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l4.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(y.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(y.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l5.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(O.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l3.Z,{}),children:"Add Header"})]})};let{Option:l8}=C.default;var l7=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=I.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(E.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(I.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,g.Vt)(l,e),s(r)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l6,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},l9=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,g.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,g.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),A.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Path"}),(0,r.jsx)(ey.Z,{children:"Target"}),(0,r.jsx)(ey.Z,{children:"Headers"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:n.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.path})}),(0,r.jsx)(e_.Z,{children:e.target}),(0,r.jsx)(e_.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l7,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},se=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=I.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call");let l=await (0,g.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),A.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(I.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=I.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call"),t(!0);let l=await (0,g.qI)(s,e);a(e=>e?[...e,l]:[l]),A.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(I.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},ss=s(17906),st=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,g.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;A.ZP.info("Request made"),await (0,g.NV)(l,e);let t=[...c];t.splice(s,1),m(t),A.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,g.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(v.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(se,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(sl,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Budget ID"}),(0,r.jsx)(ey.Z,{children:"Max Budget"}),(0,r.jsx)(ey.Z,{children:"TPM"}),(0,r.jsx)(ey.Z,{children:"RPM"})]})}),(0,r.jsx)(ef.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.budget_id}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(e_.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(e_.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(ek.Z,{children:"Test it (Curl)"}),(0,r.jsx)(ek.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sa=s(77398),sr=s.n(sa),si=s(20016);async function sn(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let so=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return sn(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sd=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sc=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sd(l)})},sm=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sc,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(U.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(so,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:eQ(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(U.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],su=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,g.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sh=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sx=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sp=["Internal User","Internal Viewer"],sg=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sj(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(sr()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(sr()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sp.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sp.includes(o)&&q(!0)},[o]);let B=(0,si.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=sr()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?sr()(S).utc().format("YYYY-MM-DD HH:mm:ss"):sr()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,g.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await su(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(sr()(N).format("MMM D, h:mm A")," - ").concat(sr()(S).format("MMM D, h:mm A"));let e=sr()(),l=sr()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>j(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),j(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(sr()().format("YYYY-MM-DDTHH:mm")),w(sr()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eZ,{columns:sm,data:H,renderSubComponent:sf,getRowCanExpand:()=>!0})]})]})}function sf(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sg,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sh,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var s_=s(92699),sv=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(w.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(ek.Z,{children:"LlamaIndex"}),(0,r.jsx)(ek.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sy=s(243),sb=s(94263);async function sZ(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lX.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sN=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[j,b]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[S,k]=(0,i.useState)([]),I=(0,i.useRef)(null),E=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,g.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),b(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{E.current&&setTimeout(()=>{var e;null===(e=E.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){A.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{j&&await sZ(i,(e,l)=>P("assistant",e,l),j,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=J.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)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsx)(eI.Z,{children:(0,r.jsx)(ek.Z,{children:"Chat"})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"API Key Source"}),(0,r.jsx)(C.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(f.Z,{className:"mx-2",children:[(0,r.jsx)(w.Z,{children:"Select Model:"}),(0,r.jsx)(C.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),b(e),N("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{b(e)},500)}})]})]}),(0,r.jsx)(v.Z,{onClick:()=>{p([]),A.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ej.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsxs)(ef.Z,{children:[x.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sy.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(ss.Z,{style:sb.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{ref:E,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(y.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(v.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sw=s(19226),sS=s(45937),sk=s(92403),sC=s(28595),sI=s(68208),sA=s(9775),sE=s(41361),sP=s(37527),sO=s(12660),sT=s(88009),sM=s(48231),sL=s(41169),sD=s(44625),sR=s(57400),sF=s(55322);let{Sider:sU}=sw.default,sz=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sk.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sC.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sI.Z,{}),roles:sx},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sA.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sE.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sx},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sO.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sT.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sM.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sL.Z,{}),roles:sx,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sD.Z,{}),roles:sx},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sR.Z,{}),roles:sx}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sO.Z,{}),roles:sx},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx}]}];var sV=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sz.find(l=>l.page===e);if(l)return l.key;for(let l of sz)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sz.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sw.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sU,{theme:"light",width:220,children:(0,r.jsx)(sS.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sq=s(40278),sK=s(96889),sB=s(97765);console.log=function(){};var sH=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,g.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let j=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",j]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sJ=s(69907),sG=s(53003),sW=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let sY=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var s$=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,k]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[J,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,g.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,g.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),y(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),k((await (0,g.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,g.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,g.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,g.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,g.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,g.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,g.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,g.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>k(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,g.b1)(l,null,void 0,void 0),y,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,g.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},eZ=async()=>{if(l)try{let e=await (0,g.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",J),eo(),ed(),ec(),em(),eg(),eZ(),sY(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==J?void 0:J.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(w.Z,{className:"mt-4",children:["SpendLogs in DB has ",J.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(v.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mt-2",children:[(0,r.jsx)(ek.Z,{children:"All Up"}),sY(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ek.Z,{children:"Team Based Usage"}),(0,r.jsx)(ek.Z,{children:"Customer Usage"}),(0,r.jsx)(ek.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(ek.Z,{children:"Cost"}),(0,r.jsx)(ek.Z,{children:"Activity"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(w.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sH,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Monthly Spend"}),(0,r.jsx)(sq.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top API Keys"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top Models"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Provider"}),(0,r.jsx)(ey.Z,{children:"Spend"})]})}),(0,r.jsx)(ef.Z,{children:T.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.provider}),(0,r.jsx)(e_.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"All Up"}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:e.model}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sK.Z,{data:P})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sq.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(f.Z,{numColSpan:2})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Time Range"}),(0,r.jsx)(sG.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Key"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(eS.Z,{className:"mt-4",children:(0,r.jsxs)(ej.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Customer"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Total Events"})]})}),(0,r.jsx)(ef.Z,{children:null==j?void 0:j.map((e,l)=>{var s;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(e_.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sG.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(f.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lW.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(H.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(w.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sq.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(f.Z,{numColSpan:2})]})]})]})]})})},sX=s(51853);let sQ=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s0=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s1=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sX.Z,{className:"h-4 w-4"})})]})})})},s2=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s0(j.litellm_params)||{},_=s0(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s0(null==g?void 0:g.litellm_cache_params)||{},_=s0(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(w.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s1,{label:"Error Message",value:j.message}),(0,r.jsx)(s1,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s1,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s1,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s1,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s1,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s1,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s1,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s1,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s1,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s1,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s4=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(v.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(sQ,{responseTimeMs:n})]}),s&&(0,r.jsx)(s2,{response:s})]})},s5=e=>{if(e)return e.toISOString().split("T")[0]};function s3(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s6=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,v]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[S,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[E,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&S&&((async()=>{p(await (0,g.zg)(l,s5(S.from),s5(S.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,g.zg)(l,s5(e),s5(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);v(s3(s)),b(s3(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,S,x]);let L=async()=>{try{A.ZP.info("Running cache health check..."),P("");let e=await (0,g.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Cache Analytics"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(_.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(sG.Z,{enableSelect:!0,value:S,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:j})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sq.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sq.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(s4,{accessToken:l,healthCheckResponse:E,runCachingHealthCheck:L})})]})]})},s8=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,g.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(w.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Guardrail Name"}),(0,r.jsx)(ey.Z,{children:"Mode"}),(0,r.jsx)(ey.Z,{children:"Status"})]})}),(0,r.jsx)(ef.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.guardrail_name}),(0,r.jsx)(e_.Z,{children:e.litellm_params.mode}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s7=new d.S;function s9(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[f,_]=(0,i.useState)(null),[v,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,k]=(0,i.useState)(!0),C=(0,n.useSearchParams)(),[I,A]=(0,i.useState)({data:[]}),[E,P]=(0,i.useState)(null),O=C.get("userID"),T=C.get("invitation_id"),[M,L]=(0,i.useState)(()=>C.get("page")||"api-keys"),[D,R]=(0,i.useState)(null);return(0,i.useEffect)(()=>{P(function(e){let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"))},[]),(0,i.useEffect)(()=>{if(!E)return;let e=(0,o.o)(E);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),R(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&L("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?k("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,g.K8)(e.auth_header_name)}},[E]),(0,i.useEffect)(()=>{D&&O&&e&&em(O,e,D,Z),D&&O&&e&&j(D,O,e,null,x),D&&lO(D,y)},[D,O,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s7,children:T?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(p,{userID:O,userRole:e,premiumUser:s,setProxySettings:w,proxySettings:N}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sV,{setPage:e=>{let l=new URLSearchParams(C);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),L(e)},userRole:e,defaultSelectedKey:M})}),"api-keys"==M?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):"models"==M?(0,r.jsx)(lZ,{userID:O,userRole:e,token:E,keys:f,accessToken:D,modelData:I,setModelData:A,premiumUser:s,teams:h}):"llm-playground"==M?(0,r.jsx)(sN,{userID:O,userRole:e,token:E,accessToken:D,disabledPersonalKeyCreation:a}):"users"==M?(0,r.jsx)(lC,{userID:O,userRole:e,token:E,keys:f,teams:h,accessToken:D,setKeys:_}):"teams"==M?(0,r.jsx)(lE,{teams:h,setTeams:x,searchParams:C,accessToken:D,userID:O,userRole:e,organizations:v}):"organizations"==M?(0,r.jsx)(lT,{organizations:v,setOrganizations:y,userModels:b,accessToken:D,userRole:e,premiumUser:s}):"admin-panel"==M?(0,r.jsx)(lU,{setTeams:x,searchParams:C,accessToken:D,showSSOBanner:S,premiumUser:s}):"api_ref"==M?(0,r.jsx)(sv,{proxySettings:N}):"settings"==M?(0,r.jsx)(lJ,{userID:O,userRole:e,accessToken:D,premiumUser:s}):"budgets"==M?(0,r.jsx)(st,{accessToken:D}):"guardrails"==M?(0,r.jsx)(s8,{accessToken:D}):"general-settings"==M?(0,r.jsx)(l2,{userID:O,userRole:e,accessToken:D,modelData:I}):"model-hub"==M?(0,r.jsx)(s_.Z,{accessToken:D,publicPage:!1,premiumUser:s}):"caching"==M?(0,r.jsx)(s6,{userID:O,userRole:e,token:E,accessToken:D,premiumUser:s}):"pass-through-settings"==M?(0,r.jsx)(l9,{userID:O,userRole:e,accessToken:D,modelData:I}):"logs"==M?(0,r.jsx)(sj,{userID:O,userRole:e,token:E,accessToken:D}):(0,r.jsx)(s$,{userID:O,userRole:e,token:E,accessToken:D,keys:f,premiumUser:s})]})]})})})}}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/index.html b/litellm/proxy/_experimental/out/index.html index 07624d4899..ae2e51152b 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 0830197521..32025bae5b 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-a006114359094d34.js"],"default",1] +3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-e28453cd004ff93c.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/_experimental/out/model_hub.txt b/litellm/proxy/_experimental/out/model_hub.txt index 54a3766fb8..2bef2383df 100644 --- a/litellm/proxy/_experimental/out/model_hub.txt +++ b/litellm/proxy/_experimental/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","418","static/chunks/app/model_hub/page-6f97b95f1023b0e9.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/_experimental/out/onboarding.txt b/litellm/proxy/_experimental/out/onboarding.txt index e05b041088..ec0568e731 100644 --- a/litellm/proxy/_experimental/out/onboarding.txt +++ b/litellm/proxy/_experimental/out/onboarding.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-8ba945cf183c937c.js"],"default",1] +3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-f2e9aa9e77b66520.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/404.html b/ui/litellm-dashboard/out/404.html index 6658255bbc..8bea7c8210 100644 --- a/ui/litellm-dashboard/out/404.html +++ b/ui/litellm-dashboard/out/404.html @@ -1 +1 @@ -404: This page could not be found.LiteLLM Dashboard

404

This page could not be found.

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

404

This page could not be found.

\ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js deleted file mode 100644 index a22da3c6fe..0000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-8ba945cf183c937c.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,t,n){Promise.resolve().then(n.bind(n,12011))},12011:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return g}});var o=n(57437),a=n(2265),c=n(99376),s=n(20831),i=n(94789),l=n(12514),r=n(49804),u=n(67101),m=n(84264),d=n(49566),h=n(96761),p=n(84566),f=n(19250),x=n(14474),k=n(13634),_=n(73002),j=n(3914);function g(){let[e]=k.Z.useForm(),t=(0,c.useSearchParams)();(0,j.bW)();let n=t.get("invitation_id"),[g,w]=(0,a.useState)(null),[S,Z]=(0,a.useState)(""),[b,N]=(0,a.useState)(""),[v,y]=(0,a.useState)(null),[T,E]=(0,a.useState)(""),[C,U]=(0,a.useState)("");return(0,a.useEffect)(()=>{n&&(0,f.W_)(n).then(e=>{let t=e.login_url;console.log("login_url:",t),E(t);let n=e.token,o=(0,x.o)(n);U(n),console.log("decoded:",o),w(o.key),console.log("decoded user email:",o.user_email),N(o.user_email),y(o.user_id)})},[n]),(0,o.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,o.jsxs)(l.Z,{children:[(0,o.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,o.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,o.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,o.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,o.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,o.jsx)(r.Z,{children:"SSO is under the Enterprise Tirer."}),(0,o.jsx)(r.Z,{children:(0,o.jsx)(s.Z,{variant:"primary",className:"mb-2",children:(0,o.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,o.jsxs)(k.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",C,"formValues:",e),g&&C&&(e.user_email=b,v&&n&&(0,f.m_)(g,n,v,e.password).then(e=>{var t;let n="/ui/";n+="?userID="+((null===(t=e.data)||void 0===t?void 0:t.user_id)||e.user_id),(0,j.uB)(C),console.log("redirecting to:",n),window.location.href=n}))},children:[(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(k.Z.Item,{label:"Email Address",name:"user_email",children:(0,o.jsx)(d.Z,{type:"email",disabled:!0,value:b,defaultValue:b,className:"max-w-md"})}),(0,o.jsx)(k.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,o.jsx)(d.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,o.jsx)("div",{className:"mt-10",children:(0,o.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},3914:function(e,t,n){"use strict";function o(){let e=window.location.hostname,t=["/","/ui"],n=["Lax","Strict","None"],o=document.cookie.split("; "),a=/^token_\d+$/;o.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(o=>{t.forEach(t=>{document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,";"),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,";"),n.forEach(n=>{let a="None"===n?" Secure;":"";document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; SameSite=").concat(n,";").concat(a),document.cookie="".concat(o,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(t,"; domain=").concat(e,"; SameSite=").concat(n,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let t=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(t),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function c(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,t=document.cookie.split("; ").map(t=>{let n=t.split("="),o=n[0];if("token"===o)return null;let a=o.match(e);return a?{name:o,timestamp:parseInt(a[1],10),value:n.slice(1).join("=")}:null}).filter(e=>null!==e);return t.length>0?(t.sort((e,t)=>t.timestamp-e.timestamp),t[0].value):null}n.d(t,{bA:function(){return o},bW:function(){return c},uB:function(){return a}})}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js new file mode 100644 index 0000000000..2909ac65a0 --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/onboarding/page-f2e9aa9e77b66520.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{32922:function(e,s,t){Promise.resolve().then(t.bind(t,12011))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return g}});var l=t(57437),n=t(2265),a=t(99376),i=t(20831),r=t(94789),o=t(12514),c=t(49804),u=t(67101),d=t(84264),m=t(49566),h=t(96761),x=t(84566),f=t(19250),p=t(14474),j=t(13634),_=t(73002);function g(){let[e]=j.Z.useForm(),s=(0,a.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));s&&s.split("=")[1]}("token");let t=s.get("invitation_id"),[g,Z]=(0,n.useState)(null),[k,w]=(0,n.useState)(""),[S,b]=(0,n.useState)(""),[N,v]=(0,n.useState)(null),[y,E]=(0,n.useState)(""),[I,O]=(0,n.useState)("");return(0,n.useEffect)(()=>{t&&(0,f.W_)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),E(s);let t=e.token,l=(0,p.o)(t);O(t),console.log("decoded:",l),Z(l.key),console.log("decoded user email:",l.user_email),b(l.user_email),v(l.user_id)})},[t]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,l.jsx)(d.Z,{children:"Claim your user account to login to Admin UI."}),(0,l.jsx)(r.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,l.jsxs)(u.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tirer."}),(0,l.jsx)(c.Z,{children:(0,l.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,l.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,l.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",g,"token:",I,"formValues:",e),g&&I&&(e.user_email=S,N&&t&&(0,f.m_)(g,t,N,e.password).then(e=>{var s;let t="/ui/";t+="?userID="+((null===(s=e.data)||void 0===s?void 0:s.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",t),window.location.href=t}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(m.Z,{type:"email",disabled:!0,value:S,defaultValue:S,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,l.jsx)(m.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(_.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}}},function(e){e.O(0,[665,441,899,250,971,117,744],function(){return e(e.s=32922)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js deleted file mode 100644 index d7f1882c15..0000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/page-a006114359094d34.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return v}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002),_=s(3914);function v(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();(0,_.bW)();let s=l.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[S,k]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[A,E]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),I(l);let s=e.token,t=(0,g.o)(s);E(s),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),k(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",A,"formValues:",e),v&&A&&(e.user_email=N,S&&s&&(0,p.m_)(v,s,S,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),(0,_.uB)(A),console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return te}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=s(3914),g=e=>{let{userID:l,userEmail:s,userRole:t,premiumUser:a,proxySettings:i}=e,n=(null==i?void 0:i.PROXY_LOGOUT_URL)||"",o=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",s||"Unknown"]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,p.bA)(),window.location.href=n},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:o,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},j=s(19250);let f=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,j.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,j.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var _=s(49804),v=s(67101),y=s(20831),b=s(49566),Z=s(87452),N=s(88829),w=s(72208),S=s(84264),k=s(96761),C=s(29233),I=s(52787),A=s(13634),E=s(41021),P=s(51369),O=s(29967),T=s(73002),M=s(20577),L=s(56632);let D=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,j.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},R=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},F=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var U=s(15424),z=s(98074);let V=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,q=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},K=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return V(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var B=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),V(e,l)&&p.push({validator:async(e,l)=>{if(l&&!q(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(z.Z,{title:h,children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}):u;return t=V(e,l)?(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(I.default,{children:l.enum.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(M.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(b.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(b.Z,{placeholder:h||""}),(0,r.jsx)(A.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:K(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},H=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(I.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},J=s(57365),G=s(93192);function W(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=G.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(P.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(S.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(S.Z,{children:"Invitation Link"}),(0,r.jsx)(S.Z,{children:(0,r.jsx)(S.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>E.ZP.success("Copied!"),children:(0,r.jsx)(y.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var Y=s(30967),$=s(28181),X=s(73879),Q=s(3632),ee=s(15452),el=s.n(ee),es=s(71157),et=s(44643),ea=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.g)(l);g(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let v=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,j.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,j.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(P.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=new Blob([el().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(Y.Z,{beforeUpload:e=>(x(null),el().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(Q.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(y.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(S.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(S.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(S.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(et.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(S.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)($.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(C.CopyToClipboard,{text:l.invitation_link,onCopy:()=>E.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(y.Z,{onClick:v,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(y.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(y.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([el().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)(X.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:er}=I.default;var ei=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=A.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[v,C]=(0,i.useState)(!1),[O,M]=(0,i.useState)(null),D=(0,n.useRouter)(),[F,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,j.So)(s,l,"any"),t=[];for(let l=0;l{D&&V(new URL("/",window.location.href).toString())},[D]);let q=async e=>{var t,a,r;try{E.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.Ov)(s,null,e);console.log("user create Response:",a),g(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};M(e),C(!0)}else(0,j.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,M(e),C(!0)});E.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";E.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(ea,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(P.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),g(null),u.resetFields()},children:[(0,r.jsx)(S.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(A.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(z.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(U.Z,{})})]}),name:"user_role",children:(0,r.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(er,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(er,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(A.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(W,{isInvitationLinkModalVisible:v,setIsInvitationLinkModalVisible:C,baseUrl:F,invitationLinkData:O})]})},en=s(7310),eo=s.n(en);let{Option:ed}=I.default,ec=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},em=(e,l)=>F(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),eu=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,j.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eh=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,D]=(0,i.useState)([]),[F,V]=(0,i.useState)([]),[q,K]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ec(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[er,en]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&eu(l,a,n,D)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,j.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,j.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(E.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,j.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),g(m.soft_budget),E.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),E.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(em($,f)),c.setFieldValue("models",[])},[$,f]);let ef=async e=>{if(!e){en([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,j.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(s)}catch(e){console.error("Error fetching users:",e),E.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(eo()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(P.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(A.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(z.Z,{title:"Select who will own this API key",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(O.ZP.Group,{onChange:e=>K(e.target.value),value:q,children:[(0,r.jsx)(O.ZP,{value:"you",children:"You"}),(0,r.jsx)(O.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(O.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(z.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:er,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(T.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(z.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(H,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(k.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(z.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),F.map(e=>(0,r.jsx)(ed,{value:e,children:R(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)(k.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(z.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(z.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(z.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(z.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(b.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(z.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(z.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(Z.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:j.H2?"".concat(j.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(U.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(N.Z,{children:(0,r.jsx)(B,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(P.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(ei,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(P.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Save your Key"}),(0,r.jsx)(_.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)(_.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(S.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:h})}),(0,r.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{E.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(S.Z,{children:"Key being created, this might take 30s"})})]})})]})},ex=s(7366),ep=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,j.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},eg=s(71594),ej=s(24525),ef=s(21626),e_=s(97214),ev=s(28241),ey=s(58834),eb=s(69552),eZ=s(71876);function eN(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,eg.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,ej.sC)(),getExpandedRowModel:(0,ej.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:n?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var ew=s(27281),eS=s(41649),ek=s(12514),eC=s(12485),eI=s(18135),eA=s(35242),eE=s(29706),eP=s(77991),eO=s(10900),eT=s(23628),eM=s(74998);function eL(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=A.Z.useForm(),[h,x]=(0,i.useState)([]),p=em(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,j.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let g={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(A.Z,{form:u,onFinish:n,initialValues:g,layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(M.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(L.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(L.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(y.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]})}function eD(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let g=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,j.s0)(a,l.token,e);d(s.key),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key"),p(!1)}}},f=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(P.Z,{title:"Regenerate API Key",open:s,onCancel:f,footer:o?[(0,r.jsx)(y.Z,{onClick:f,children:"Close"},"close")]:[(0,r.jsx)(y.Z,{onClick:f,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(C.CopyToClipboard,{text:o,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(A.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eR(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=A.Z.useForm(),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),E.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,j.Nc)(o,e),E.ZP.success("Key updated successfully"),h(!1)}catch(e){E.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,j.I1)(o,n.token),E.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),E.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{icon:eO.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(k.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(y.Z,{icon:eT.Z,variant:"secondary",onClick:()=>_(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>g(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eD,{selectedToken:n,visible:f,onClose:()=>_(!1),accessToken:o}),p&&(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)(y.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>g(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(S.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(y.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eL,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(S.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(S.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(S.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(S.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(S.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(S.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(S.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(S.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(S.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eF=s(87908),eU=s(82422),ez=s(2356),eV=s(44633),eq=s(86462),eK=s(3837),eB=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[v,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let C=(0,i.useCallback)(eo()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eU.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),O=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(y.Z,{icon:ez.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(ek.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(T.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==O?void 0:O.label)||m,f?(0,r.jsx)(eV.Z,{className:"h-4 w-4"}):(0,r.jsx)(eq.Z,{className:"h-4 w-4"})]})}),(null==O?void 0:O.isSearchable)?(0,r.jsx)(I.default,{showSearch:!0,placeholder:"Search ".concat(O.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),C(e,O)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:v,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eF.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(T.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(L.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eK.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(T.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(T.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eH=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eJ=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eG(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[g,f]=(0,i.useState)(null),[_,v]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,j.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.getValue(),children:(0,r.jsx)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(z.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eH(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eJ(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:g?(0,r.jsx)(eR,{keyId:g,onClose:()=>f(null),keyData:l.find(e=>e.token===g),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eB,{options:w,onApplyFilters:e=>{if(v({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{v({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eN,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eW=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[I,O]=(0,i.useState)(null),[T,L]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ep({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=A.Z.useForm(),[em,eu]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,ex.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,ex.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,ex.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await D(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,j.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),w(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){E.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,j.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),E.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),E.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eG,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),f&&(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)(y.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(P.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(y.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(y.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(A.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(b.Z,{disabled:!0})}),(0,r.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(M.Z,{style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(y.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(P.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(y.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(k.Z,{children:"Regenerated Key"}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(S.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(S.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(C.CopyToClipboard,{text:ei,onCopy:()=>E.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(y.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eY=s(12011);console.log=function(){},console.log("isLocal:",!1);var e$=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:g}=e,[y,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),w=(0,n.useSearchParams)(),S=(0,p.bW)(),k=w.get("invitation_id"),[C,I]=(0,i.useState)(null),[A,E]=(0,i.useState)(null),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)(null),[L,D]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(S){let e=(0,o.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),I(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&C&&s&&!a&&!y){let e=sessionStorage.getItem("userModels"+l);e?O(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.g)(C);M(e);let t=await (0,j.Br)(C,l,s,!1,null,null);b(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(y))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,j.So)(C,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),O(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),f(C,l,s,Z,u))}},[l,S,C,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(C,", userID: ").concat(l,", userRole: ").concat(s)),C&&(console.log("fetching teams"),f(C,l,s,Z,u))},[Z]),(0,i.useEffect)(()=>{if(null!==a&&null!=L&&null!==L.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))L.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===L.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),E(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;E(e)}},[L]),null!=k)return(0,r.jsx)(eY.default,{});if(null==l||null==S){console.log("All cookies before redirect:",document.cookie),(0,p.bA)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=G.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",L),console.log("All cookies after redirect:",document.cookie),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(_.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eh,{userID:l,team:L,teams:t,userRole:s,accessToken:C,data:a,setData:h},L?L.team_id:null),(0,r.jsx)(eW,{userID:l,userRole:s,accessToken:C,selectedTeam:L||null,setSelectedTeam:D,data:a,setData:h,premiumUser:x,teams:t,currentOrg:Z,setCurrentOrg:N,organizations:g})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let eX={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eQ={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},e0=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eQ[e],displayName:e}}let l=Object.keys(eX).find(l=>eX[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eQ[s],displayName:s}},e1=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e2=(e,l)=>{console.log("Provider key: ".concat(e));let s=eX[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e4=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=eX[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=eX[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw E.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,j.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){E.ZP.error("Failed to create model: "+e,10)}},e5=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e3=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,j.um)(l,i),E.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e6=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=A.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(P.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(A.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},e8=s(47323),e7=s(53410),e9=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),E.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){E.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(I.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(P.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(A.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(S.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(L.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(I.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(T.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},le=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=A.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,j.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(eo()((e,l)=>f(e,l),300),[]),v=(e,l)=>{g(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(P.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(A.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(I.default.Option,{value:e.value,children:(0,r.jsxs)(z.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(T.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},ll=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,g]=(0,i.useState)(!1),[f]=A.Z.useForm(),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.Xm)(a,s);u(e)}catch(e){E.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.cu)(a,s,l),E.ZP.success("Team member added successfully"),g(!1),f.resetFields(),O()}catch(e){E.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},F=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.sN)(a,s,l),E.ZP.success("Team member updated successfully"),b(!1),O()}catch(e){E.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,j.Lp)(a,s,e),E.ZP.success("Team member removed successfully"),O()}catch(e){E.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,j.Gh)(a,t),E.ZP.success("Team settings updated successfully"),C(!1),O()}catch(e){E.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:K.team_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"User Email"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>V(e),icon:eM.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(y.Z,{onClick:()=>g(!0),children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Team Settings"}),P&&!w&&(0,r.jsx)(y.Z,{onClick:()=>C(!0),children:"Edit Settings"})]}),w?(0,r.jsxs)(A.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(L.Z,{type:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>C(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(eS.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e9,{visible:_,onCancel:()=>b(!1),onSubmit:F,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(le,{isVisible:p,onCancel:()=>g(!1),onSubmit:D,accessToken:a})]})},ls=s(30150);function lt(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,g,f,_,Z,N,w,C;let{modelId:I,onClose:P,modelData:O,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=A.Z.useForm(),[V,q]=(0,i.useState)(O),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:I}};await (0,j.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),E.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),E.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!O)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(S.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,j.Og)(M,I),E.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),E.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(eO.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(k.Z,{children:["Public Model Name: ",e5(O)]}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:O.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(y.Z,{icon:eM.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mb-6",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[O.provider&&(0,r.jsx)("img",{src:e0(O.provider).logo,alt:"".concat(O.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=O.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(k.Z,{children:O.provider||"Not Set"})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(k.Z,{children:O.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Input: $",O.input_cost,"/1M tokens"]}),(0,r.jsxs)(S.Z,{children:["Output: $",O.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",O.model_info.created_at?new Date(O.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",O.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(A.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*O.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*O.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*O.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*O.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=V.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=V.litellm_params)||void 0===_?void 0:_.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=V.litellm_params)||void 0===w?void 0:w.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ls.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:O.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(y.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(y.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(O,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(T.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(T.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var la=s(67960),lr=s(47451),li=s(69410),ln=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=A.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(b.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(b.Z,{placeholder:t(l)})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(b.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},lo=()=>{let e=A.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=A.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=A.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(b.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)($.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:ld}=G.default;var lc=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(A.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(b.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(b.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(b.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(Y.Z,{...s,children:(0,r.jsx)(T.ZP,{icon:(0,r.jsx)(Q.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsx)(S.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(I.default,{placeholder:"Select API Base",children:[(0,r.jsx)(I.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(I.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(b.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(b.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(A.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(b.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(lr.Z,{children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(ld,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:""})}),(0,r.jsx)(A.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)(b.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(b.Z,{placeholder:"sk-",type:"password"})})]})},lm=s(63709),lu=s(90464);let{Link:lh}=G.default;var lx=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=A.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(Z.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(A.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(H,{teams:t})}),(0,r.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lm.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(I.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}):(0,r.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lm.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(A.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(lr.Z,{className:"mb-4",children:[(0,r.jsx)(li.Z,{span:10}),(0,r.jsx)(li.Z,{span:10,children:(0,r.jsxs)(S.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lh,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(A.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lu.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lp,Link:lg}=G.default;var lj=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lp,{level:2,children:"Add new model"}),(0,r.jsx)(la.Z,{children:(0,r.jsx)(A.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.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)(I.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eQ[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(ln,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(lo,{}),(0,r.jsx)(lc,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lx,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(z.Z,{title:"Get help on our github",children:(0,r.jsx)(G.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lf=s(49084);function l_(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let lv=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:e0(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(z.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(z.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:ly,Link:lb}=G.default,lZ={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lN=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[w,C]=(0,i.useState)([]),[I,P]=(0,i.useState)(a.OpenAI),[O,T]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[H,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[eN,eS]=(0,i.useState)(null),[eO,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==eN?void 0:eN.token;void 0===r&&(r=null);let i=eO;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,j.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,j.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,j.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,j.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,j.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,j.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[eN,eO]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,j.K_)(l,{router_settings:{model_group_retry_policy:ex}}),E.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),E.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let g=await (0,j.hy)(l);C(g);let f=await (0,j.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,j.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,j.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,j.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==eN?void 0:eN.token,eO);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,j.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==eN?void 0:eN.token,eO),S=await (0,j.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,j.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,j.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,j.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,j.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==g&&a(),eJ()},[l,s,t,n,g,_]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e0=l.litellm_params)||void 0===e0?void 0:e0.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=G.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 e7=async()=>{try{E.ZP.info("Running health check..."),T("");let e=await (0,j.EY)(l);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}};S.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{eS(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{eS(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(J.Z,{value:String(l),disabled:!0,onClick:()=>{eS(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(S.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(J.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(J.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(I)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===I);return(e9&&w.find(e=>e.name===eX[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(ll,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(lt,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"All Models"}),(0,r.jsx)(eC.Z,{children:"Add Model"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(eC.Z,{children:"Model Analytics"}),(0,r.jsx)(eC.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",_]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(J.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(l_,{columns:lv(m,ez,eB,e5,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e6,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e3(e,l,D,F)})]}),(0,r.jsx)(eE.Z,{className:"h-full",children:(0,r.jsx)(lj,{form:p,handleOk:()=>{p.validateFields().then(e=>{e4(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:I,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e2(e,g);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e1,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?E.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&E.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(y.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(S.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(ew.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(k.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(S.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lZ&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lZ).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(M.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(y.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lw=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=A.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(P.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(A.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(I.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(J.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(A.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(M.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lS=s(15731);let lk=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(z.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(z.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lS.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(v.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(eS.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(eS.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lC(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,eg.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,ej.sC)(),getSortedRowModel:(0,ej.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ef.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ey.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eZ.Z,{children:e.headers.map(e=>(0,r.jsx)(eb.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,eg.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eq.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lf.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(e_.Z,{children:t?(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eZ.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(ev.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,eg.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lI=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(1),[_,v]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[A,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(A&&l)try{if(await (0,j.Eb)(l,[A]),E.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==A);h(e)}}catch(e){console.error("Error deleting user:",e),E.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,j.pf)(l,e,null),E.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(g));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,j.Br)(l,null,a,!0,g,25);sessionStorage.setItem("userList_".concat(g),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,j.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,g]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lk(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(ei,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||g<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||g>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lC,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lw,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",A]})]})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lA=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,j.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,j.cu)(l,e,{user_id:s,role:"user"}),E.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),E.ZP.error("Failed to join team")}};return(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Description"}),(0,r.jsx)(eb.Z,{children:"Members"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsxs)(e_.Z,{children:[t.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.team_alias})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.description||"No description available"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eS.Z,{size:"xs",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(S.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lE=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,F(s,l)};var lP=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&f(t,n,o,u,a),ew()},[c]);let[g]=A.Z.useForm(),[k]=A.Z.useForm(),{Title:C,Paragraph:O}=G.default,[F,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[J,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lE(x,ea);console.log("models: ".concat(e)),em(e),g.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,j.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},ej=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,j.rs)(t,eo),f(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await D(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));E.ZP.info("Creating Team");let o=await (0,j.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),E.ZP.success("Team created"),g.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),E.ZP.error("Error creating the team: "+e,20)}},ew=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:J?(0,r.jsx)(ll,{teamId:J,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===J)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Your Teams"}),(0,r.jsx)(eC.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(S.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Team Name"}),(0,r.jsx)(eb.Z,{children:"Team ID"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"Organization"}),(0,r.jsx)(eb.Z,{children:"Info"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.team_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ev.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ev.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)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(S.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(S.Z,{children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)})},l))}):null}),(0,r.jsx)(ev.Z,{children:e.organization_id}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(S.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(ev.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>eg(e.team_id),icon:eM.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(y.Z,{onClick:ej,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(P.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),g.resetFields()},onCancel:()=>{Q(!1),g.resetFields()},children:(0,r.jsxs)(A.Z,{form:g,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(z.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{g.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(z.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(b.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)(A.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(z.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(U.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lA,{accessToken:t,userID:n})})]})]})})},lO=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(!1),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,C]=(0,i.useState)(null),P=n||o,O=async()=>{try{if(x(!0),!a)return;let e=await (0,j.t$)(a,s);u(e)}catch(e){E.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{O()},[s,a]);let D=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.vh)(a,s,l),E.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.LY)(a,s,l),E.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,j.Sb)(a,s,e.user_id),E.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),O()}catch(e){E.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,j.VA)(a,l),E.ZP.success("Organization settings updated successfully"),f(!1),O()}catch(e){E.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(T.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(k.Z,{children:m.organization_alias}),(0,r.jsx)(S.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eI.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eA.Z,{className:"mb-4",children:[(0,r.jsx)(eC.Z,{children:"Overview"}),(0,r.jsx)(eC.Z,{children:"Members"}),(0,r.jsx)(eC.Z,{children:"Settings"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(S.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(k.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(S.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(S.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(S.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(S.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"User ID"}),(0,r.jsx)(eb.Z,{children:"Role"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Created At"}),(0,r.jsx)(eb.Z,{})]})}),(0,r.jsx)(e_.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(ev.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{C({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(y.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(k.Z,{children:"Organization Settings"}),P&&!g&&(0,r.jsx)(y.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),g?(0,r.jsxs)(A.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(L.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(T.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(y.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(eS.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(le,{isVisible:_,onCancel:()=>b(!1),onSubmit:D,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e9,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:w,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lT=async(e,l)=>{l(await (0,j.r6)(e))};var lM=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,Z]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[k,C]=(0,i.useState)(!1),[O]=A.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lT(a,m)},[l,a]);let T=e=>{e&&(w(e),Z(!0))},D=async()=>{if(N&&a)try{await (0,j.cq)(a,N),E.ZP.success("Organization deleted successfully"),Z(!1),w(null),lT(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,j.H1)(a,e),C(!1),O.resetFields(),lT(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lO,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(eC.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(S.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(ek.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Organization ID"}),(0,r.jsx)(eb.Z,{children:"Organization Name"}),(0,r.jsx)(eb.Z,{children:"Created"}),(0,r.jsx)(eb.Z,{children:"Spend (USD)"}),(0,r.jsx)(eb.Z,{children:"Budget (USD)"}),(0,r.jsx)(eb.Z,{children:"Models"}),(0,r.jsx)(eb.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(eb.Z,{children:"Info"}),(0,r.jsx)(eb.Z,{children:"Actions"})]})}),(0,r.jsx)(e_.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(z.Z,{title:e.organization_id,children:(0,r.jsxs)(y.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(ev.Z,{children:e.organization_alias}),(0,r.jsx)(ev.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(ev.Z,{children:e.spend}),(0,r.jsx)(ev.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(ev.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(eS.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(R(e).slice(0,30),"..."):R(e)},l))})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(S.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(ev.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,r.jsx)(e8.Z,{onClick:()=>T(e.organization_id),icon:eM.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(_.Z,{numColSpan:1,children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>C(!0),children:"+ Create New Organization"}),(0,r.jsx)(P.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{C(!1),O.resetFields()},children:(0,r.jsxs)(A.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(I.default.Option,{value:e,children:R(e)},e))]})}),(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(M.Z,{step:1,width:400})}),(0,r.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(L.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(y.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),f?(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 Organization"}),(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 organization?"})})]})})}),(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)(y.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(y.Z,{onClick:()=>{Z(!1),w(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(S.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lL=s(94789);let lD={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lR={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lF=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lR[e];return l?l.fields.map(e=>(0,r.jsx)(A.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(L.Z.Password,{}):(0,r.jsx)(b.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(P.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(A.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(I.default,{children:Object.entries(lD).map(e=>{let[l,s]=e;return(0,r.jsx)(I.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(A.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(b.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(P.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(S.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(S.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)(T.ZP,{onClick:n,children:"Done"})})]})]})};let lU=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lz=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=A.Z.useForm(),[d]=A.Z.useForm(),{Title:c,Paragraph:m}=G.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[_,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[I,O]=(0,i.useState)(!1),[M,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,J]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lU(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){E.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,j.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),E.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,j.eH)(s,e.ip);let l=await (0,j.PT)(s);B(l),E.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),E.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{J(e),q(!0)},et=async()=>{if(H&&s)try{await (0,j.$I)(s,H);let e=await (0,j.PT)(s);B(e.length>0?e:[X]),E.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),E.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),J(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,j.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,j.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,j.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;E.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,j.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,j.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lR[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,j.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(v.Z,{children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:()=>!0===a?O(!0):E.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(y.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lF,{isAddSSOModalVisible:I,isInstructionsModalVisible:M,handleAddSSOOk:()=>{O(!1),o.resetFields()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),O(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(P.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(y.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"IP Address"}),(0,r.jsx)(eb.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:K.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e}),(0,r.jsx)(ev.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(y.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(P.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(A.Z,{onFinish:el,children:[(0,r.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(L.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(A.Z.Item,{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(P.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(y.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(y.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lL.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lV=s(92858),lq=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=A.Z.useForm();return(0,r.jsxs)(A.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{align:"center",children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(A.Z.Item,{name:e.field_name,children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(ev.Z,{children:"Integer"===e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lV.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(L.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lK=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,j.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lq,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,j.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.jA)(l,"alerting",["slack"]):(0,j.jA)(l,"alerting",[])),E.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lB=s(86582);let{Title:lH,Paragraph:lJ}=G.default;console.log=function(){};var lG=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=A.Z.useForm(),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[_,Z]=(0,i.useState)(""),[N,w]=(0,i.useState)({}),[k,C]=(0,i.useState)([]),[O,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),H=e=>{k.includes(e)?C(k.filter(l=>l!==e)):C([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),C(e.active_alerts),Z(s),w(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,j.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,j.K_)(l,{environment_variables:s}),E.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,j.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),E.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){E.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eC.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(eC.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(eC.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(v.Z,{numItems:2,children:(0,r.jsx)(ek.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(eb.Z,{children:"Callback Name"})})}),(0,r.jsx)(e_.Z,{children:n.map((e,s)=>(0,r.jsxs)(eZ.Z,{className:"flex justify-between",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.name})}),(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(S.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{}),(0,r.jsx)(eb.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)}):(0,r.jsx)(y.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lV.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>H(s)})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:t})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:_})})]},l)})})]}),(0,r.jsx)(y.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,j.K_)(l,s)}catch(e){E.ZP.error("Failed to update alerts: "+e,20)}E.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(lK,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(lH,{level:4,children:"Email Settings"}),(0,r.jsxs)(S.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(ev.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(v.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(S.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(S.Z,{className:"mt-2",children:l}),(0,r.jsx)(b.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(y.Z,{onClick:()=>(0,j.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(P.Z,{title:"Add Logging Callback",visible:O,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(A.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lB.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(I.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(J.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lB.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(b.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(P.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(A.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lB.Z,{label:l,name:l,children:(0,r.jsx)(b.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lW=s(92414),lY=s(46030);let{Option:l$}=I.default;var lX=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=A.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(P.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(A.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,j.K_)(s,{router_settings:o}),a(o)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(ew.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(J.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(A.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lW.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lQ=s(33619);async function l0(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lQ.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});E.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l1={ttl:3600,lowest_latency_buffer:0},l2=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(N.Z,{children:"latency-based-routing"==l?(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(S.Z,{children:"No specific settings"})})]})};var l4=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[w,C]=(0,i.useState)(null),I={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,j.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,j.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,j.K_)(l,{router_settings:t}),o(t),E.ZP.success("Router settings updated successfully")}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},T=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,j.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,j.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,j.K_)(l,{router_settings:s})}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eA.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eC.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(eC.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(eC.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(k.Z,{children:"Router Settings"}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"})]})}),(0,r.jsx)(e_.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[l]})]}),(0,r.jsx)(ev.Z,{children:"routing_strategy"==l?(0,r.jsxs)(ew.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(J.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(J.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(J.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(b.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l2,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l1,paramExplanation:I})]}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(y.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Model Name"}),(0,r.jsx)(eb.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(e_.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:t}),(0,r.jsx)(ev.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(y.Z,{onClick:()=>l0(t,l),children:"Test Fallback"})}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(lX,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Setting"}),(0,r.jsx)(eb.Z,{children:"Value"}),(0,r.jsx)(eb.Z,{children:"Status"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(S.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(ev.Z,{children:"Integer"==e.field_type?(0,r.jsx)(M.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(ev.Z,{children:!0==e.stored_in_db?(0,r.jsx)(eS.Z,{icon:et.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(eS.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(ev.Z,{children:[(0,r.jsx)(y.Z,{onClick:()=>T(e.field_name,l),children:"Update"}),(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l5=s(93142),l3=s(45246),l6=s(96473),l8=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l5.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(b.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(b.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l3.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(T.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l6.Z,{}),children:"Add Header"})]})};let{Option:l7}=I.default;var l9=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=A.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(y.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(P.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(A.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,j.Vt)(l,e),s(r)}catch(e){E.ZP.error("Failed to update router settings: "+e,20)}E.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(b.Z,{})}),(0,r.jsx)(A.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l8,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},se=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,j.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,j.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),E.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eI.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Path"}),(0,r.jsx)(eb.Z,{children:"Target"}),(0,r.jsx)(eb.Z,{children:"Headers"}),(0,r.jsx)(eb.Z,{children:"Action"})]})}),(0,r.jsx)(e_.Z,{children:n.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(S.Z,{children:e.path})}),(0,r.jsx)(ev.Z,{children:e.target}),(0,r.jsx)(ev.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)(e8.Z,{icon:eM.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l9,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=A.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call");let l=await (0,j.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),E.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(A.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ss=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=A.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{E.ZP.info("Making API Call"),t(!0);let l=await (0,j.qI)(s,e);a(e=>e?[...e,l]:[l]),E.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),E.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(P.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(A.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(A.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(b.Z,{placeholder:""})}),(0,r.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(M.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(w.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(N.Z,{children:[(0,r.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(M.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(T.ZP,{htmlType:"submit",children:"Save"})})]})})},st=s(17906),sa=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,j.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;E.ZP.info("Request made"),await (0,j.NV)(l,e);let t=[...c];t.splice(s,1),m(t),E.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,j.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(y.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(sl,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(ss,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(S.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Budget ID"}),(0,r.jsx)(eb.Z,{children:"Max Budget"}),(0,r.jsx)(eb.Z,{children:"TPM"}),(0,r.jsx)(eb.Z,{children:"RPM"})]})}),(0,r.jsx)(e_.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.budget_id}),(0,r.jsx)(ev.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(ev.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(ev.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e8.Z,{icon:e7.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e8.Z,{icon:eM.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(S.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(eC.Z,{children:"Test it (Curl)"}),(0,r.jsx)(eC.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sr=s(77398),si=s.n(sr),sn=s(20016);async function so(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let sd=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return so(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sc=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sm=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sc(l)})},su=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sm,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(z.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(sd,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(z.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:e0(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(z.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(z.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],sh=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,j.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sx=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sp=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sg=["Internal User","Internal Viewer"],sj=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sf(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(si()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(si()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sg.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&g(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sg.includes(o)&&q(!0)},[o]);let B=(0,sn.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=si()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?si()(S).utc().format("YYYY-MM-DD HH:mm:ss"):si()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,j.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await sh(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(si()(N).format("MMM D, h:mm A")," - ").concat(si()(S).format("MMM D, h:mm A"));let e=si()(),l=si()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>g(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),g(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(si()().format("YYYY-MM-DDTHH:mm")),w(si()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eN,{columns:su,data:H,renderSubComponent:s_,getRowCanExpand:()=>!0})]})]})}function s_(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sj,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sx,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var sv=s(92699),sy=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(S.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(eC.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eC.Z,{children:"LlamaIndex"}),(0,r.jsx)(eC.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(st.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sb=s(243),sZ=s(94263);async function sN(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lQ.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){E.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sw=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[w,k]=(0,i.useState)([]),C=(0,i.useRef)(null),A=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,j.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),f(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{A.current&&setTimeout(()=>{var e;null===(e=A.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){E.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{g&&await sN(i,(e,l)=>P("assistant",e,l),g,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=G.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)(v.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eC.Z,{children:"Chat"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"API Key Source"}),(0,r.jsx)(I.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(_.Z,{className:"mx-2",children:[(0,r.jsx)(S.Z,{children:"Select Model:"}),(0,r.jsx)(I.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),N("custom"===e)},options:[...w,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(b.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{f(e)},500)}})]})]}),(0,r.jsx)(y.Z,{onClick:()=>{p([]),E.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ef.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{})})}),(0,r.jsxs)(e_.Z,{children:[x.map((e,l)=>(0,r.jsx)(eZ.Z,{children:(0,r.jsxs)(ev.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sb.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(st.Z,{style:sZ.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{ref:A,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(b.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(y.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sS=s(19226),sk=s(45937),sC=s(92403),sI=s(28595),sA=s(68208),sE=s(9775),sP=s(41361),sO=s(37527),sT=s(12660),sM=s(88009),sL=s(48231),sD=s(41169),sR=s(44625),sF=s(57400),sU=s(55322);let{Sider:sz}=sS.default,sV=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sC.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sI.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sA.Z,{}),roles:sp},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sE.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sP.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sp},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sT.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sM.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sL.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sD.Z,{}),roles:sp,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sR.Z,{}),roles:sp},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sO.Z,{}),roles:sp},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sF.Z,{}),roles:sp}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sT.Z,{}),roles:sp},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sU.Z,{}),roles:sp},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sU.Z,{}),roles:sp}]}];var sq=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sV.find(l=>l.page===e);if(l)return l.key;for(let l of sV)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sV.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sS.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sz,{theme:"light",width:220,children:(0,r.jsx)(sk.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sK=s(40278),sB=s(96889),sH=s(97765);console.log=function(){};var sJ=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,j.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let g=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sG=s(69907),sW=s(53003),sY=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let s$=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var sX=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,j.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,j.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),w((await (0,j.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,j.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,j.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,j.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,j.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,j.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,j.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,j.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,j.b1)(l,null,void 0,void 0),f,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,j.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(l)try{let e=await (0,j.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),s$(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(S.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(y.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"mt-2",children:[(0,r.jsx)(eC.Z,{children:"All Up"}),s$(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eC.Z,{children:"Team Based Usage"}),(0,r.jsx)(eC.Z,{children:"Customer Usage"}),(0,r.jsx)(eC.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(eC.Z,{children:"Cost"}),(0,r.jsx)(eC.Z,{children:"Activity"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(S.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sJ,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Monthly Spend"}),(0,r.jsx)(sK.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top API Keys"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Top Models"}),(0,r.jsx)(sK.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(_.Z,{numColSpan:1}),(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sY.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Provider"}),(0,r.jsx)(eb.Z,{children:"Spend"})]})}),(0,r.jsx)(e_.Z,{children:T.map(e=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.provider}),(0,r.jsx)(ev.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"All Up"}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:e.model}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sG.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(sH.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sK.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(_.Z,{numColSpan:2,children:[(0,r.jsxs)(ek.Z,{className:"mb-2",children:[(0,r.jsx)(k.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sB.Z,{data:P})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sK.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(_.Z,{numColSpan:2})]})}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Time Range"}),(0,r.jsx)(sW.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(S.Z,{children:"Select Key"}),(0,r.jsxs)(ew.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(J.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(J.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(ek.Z,{className:"mt-4",children:(0,r.jsxs)(ef.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Customer"}),(0,r.jsx)(eb.Z,{children:"Spend"}),(0,r.jsx)(eb.Z,{children:"Total Events"})]})}),(0,r.jsx)(e_.Z,{children:null==g?void 0:g.map((e,l)=>{var s;return(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.end_user}),(0,r.jsx)(ev.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(ev.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(v.Z,{numItems:2,children:[(0,r.jsx)(_.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(_.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lY.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lW.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lY.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(J.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(v.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(_.Z,{numColSpan:2,children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)(k.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(S.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sK.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(_.Z,{numColSpan:2})]})]})]})]})})},sQ=s(51853);let s0=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s1=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s2=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sQ.Z,{className:"h-4 w-4"})})]})})})},s4=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s1(j.litellm_params)||{},_=s1(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s1(null==g?void 0:g.litellm_cache_params)||{},_=s1(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsxs)(eA.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(eC.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(et.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(es.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(S.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s2,{label:"Error Message",value:j.message}),(0,r.jsx)(s2,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s2,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s2,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s2,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s2,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s2,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s2,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s2,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s2,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s2,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eE.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s5=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(y.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(s0,{responseTimeMs:n})]}),s&&(0,r.jsx)(s4,{response:s})]})},s3=e=>{if(e)return e.toISOString().split("T")[0]};function s6(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s8=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,f]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[w,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[A,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&w&&((async()=>{p(await (0,j.zg)(l,s3(w.from),s3(w.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,j.zg)(l,s3(e),s3(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);f(s6(s)),b(s6(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,w,x]);let L=async()=>{try{E.ZP.info("Running cache health check..."),P("");let e=await (0,j.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eI.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eA.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eC.Z,{children:"Cache Analytics"}),(0,r.jsx)(eC.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(S.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e8.Z,{icon:eT.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eP.Z,{children:[(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(ek.Z,{children:[(0,r.jsxs)(v.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(lW.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lY.Z,{value:e,children:e},e))})}),(0,r.jsx)(_.Z,{children:(0,r.jsx)(sW.Z,{enableSelect:!0,value:w,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,r.jsxs)(ek.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sK.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sH.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sK.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s6,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)(s5,{accessToken:l,healthCheckResponse:A,runCachingHealthCheck:L})})]})]})},s7=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,j.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(S.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(eb.Z,{children:"Guardrail Name"}),(0,r.jsx)(eb.Z,{children:"Mode"}),(0,r.jsx)(eb.Z,{children:"Status"})]})}),(0,r.jsx)(e_.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eZ.Z,{children:[(0,r.jsx)(ev.Z,{children:e.guardrail_name}),(0,r.jsx)(ev.Z,{children:e.litellm_params.mode}),(0,r.jsx)(ev.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eZ.Z,{children:(0,r.jsx)(ev.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s9=new d.S;function te(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[_,v]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)([]),[w,S]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,C]=(0,i.useState)(!0),I=(0,n.useSearchParams)(),[A,E]=(0,i.useState)({data:[]}),[P,O]=(0,i.useState)(null),T=I.get("userID"),M=I.get("invitation_id"),[L,D]=(0,i.useState)(()=>I.get("page")||"api-keys"),[R,F]=(0,i.useState)(null);return(0,i.useEffect)(()=>{O((0,p.bW)())},[]),(0,i.useEffect)(()=>{if(!P)return;let e=(0,o.o)(P);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),F(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&D("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?C("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,j.K8)(e.auth_header_name)}},[P]),(0,i.useEffect)(()=>{R&&T&&e&&eu(T,e,R,N),R&&T&&e&&f(R,T,e,null,x),R&&lT(R,b)},[R,T,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s9,children:M?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(g,{userID:T,userRole:e,premiumUser:s,userEmail:m,setProxySettings:S,proxySettings:w}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sq,{setPage:e=>{let l=new URLSearchParams(I);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),D(e)},userRole:e,defaultSelectedKey:L})}),"api-keys"==L?(0,r.jsx)(e$,{userID:T,userRole:e,premiumUser:s,teams:h,keys:_,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:v,organizations:y}):"models"==L?(0,r.jsx)(lN,{userID:T,userRole:e,token:P,keys:_,accessToken:R,modelData:A,setModelData:E,premiumUser:s,teams:h}):"llm-playground"==L?(0,r.jsx)(sw,{userID:T,userRole:e,token:P,accessToken:R,disabledPersonalKeyCreation:a}):"users"==L?(0,r.jsx)(lI,{userID:T,userRole:e,token:P,keys:_,teams:h,accessToken:R,setKeys:v}):"teams"==L?(0,r.jsx)(lP,{teams:h,setTeams:x,searchParams:I,accessToken:R,userID:T,userRole:e,organizations:y}):"organizations"==L?(0,r.jsx)(lM,{organizations:y,setOrganizations:b,userModels:Z,accessToken:R,userRole:e,premiumUser:s}):"admin-panel"==L?(0,r.jsx)(lz,{setTeams:x,searchParams:I,accessToken:R,showSSOBanner:k,premiumUser:s}):"api_ref"==L?(0,r.jsx)(sy,{proxySettings:w}):"settings"==L?(0,r.jsx)(lG,{userID:T,userRole:e,accessToken:R,premiumUser:s}):"budgets"==L?(0,r.jsx)(sa,{accessToken:R}):"guardrails"==L?(0,r.jsx)(s7,{accessToken:R}):"general-settings"==L?(0,r.jsx)(l4,{userID:T,userRole:e,accessToken:R,modelData:A}):"model-hub"==L?(0,r.jsx)(sv.Z,{accessToken:R,publicPage:!1,premiumUser:s}):"caching"==L?(0,r.jsx)(s8,{userID:T,userRole:e,token:P,accessToken:R,premiumUser:s}):"pass-through-settings"==L?(0,r.jsx)(se,{userID:T,userRole:e,accessToken:R,modelData:A}):"logs"==L?(0,r.jsx)(sf,{userID:T,userRole:e,token:P,accessToken:R}):(0,r.jsx)(sX,{userID:T,userRole:e,token:P,accessToken:R,keys:_,premiumUser:s})]})]})})})}},3914:function(e,l,s){"use strict";function t(){let e=window.location.hostname,l=["/","/ui"],s=["Lax","Strict","None"],t=document.cookie.split("; "),a=/^token_\d+$/;t.map(e=>e.split("=")[0]).filter(e=>"token"===e||a.test(e)).forEach(t=>{l.forEach(l=>{document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,";"),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let a="None"===s?" Secure;":"";document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; SameSite=").concat(s,";").concat(a),document.cookie="".concat(t,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(a)})})}),console.log("After clearing cookies:",document.cookie)}function a(e){let l=Math.floor(Date.now()/1e3);document.cookie="".concat("token_".concat(l),"=").concat(e,"; path=/; domain=").concat(window.location.hostname,";")}function r(){if("undefined"==typeof document)return null;let e=/^token_(\d+)$/,l=document.cookie.split("; ").map(l=>{let s=l.split("="),t=s[0];if("token"===t)return null;let a=t.match(e);return a?{name:t,timestamp:parseInt(a[1],10),value:s.slice(1).join("=")}:null}).filter(e=>null!==e);return l.length>0?(l.sort((e,l)=>l.timestamp-e.timestamp),l[0].value):null}s.d(l,{bA:function(){return t},bW:function(){return r},uB:function(){return a}})}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js new file mode 100644 index 0000000000..1e9a200f47 --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/page-e28453cd004ff93c.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,92222))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return _}});var t=s(57437),a=s(2265),r=s(99376),i=s(20831),n=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(49566),h=s(96761),x=s(84566),p=s(19250),g=s(14474),j=s(13634),f=s(73002);function _(){let[e]=j.Z.useForm(),l=(0,r.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));l&&l.split("=")[1]}("token");let s=l.get("invitation_id"),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(""),[Z,N]=(0,a.useState)(""),[w,S]=(0,a.useState)(null),[k,C]=(0,a.useState)(""),[I,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),C(l);let s=e.token,t=(0,g.o)(s);A(s),console.log("decoded:",t),v(t.key),console.log("decoded user email:",t.user_email),N(t.user_email),S(t.user_id)})},[s]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tirer."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",_,"token:",I,"formValues:",e),_&&I&&(e.user_email=Z,w&&s&&(0,p.m_)(_,s,w,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:Z,defaultValue:Z,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},92222:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return s9}});var t,a,r=s(57437),i=s(2265),n=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(80795),h=s(15883),x=s(40428),p=e=>{let{userID:l,userRole:s,premiumUser:t,proxySettings:a}=e,i=(null==a?void 0:a.PROXY_LOGOUT_URL)||"",n=[{key:"1",label:(0,r.jsxs)("div",{className:"py-1",children:[(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",s]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,r.jsx)(h.Z,{})," ",l]}),(0,r.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(t)]})]})},{key:"2",label:(0,r.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=i},children:[(0,r.jsx)(x.Z,{})," Logout"]})}];return(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,r.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:n,style:{padding:"4px",marginTop:"4px"}},children:(0,r.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})},g=s(19250);let j=async(e,l,s,t,a)=>{let r;r="Admin"!=s&&"Admin Viewer"!=s?await (0,g.It)(e,(null==t?void 0:t.organization_id)||null,l):await (0,g.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var f=s(49804),_=s(67101),v=s(20831),y=s(49566),b=s(87452),Z=s(88829),N=s(72208),w=s(84264),S=s(96761),k=s(29233),C=s(52787),I=s(13634),A=s(41021),E=s(51369),P=s(29967),O=s(73002),T=s(20577),M=s(56632);let L=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,g.So)(s,e,l,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},D=e=>{if(e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},R=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var F=s(15424),U=s(98074);let z=(e,l)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===l.format,V=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},q=(e,l,s)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[s]||"Text input";return z(e,l)?"".concat(t,"\nMust be valid JSON format"):l.enum?"Select from available options\nAllowed values: ".concat(l.enum.join(", ")):t};var K=e=>{let{schemaComponent:l,excludedFields:s=[],form:t,overrideLabels:a={},overrideTooltips:n={},customValidation:o={},defaultValues:d={}}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null);(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.lP)()).components.schemas[l];if(!e)throw Error('Schema component "'.concat(l,'" not found'));m(e);let a={};Object.keys(e.properties).filter(e=>!s.includes(e)&&void 0!==d[e]).forEach(e=>{a[e]=d[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[l,t,s]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let l=e.anyOf.map(e=>e.type);if(l.includes("number")||l.includes("integer"))return"number";l.includes("string")}return"string"},p=(e,l)=>{var s;let t;let i=x(l),m=null==c?void 0:null===(s=c.required)||void 0===s?void 0:s.includes(e),u=a[e]||l.title||e,h=n[e]||l.description,p=[];m&&p.push({required:!0,message:"".concat(u," is required")}),o[e]&&p.push({validator:o[e]}),z(e,l)&&p.push({validator:async(e,l)=>{if(l&&!V(l))throw Error("Please enter valid JSON")}});let g=h?(0,r.jsxs)("span",{children:[u," ",(0,r.jsx)(U.Z,{title:h,children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}):u;return t=z(e,l)?(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):l.enum?(0,r.jsx)(C.default,{children:l.enum.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))}):"number"===i||"integer"===i?(0,r.jsx)(T.Z,{style:{width:"100%"},precision:"integer"===i?0:void 0}):"duration"===e?(0,r.jsx)(y.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,r.jsx)(y.Z,{placeholder:h||""}),(0,r.jsx)(I.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:d[e],help:(0,r.jsx)("div",{className:"text-xs text-gray-500",children:q(e,l,i)}),children:t},e)};return u?(0,r.jsxs)("div",{className:"text-red-500",children:["Error: ",u]}):(null==c?void 0:c.properties)?(0,r.jsx)("div",{children:Object.entries(c.properties).filter(e=>{let[l]=e;return!s.includes(l)}).map(e=>{let[l,s]=e;return p(l,s)})}):null},B=e=>{let{teams:l,value:s,onChange:t}=e;return(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search or select a team",value:s,onChange:t,filterOption:(e,l)=>{var s,t,a;return!!l&&((null===(a=l.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(s=t.props)||void 0===s?void 0:s.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==l?void 0:l.map(e=>(0,r.jsxs)(C.default.Option,{value:e.team_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},H=s(57365),J=s(93192);function G(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:i,Paragraph:n}=J.default,o=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,r.jsxs)(E.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(w.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(w.Z,{children:"Invitation Link"}),(0,r.jsx)(w.Z,{children:(0,r.jsx)(w.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(k.CopyToClipboard,{text:o(),onCopy:()=>A.ZP.success("Copied!"),children:(0,r.jsx)(v.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var W=s(30967),Y=s(28181),$=s(73879),X=s(3632),Q=s(15452),ee=s.n(Q),el=s(71157),es=s(44643),et=e=>{let{accessToken:l,teams:s,possibleUIRoles:t,onUsersCreated:a}=e,[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.g)(l);j(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),_(new URL("/",window.location.href).toString())},[l]);let y=async()=>{u(!0);let e=d.map(e=>({...e,status:"pending"}));c(e);let s=!1;for(let a=0;ae.trim())),e.models&&"string"==typeof e.models&&(e.models=e.models.split(",").map(e=>e.trim())),e.max_budget&&""!==e.max_budget.toString().trim()&&(e.max_budget=parseFloat(e.max_budget.toString()));let r=await (0,g.Ov)(l,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){s=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==p?void 0:p.SSO_ENABLED){let e=new URL("/ui",f).toString();c(l=>l.map((l,s)=>s===a?{...l,status:"success",key:r.key||r.user_id,invitation_link:e}:l))}else{let s=await (0,g.XO)(l,e),t=new URL("/ui?invitation_id=".concat(s.id),f).toString();c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),c(e=>e.map((e,l)=>l===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}catch(l){console.error("Caught error:",l);let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||String(l);c(l=>l.map((l,s)=>s===a?{...l,status:"failed",error:e}:l))}}u(!1),s&&a&&a()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>o(!0),children:"+ Bulk Invite Users"}),(0,r.jsx)(E.Z,{title:"Bulk Invite Users",visible:n,width:800,onCancel:()=>o(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,r.jsx)("div",{className:"flex flex-col",children:0===d.length?(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,r.jsxs)("div",{className:"ml-11 mb-6",children:[(0,r.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,r.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,r.jsx)("li",{children:"Download our CSV template"}),(0,r.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,r.jsx)("li",{children:"Save the file and upload it here"}),(0,r.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,r.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,r.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_email"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"user_role"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"teams"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:"models"}),(0,r.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=new Blob([ee().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),l=window.URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download="bulk_users_template.csv",document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(l)},size:"lg",className:"w-full md:w-auto",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,r.jsx)("div",{className:"ml-11",children:(0,r.jsx)(W.Z,{beforeUpload:e=>(x(null),ee().parse(e,{complete:e=>{let l=e.data[0],s=["user_email","user_role"].filter(e=>!l.includes(e));if(s.length>0){x("Your CSV is missing these required columns: ".concat(s.join(", "))),c([]);return}try{let s=e.data.slice(1).map((e,s)=>{var t,a,r,i,n,o;let d={user_email:(null===(t=e[l.indexOf("user_email")])||void 0===t?void 0:t.trim())||"",user_role:(null===(a=e[l.indexOf("user_role")])||void 0===a?void 0:a.trim())||"",teams:null===(r=e[l.indexOf("teams")])||void 0===r?void 0:r.trim(),max_budget:null===(i=e[l.indexOf("max_budget")])||void 0===i?void 0:i.trim(),budget_duration:null===(n=e[l.indexOf("budget_duration")])||void 0===n?void 0:n.trim(),models:null===(o=e[l.indexOf("models")])||void 0===o?void 0:o.trim(),rowNumber:s+2,isValid:!0,error:""},c=[];d.user_email||c.push("Email is required"),d.user_role||c.push("Role is required"),d.user_email&&!d.user_email.includes("@")&&c.push("Invalid email format");let m=["proxy_admin","proxy_admin_view_only","internal_user","internal_user_view_only"];return d.user_role&&!m.includes(d.user_role)&&c.push("Invalid role. Must be one of: ".concat(m.join(", "))),d.max_budget&&isNaN(parseFloat(d.max_budget.toString()))&&c.push("Max budget must be a number"),c.length>0&&(d.isValid=!1,d.error=c.join(", ")),d}),t=s.filter(e=>e.isValid);c(s),0===t.length?x("No valid users found in the CSV. Please check the errors below."):t.length{x("Failed to parse CSV file: ".concat(e.message)),c([])},header:!1}),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,r.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,r.jsx)(X.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,r.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,r.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,r.jsx)(v.Z,{size:"sm",children:"Browse files"})]})})})]}):(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center mb-4",children:[(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,r.jsx)("h3",{className:"text-lg font-medium",children:d.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,r.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,r.jsx)(w.Z,{className:"text-red-600 font-medium",children:h})}),(0,r.jsxs)("div",{className:"ml-11",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,r.jsx)("div",{className:"flex items-center",children:d.some(e=>"success"===e.status||"failed"===e.status)?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[d.filter(e=>"success"===e.status).length," Successful"]}),d.some(e=>"failed"===e.status)&&(0,r.jsxs)(w.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[d.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,r.jsxs)(w.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[d.filter(e=>e.isValid).length," of ",d.length," users valid"]})]})}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex space-x-3",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]})]}),d.some(e=>"success"===e.status)&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,r.jsxs)("div",{className:"flex items-start",children:[(0,r.jsx)("div",{className:"mr-3 mt-1",children:(0,r.jsx)(es.Z,{className:"h-5 w-5 text-blue-500"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,r.jsxs)(w.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,r.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,r.jsx)(Y.Z,{dataSource:d,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,l)=>l.isValid?l.status&&"pending"!==l.status?"success"===l.status?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,r.jsx)("span",{className:"text-green-500",children:"Success"})]}),l.invitation_link&&(0,r.jsx)("div",{className:"mt-1",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:l.invitation_link}),(0,r.jsx)(k.CopyToClipboard,{text:l.invitation_link,onCopy:()=>A.ZP.success("Invitation link copied!"),children:(0,r.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Failed"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(l.error)})]}):(0,r.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),l.error&&(0,r.jsx)("span",{className:"text-sm text-red-500 ml-7",children:l.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,r.jsx)(v.Z,{onClick:y,disabled:0===d.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(d.filter(e=>e.isValid).length," Users")})]}),d.some(e=>"success"===e.status||"failed"===e.status)&&(0,r.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,r.jsx)(v.Z,{onClick:()=>{c([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,r.jsxs)(v.Z,{onClick:()=>{let e=d.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),l=new Blob([ee().unparse(e)],{type:"text/csv"}),s=window.URL.createObjectURL(l),t=document.createElement("a");t.href=s,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},variant:"primary",className:"flex items-center",children:[(0,r.jsx)($.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:ea}=C.default;var er=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a,onUserCreated:o,isEmbedded:d=!1}=e,[c,m]=(0,i.useState)(null),[u]=I.Z.useForm(),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(null),[f,_]=(0,i.useState)([]),[k,P]=(0,i.useState)(!1),[T,L]=(0,i.useState)(null),R=(0,n.useRouter)(),[z,V]=(0,i.useState)("http://localhost:4000");(0,i.useEffect)(()=>{(async()=>{try{let e=await (0,g.So)(s,l,"any"),t=[];for(let l=0;l{R&&V(new URL("/",window.location.href).toString())},[R]);let q=async e=>{var t,a,r;try{A.ZP.info("Making API Call"),d||x(!0),e.models&&0!==e.models.length||(e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,g.Ov)(s,null,e);console.log("user create Response:",a),j(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(o&&d){o(r),u.resetFields();return}if(null==c?void 0:c.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};L(e),P(!0)}else(0,g.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,L(e),P(!0)});A.ZP.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+l)}catch(l){let e=(null===(r=l.response)||void 0===r?void 0:null===(a=r.data)||void 0===a?void 0:a.detail)||(null==l?void 0:l.message)||"Error creating the user";A.ZP.error(e),console.error("Error creating the user:",l)}};return d?(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{className:"mx-auto mb-0",onClick:()=>x(!0),children:"+ Invite User"}),(0,r.jsx)(et,{accessToken:s,teams:t,possibleUIRoles:a}),(0,r.jsxs)(E.Z,{title:"Invite User",visible:h,width:800,footer:null,onOk:()=>{x(!1),u.resetFields()},onCancel:()=>{x(!1),j(null),u.resetFields()},children:[(0,r.jsx)(w.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(I.Z,{form:u,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Global Proxy Role"," ",(0,r.jsx)(U.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,r.jsx)(F.Z,{})})]}),name:"user_role",children:(0,r.jsx)(C.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,r.jsx)(C.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(ea,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(ea,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(I.Z.Item,{className:"gap-2",label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Models user has access to, outside of team scope.",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),f.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create User"})})]})]}),p&&(0,r.jsx)(G,{isInvitationLinkModalVisible:k,setIsInvitationLinkModalVisible:P,baseUrl:z,invitationLinkData:T})]})},ei=s(7310),en=s.n(ei);let{Option:eo}=C.default,ed=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s},ec=(e,l)=>R(e&&e.models.length>0?e.models.includes("all-proxy-models")?l:e.models:l,l),em=async(e,l,s,t)=>{try{if(null===e||null===l)return;if(null!==s){let a=(await (0,g.So)(s,e,l)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eu=e=>{let{userID:l,team:s,teams:t,userRole:a,accessToken:n,data:o,setData:d}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(null),[L,R]=(0,i.useState)([]),[z,V]=(0,i.useState)([]),[q,H]=(0,i.useState)("you"),[J,G]=(0,i.useState)(ed(o)),[W,Y]=(0,i.useState)([]),[$,X]=(0,i.useState)(s),[Q,ee]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),[et,ea]=(0,i.useState)({}),[ei,eu]=(0,i.useState)([]),[eh,ex]=(0,i.useState)(!1),ep=()=>{u(!1),c.resetFields()},eg=()=>{u(!1),x(null),c.resetFields()};(0,i.useEffect)(()=>{l&&a&&n&&em(l,a,n,R)},[n,l,a]),(0,i.useEffect)(()=>{(async()=>{try{let e=(await (0,g.t3)(n)).guardrails.map(e=>e.guardrail_name);Y(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[n]),(0,i.useEffect)(()=>{(async()=>{try{if(n){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,g.lg)(n);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[n]);let ej=async e=>{try{var s,t,a;let r=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",i=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==o?void 0:o.filter(e=>e.team_id===i).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(r))throw Error("Key alias ".concat(r," already exists for team with ID ").concat(i,", please provide another key alias"));if(A.ZP.info("Making API Call"),u(!0),"you"===q&&(e.user_id=l),"service_account"===q){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let m=await (0,g.wX)(n,l,e);console.log("key create Response:",m),d(e=>e?[...e,m]:[m]),x(m.key),j(m.soft_budget),A.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),A.ZP.error("Error creating the key: ".concat(e))}};(0,i.useEffect)(()=>{V(ec($,L)),c.setFieldValue("models",[])},[$,L]);let ef=async e=>{if(!e){eu([]);return}ex(!0);try{let l=new URLSearchParams;if(l.append("user_email",e),null==n)return;let s=(await (0,g.u5)(n,l)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eu(s)}catch(e){console.error("Error fetching users:",e),A.ZP.error("Failed to search for users")}finally{ex(!1)}},e_=(0,i.useCallback)(en()(e=>ef(e),300),[n]),ev=(e,l)=>{let s=l.user;c.setFieldsValue({user_id:s.user_id})};return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,r.jsx)(E.Z,{visible:m,width:1e3,footer:null,onOk:ep,onCancel:eg,children:(0,r.jsxs)(I.Z,{form:c,onFinish:ej,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Owned By"," ",(0,r.jsx)(U.Z,{title:"Select who will own this API key",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,r.jsxs)(P.ZP.Group,{onChange:e=>H(e.target.value),value:q,children:[(0,r.jsx)(P.ZP,{value:"you",children:"You"}),(0,r.jsx)(P.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,r.jsx)(P.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===q&&(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["User ID"," ",(0,r.jsx)(U.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===q,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{e_(e)},onSelect:(e,l)=>ev(e,l),options:ei,loading:eh,allowClear:!0,style:{width:"100%"},notFoundContent:eh?"Searching...":"No users found"}),(0,r.jsx)(O.ZP,{onClick:()=>ee(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,r.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Team"," ",(0,r.jsx)(U.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:s?s.team_id:null,className:"mt-4",children:(0,r.jsx)(B,{teams:t,onChange:e=>{X((null==t?void 0:t.find(l=>l.team_id===e))||null)}})})]}),(0,r.jsxs)("div",{className:"mb-8",children:[(0,r.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["you"===q||"another_user"===q?"Key Name":"Service Account ID"," ",(0,r.jsx)(U.Z,{title:"you"===q||"another_user"===q?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===q?"key name":"service account ID")}],help:"required",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),z.map(e=>(0,r.jsx)(eo,{value:e,children:D(e)},e))]})})]}),(0,r.jsx)("div",{className:"mb-8",children:(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Max Budget (USD)"," ",(0,r.jsx)(U.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Reset Budget"," ",(0,r.jsx)(U.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{className:"mt-4",label:(0,r.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,r.jsx)(U.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Expire Key"," ",(0,r.jsx)(U.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,r.jsx)(y.Z,{placeholder:"e.g., 30d"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:W.map(e=>({value:e,label:e}))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Metadata"," ",(0,r.jsx)(U.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Tags"," ",(0,r.jsx)(U.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),(0,r.jsxs)(b.Z,{className:"mt-4 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("b",{children:"Advanced Settings"}),(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,r.jsx)("a",{href:g.H2?"".concat(g.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,r.jsx)(F.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,r.jsx)(Z.Z,{children:(0,r.jsx)(K,{schemaComponent:"GenerateKeyRequest",form:c,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Key"})})]})}),Q&&(0,r.jsx)(E.Z,{title:"Create New User",visible:Q,onCancel:()=>ee(!1),footer:null,width:800,children:(0,r.jsx)(er,{userID:l,accessToken:n,teams:t,possibleUIRoles:et,onUserCreated:e=>{es(e),c.setFieldsValue({user_id:e}),ee(!1)},isEmbedded:!0})}),h&&(0,r.jsx)(E.Z,{visible:m,onOk:ep,onCancel:eg,footer:null,children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Save your Key"}),(0,r.jsx)(f.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)(f.Z,{numColSpan:1,children:null!=h?(0,r.jsxs)("div",{children:[(0,r.jsx)(w.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:h})}),(0,r.jsx)(k.CopyToClipboard,{text:h,onCopy:()=>{A.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(w.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=s(7366),ex=e=>{let{selectedTeam:l,currentOrg:s,accessToken:t,currentPage:a=1}=e,[r,n]=(0,i.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(null),u=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!t){console.log("accessToken",t);return}d(!0);let a=await (0,g.OD)(t,(null==s?void 0:s.organization_id)||null,(null==l?void 0:l.team_id)||"",e.page||1,50);console.log("data",a),n(a),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,i.useEffect)(()=>{u(),console.log("selectedTeam",l,"currentOrg",s,"accessToken",t)},[l,s,t]),{keys:r.keys,isLoading:o,error:c,pagination:{currentPage:r.current_page,totalPages:r.total_pages,totalCount:r.total_count},refresh:u}},ep=s(71594),eg=s(24525),ej=s(21626),ef=s(97214),e_=s(28241),ev=s(58834),ey=s(69552),eb=s(71876);function eZ(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:n=!1}=e,o=(0,ep.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,eg.sC)(),getExpandedRowModel:(0,eg.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:n?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}var eN=s(27281),ew=s(41649),eS=s(12514),ek=s(12485),eC=s(18135),eI=s(35242),eA=s(29706),eE=s(77991),eP=s(10900),eO=s(23628),eT=s(74998);function eM(e){var l,s;let{keyData:t,onCancel:a,onSubmit:n,teams:o,accessToken:d,userID:c,userRole:m}=e,[u]=I.Z.useForm(),[h,x]=(0,i.useState)([]),p=ec(null==o?void 0:o.find(e=>e.team_id===t.team_id),h);(0,i.useEffect)(()=>{(async()=>{try{if(d&&c&&m){let e=(await (0,g.So)(d,c,m)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[]);let j={...t,budget_duration:(s=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[s]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(l=t.metadata)||void 0===l?void 0:l.guardrails)||[]};return(0,r.jsxs)(I.Z,{form:u,onFinish:n,initialValues:j,layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[p.length>0&&(0,r.jsx)(C.default.Option,{value:"all-team-models",children:"All Team Models"}),p.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"daily",children:"Daily"}),(0,r.jsx)(C.default.Option,{value:"weekly",children:"Weekly"}),(0,r.jsx)(C.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,r.jsx)(T.Z,{style:{width:"100%"},min:0})}),(0,r.jsx)(I.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,r.jsx)(M.Z.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,r.jsx)(I.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsx)(I.Z.Item,{name:"token",hidden:!0,children:(0,r.jsx)(M.Z,{})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(v.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]})}function eL(e){let{selectedToken:l,visible:s,onClose:t,accessToken:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s&&l&&n.setFieldsValue({key_alias:l.key_alias,max_budget:l.max_budget,tpm_limit:l.tpm_limit,rpm_limit:l.rpm_limit,duration:l.duration||""})},[s,l,n]),(0,i.useEffect)(()=>{s||(d(null),p(!1),n.resetFields())},[s,n]),(0,i.useEffect)(()=>{(null==c?void 0:c.duration)?h((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString()}catch(e){return null}})(c.duration)):h(null)},[null==c?void 0:c.duration]);let j=async()=>{if(l&&a){p(!0);try{let e=await n.validateFields(),s=await (0,g.s0)(a,l.token,e);d(s.key),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key"),p(!1)}}},b=()=>{d(null),p(!1),n.resetFields(),t()};return(0,r.jsx)(E.Z,{title:"Regenerate API Key",open:s,onCancel:b,footer:o?[(0,r.jsx)(v.Z,{onClick:b,children:"Close"},"close")]:[(0,r.jsx)(v.Z,{onClick:b,className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:j,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:o?(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:(null==l?void 0:l.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,r.jsx)("pre",{className:"break-words whitespace-normal",children:o})}),(0,r.jsx)(k.CopyToClipboard,{text:o,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,r.jsxs)(I.Z,{form:n,layout:"vertical",onValuesChange:e=>{"duration"in e&&m(l=>({...l,duration:e.duration}))},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==l?void 0:l.expires)?new Date(l.expires).toLocaleString():"Never"]}),u&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",u]})]})})}function eD(e){var l,s;let{keyId:t,onClose:a,keyData:n,accessToken:o,userID:d,userRole:c,teams:m}=e,[u,h]=(0,i.useState)(!1),[x]=I.Z.useForm(),[p,j]=(0,i.useState)(!1),[f,y]=(0,i.useState)(!1);if(!n)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(w.Z,{children:"Key not found"})]});let b=async e=>{try{var l,s;if(!o)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),A.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]),await (0,g.Nc)(o,e),A.ZP.success("Key updated successfully"),h(!1)}catch(e){A.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!o)return;await (0,g.I1)(o,n.token),A.ZP.success("Key deleted successfully"),a()}catch(e){console.error("Error deleting the key:",e),A.ZP.error("Failed to delete key")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{icon:eP.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,r.jsx)(S.Z,{children:n.key_alias||"API Key"}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:n.token})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(v.Z,{icon:eO.Z,variant:"secondary",onClick:()=>y(!0),className:"flex items-center",children:"Regenerate Key"}),(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>j(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,r.jsx)(eL,{selectedToken:n,visible:f,onClose:()=>y(!1),accessToken:o}),p&&(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)(v.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>j(!1),children:"Cancel"})]})]})]})}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Spend"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",Number(n.spend).toFixed(4)]}),(0,r.jsxs)(w.Z,{children:["of ",null!==n.max_budget?"$".concat(n.max_budget):"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Key Settings"}),!u&&(0,r.jsx)(v.Z,{variant:"light",onClick:()=>h(!0),children:"Edit Settings"})]}),u?(0,r.jsx)(eM,{keyData:n,onCancel:()=>h(!1),onSubmit:b,teams:m,accessToken:o,userID:d,userRole:c}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key ID"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.token})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Key Alias"}),(0,r.jsx)(w.Z,{children:n.key_alias||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Secret Key"}),(0,r.jsx)(w.Z,{className:"font-mono",children:n.key_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(w.Z,{children:n.team_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),(0,r.jsx)(w.Z,{children:n.organization_id||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created"}),(0,r.jsx)(w.Z,{children:new Date(n.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Expires"}),(0,r.jsx)(w.Z,{children:n.expires?new Date(n.expires).toLocaleString():"Never"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Spend"}),(0,r.jsxs)(w.Z,{children:["$",Number(n.spend).toFixed(4)," USD"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsx)(w.Z,{children:null!==n.max_budget?"$".concat(n.max_budget," USD"):"Unlimited"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:n.models&&n.models.length>0?n.models.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):(0,r.jsx)(w.Z,{children:"No models specified"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)(w.Z,{children:["TPM: ",null!==n.tpm_limit?n.tpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",null!==n.rpm_limit?n.rpm_limit:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",null!==n.max_parallel_requests?n.max_parallel_requests:"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model TPM Limits: ",(null===(l=n.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(n.metadata.model_tpm_limit):"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["Model RPM Limits: ",(null===(s=n.metadata)||void 0===s?void 0:s.model_rpm_limit)?JSON.stringify(n.metadata.model_rpm_limit):"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Metadata"}),(0,r.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(n.metadata,null,2)})]})]})]})})]})]})]})}var eR=s(87908),eF=s(82422),eU=s(2356),ez=s(44633),eV=s(86462),eq=s(3837),eK=e=>{var l;let{options:s,onApplyFilters:t,onResetFilters:a,initialValues:n={},buttonLabel:o="Filter"}=e,[d,c]=(0,i.useState)(!1),[m,h]=(0,i.useState)((null===(l=s[0])||void 0===l?void 0:l.name)||""),[x,p]=(0,i.useState)(n),[g,j]=(0,i.useState)(n),[f,_]=(0,i.useState)(!1),[y,b]=(0,i.useState)([]),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(""),k=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{let l=e.target;!k.current||k.current.contains(l)||l.closest(".ant-dropdown")||l.closest(".ant-select-dropdown")||c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let I=(0,i.useCallback)(en()(async(e,l)=>{if(e&&l.isSearchable&&l.searchFn){N(!0);try{let s=await l.searchFn(e);b(s)}catch(e){console.error("Error searching:",e),b([])}finally{N(!1)}}},300),[]),A=e=>{j(l=>({...l,[m]:e}))},E=()=>{let e={};s.forEach(l=>{e[l.name]=""}),j(e)},P=s.map(e=>({key:e.name,label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[m===e.name&&(0,r.jsx)(eF.Z,{className:"h-4 w-4 text-blue-600"}),e.label||e.name]})})),T=s.find(e=>e.name===m);return(0,r.jsxs)("div",{className:"relative",ref:k,children:[(0,r.jsx)(v.Z,{icon:eU.Z,onClick:()=>c(!d),variant:"secondary",size:"xs",className:"flex items-center pr-2",children:o}),d&&(0,r.jsx)(eS.Z,{className:"absolute left-0 mt-2 w-96 z-50 border border-gray-200 shadow-lg",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsx)(u.Z,{menu:{items:P,onClick:e=>{let{key:l}=e;h(l),_(!1),b([])}},onOpenChange:_,open:f,trigger:["click"],children:(0,r.jsxs)(O.ZP,{className:"min-w-32 text-left flex justify-between items-center",children:[(null==T?void 0:T.label)||m,f?(0,r.jsx)(ez.Z,{className:"h-4 w-4"}):(0,r.jsx)(eV.Z,{className:"h-4 w-4"})]})}),(null==T?void 0:T.isSearchable)?(0,r.jsx)(C.default,{showSearch:!0,placeholder:"Search ".concat(T.label||m,"..."),value:g[m]||void 0,onChange:e=>A(e),onSearch:e=>{S(e),I(e,T)},onInputKeyDown:e=>{"Enter"===e.key&&w&&(A(w),e.preventDefault())},filterOption:!1,className:"flex-1 w-full max-w-full truncate",loading:Z,options:y,allowClear:!0,notFoundContent:Z?(0,r.jsx)(eR.Z,{size:"small"}):(0,r.jsx)("div",{className:"p-2",children:w&&(0,r.jsxs)(O.ZP,{type:"link",className:"p-0 mt-1",onClick:()=>{A(w);let e=document.activeElement;e&&e.blur()},children:["Use “",w,"” as filter value"]})})}):(0,r.jsx)(M.Z,{placeholder:"Enter value...",value:g[m]||"",onChange:e=>A(e.target.value),className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",suffix:g[m]?(0,r.jsx)(eq.Z,{className:"h-4 w-4 cursor-pointer text-gray-400 hover:text-gray-500",onClick:e=>{e.stopPropagation(),A("")}}):null})]}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsx)(O.ZP,{onClick:()=>{E(),a(),c(!1)},children:"Reset"}),(0,r.jsx)(O.ZP,{onClick:()=>{p(g),t(g),c(!1)},children:"Apply Filters"})]})]})})]})};let eB=e=>async l=>e&&l.trim()?e.filter(e=>e.team_alias.toLowerCase().includes(l.toLowerCase())).map(e=>({label:"".concat(e.team_alias," (").concat(e.team_id.substring(0,8),"...)"),value:e.team_id})):[],eH=e=>async l=>{if(!e||!l.trim())return[];let s=[];return e.forEach(e=>{e.organization_alias&&e.organization_alias.toLowerCase().includes(l.toLowerCase())&&s.push({label:"".concat(e.organization_alias," (").concat(e.organization_id,")"),value:e.organization_id||""})}),s};function eJ(e){let{keys:l,isLoading:s=!1,pagination:t,onPageChange:a,pageSize:n=50,teams:o,selectedTeam:d,setSelectedTeam:c,accessToken:m,userID:u,userRole:h,organizations:x,setCurrentOrg:p}=e,[j,f]=(0,i.useState)(null),[_,y]=(0,i.useState)({"Team ID":"","Organization ID":""}),[b,Z]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(m){let e=l.map(e=>e.user_id).filter(e=>null!==e);(async()=>{Z((await (0,g.Of)(m,e,1,100)).users)})()}},[m,l]);let N=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):null}},{header:"Key ID",accessorKey:"token",cell:e=>(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.getValue(),children:(0,r.jsx)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>f(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Secret Key",accessorKey:"key_name",cell:e=>(0,r.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{header:"Team Alias",accessorKey:"team_id",cell:e=>{let{row:l,getValue:s}=e,t=s(),a=null==o?void 0:o.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{header:"Team ID",accessorKey:"team_id",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>(0,r.jsx)(U.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{header:"Organization ID",accessorKey:"organization_id",cell:e=>e.getValue()?e.renderValue():"-"},{header:"User Email",accessorKey:"user_id",cell:e=>{let l=e.getValue(),s=b.find(e=>e.user_id===l);return(null==s?void 0:s.user_email)?s.user_email:"-"}},{header:"User ID",accessorKey:"user_id",cell:e=>{let l=e.getValue();return l?(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{children:[l.slice(0,7),"..."]})}):"-"}},{header:"Created At",accessorKey:"created_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"-"}},{header:"Created By",accessorKey:"created_by",cell:e=>e.getValue()||"Unknown"},{header:"Expires",accessorKey:"expires",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleDateString():"Never"}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>Number(e.getValue()).toFixed(4)},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{header:"Budget Reset",accessorKey:"budget_reset_at",cell:e=>{let l=e.getValue();return l?new Date(l).toLocaleString():"Never"}},{header:"Models",accessorKey:"models",cell:e=>{let l=e.getValue();return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:l&&l.length>0?l.map((e,l)=>(0,r.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},l)):"-"})}},{header:"Rate Limits",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{children:["TPM: ",null!==s.tpm_limit?s.tpm_limit:"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",null!==s.rpm_limit?s.rpm_limit:"Unlimited"]})]})}}],w=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:eB(o)},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:eH(x)}];return(0,r.jsx)("div",{className:"w-full h-full overflow-hidden",children:j?(0,r.jsx)(eD,{keyId:j,onClose:()=>f(null),keyData:l.find(e=>e.token===j),accessToken:m,userID:u,userRole:h,teams:o}):(0,r.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between w-full mb-2",children:[(0,r.jsx)(eK,{options:w,onApplyFilters:e=>{if(y({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||""}),e["Team ID"]){let l=null==o?void 0:o.find(l=>l.team_id===e["Team ID"]);l&&c(l)}if(e["Organization ID"]){let l=null==x?void 0:x.find(l=>l.organization_id===e["Organization ID"]);l&&p(l)}},initialValues:_,onResetFilters:()=>{y({"Team ID":"","Organization ID":""}),c(null),p(null)}}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",s?"...":"".concat((t.currentPage-1)*n+1," - ").concat(Math.min(t.currentPage*n,t.totalCount))," of ",s?"...":t.totalCount," results"]}),(0,r.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",s?"...":t.currentPage," of ",s?"...":t.totalPages]}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage-1),disabled:s||1===t.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>a(t.currentPage+1),disabled:s||t.currentPage===t.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]}),(0,r.jsx)("div",{className:"h-[32rem] overflow-auto",children:(0,r.jsx)(eZ,{columns:N.filter(e=>"expander"!==e.id),data:l,isLoading:s,getRowCanExpand:()=>!1,renderSubComponent:()=>(0,r.jsx)(r.Fragment,{})})})]})})}console.log=function(){};var eG=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,setSelectedTeam:n,data:o,setData:d,teams:c,premiumUser:m,currentOrg:u,organizations:h,setCurrentOrg:x}=e,[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,C]=(0,i.useState)(null),[P,O]=(0,i.useState)(null),[M,D]=(0,i.useState)(null),[R,F]=(0,i.useState)((null==a?void 0:a.team_id)||""),[U,z]=(0,i.useState)("");(0,i.useEffect)(()=>{F((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:q,error:K,pagination:B,refresh:H}=ex({selectedTeam:a,currentOrg:u,accessToken:t}),[J,G]=(0,i.useState)(!1),[W,Y]=(0,i.useState)(!1),[$,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)([]),el=new Set,[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(!1),[ei,en]=(0,i.useState)(null),[eo,ed]=(0,i.useState)(null),[ec]=I.Z.useForm(),[em,eu]=(0,i.useState)(null),[ep,eg]=(0,i.useState)(el),[ej,ef]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",$),(null==eo?void 0:eo.duration)?eu((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,eh.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,eh.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,eh.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eo.duration)):eu(null),console.log("calculateNewExpiryTime:",em)},[$,null==eo?void 0:eo.duration]),(0,i.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await L(l,s,t);e&&ee(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]),(0,i.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,s)=>{let t=l.team_id;e.add(t)}),eg(e)}},[c]);let e_=async()=>{if(null!=N&&null!=o){try{await (0,g.I1)(t,N);let e=o.filter(e=>e.token!==N);d(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),C(null)}},ev=(e,l)=>{ed(s=>({...s,[e]:l}))},ey=async()=>{if(!m){A.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=$)try{let e=await ec.validateFields(),l=await (0,g.s0)(t,$.token,e);if(en(l.key),o){let s=o.map(s=>s.token===(null==$?void 0:$.token)?{...s,key_name:l.key_name,...e}:s);d(s)}er(!1),ec.resetFields(),A.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),A.ZP.error("Failed to regenerate API Key")}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eJ,{keys:V,isLoading:q,pagination:B,onPageChange:e=>{H({page:e})},pageSize:50,teams:c,selectedTeam:a,setSelectedTeam:n,accessToken:t,userID:l,userRole:s,organizations:h,setCurrentOrg:x}),b&&(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)(v.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),C(null)},children:"Cancel"})]})]})]})}),(0,r.jsx)(E.Z,{title:"Regenerate API Key",visible:ea,onCancel:()=>{er(!1),ec.resetFields()},footer:[(0,r.jsx)(v.Z,{onClick:()=>{er(!1),ec.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(v.Z,{onClick:ey,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,r.jsxs)(I.Z,{form:ec,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,r.jsx)(I.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(y.Z,{disabled:!0})}),(0,r.jsx)(I.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(T.Z,{style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==$?void 0:$.expires)!=null?new Date($.expires).toLocaleString():"Never"]}),em&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",em]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(v.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ei&&(0,r.jsx)(E.Z,{visible:!!ei,onCancel:()=>en(null),footer:[(0,r.jsx)(v.Z,{onClick:()=>en(null),children:"Close"},"close")],children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(S.Z,{children:"Regenerated Key"}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(w.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==$?void 0:$.key_alias)||"No alias set"})}),(0,r.jsx)(w.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ei})}),(0,r.jsx)(k.CopyToClipboard,{text:ei,onCopy:()=>A.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(v.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},eW=s(12011);console.log=function(){},console.log("isLocal:",!1);var eY=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:x,organizations:p}=e,[v,y]=(0,i.useState)(null),[b,Z]=(0,i.useState)(null),N=(0,n.useSearchParams)(),w=function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"),S=N.get("invitation_id"),[k,C]=(0,i.useState)(null),[I,A]=(0,i.useState)(null),[E,P]=(0,i.useState)([]),[O,T]=(0,i.useState)(null),[M,L]=(0,i.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,i.useEffect)(()=>{if(w){let e=(0,o.o)(w);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),C(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&k&&s&&!a&&!v){let e=sessionStorage.getItem("userModels"+l);e?P(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(b))),(async()=>{try{let e=await (0,g.g)(k);T(e);let t=await (0,g.Br)(k,l,s,!1,null,null);y(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(v))),(null==t?void 0:t.teams[0].keys)?h(t.keys.concat(t.teams.filter(e=>"Admin"===s||e.user_id===l).flatMap(e=>e.keys))):h(t.keys),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let a=(await (0,g.So)(k,l,s)).data.map(e=>e.id);console.log("available_model_names:",a),P(a),console.log("userModels:",E),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})(),j(k,l,s,b,u))}},[l,w,k,a,s]),(0,i.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(b),", accessToken: ").concat(k,", userID: ").concat(l,", userRole: ").concat(s)),k&&(console.log("fetching teams"),j(k,l,s,b,u))},[b]),(0,i.useEffect)(()=>{if(null!==a&&null!=M&&null!==M.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))M.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===M.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),A(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;A(e)}},[M]),null!=S)return(0,r.jsx)(eW.default,{});if(null==l||null==w){let e="/sso/key/generate";return document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Full URL:",e),window.location.href=e,null}if(null==k)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=J.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",M),(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(f.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,r.jsx)(eu,{userID:l,team:M,teams:t,userRole:s,accessToken:k,data:a,setData:h},M?M.team_id:null),(0,r.jsx)(eG,{userID:l,userRole:s,accessToken:k,selectedTeam:M||null,setSelectedTeam:L,data:a,setData:h,premiumUser:x,teams:t,currentOrg:b,setCurrentOrg:Z,organizations:p})]})})})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI";let e$={OpenAI:"openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai"},eX={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Foundry (Studio)":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg",AssemblyAI:"https://artificialanalysis.ai/img/logos/assemblyai_small.png"},eQ=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:eX[e],displayName:e}}let l=Object.keys(e$).find(l=>e$[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eX[s],displayName:s}},e0=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e1=(e,l)=>{console.log("Provider key: ".concat(e));let s=e$[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t},e2=async(e,l,s,t)=>{try{console.log("handling submit for formValues:",e);let a=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=e$[e.custom_llm_provider]+"/*";e.model_name=l,a.push({public_name:l,litellm_model:l}),e.model=l}for(let s of a){let t={},a={},r=s.public_name;for(let[l,r]of(t.model=s.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),t.model=s.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)t.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=e$[r];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("custom_model_name"===l)t.model=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 A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw A.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(t[l]=Number(r));continue}else t[l]=r}let i={model_name:r,litellm_params:t,model_info:a},n=await (0,g.kK)(l,i);console.log("response for model create call: ".concat(n.data))}t&&t(),s.resetFields()}catch(e){A.ZP.error("Failed to create model: "+e,10)}},e4=e=>{var l;return(null==e?void 0:null===(l=e.model_info)||void 0===l?void 0:l.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"},e5=async(e,l,s,t)=>{if(console.log("handleEditSubmit:",e),null==l)return;let a={},r=null;for(let[l,s]of(e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),Object.entries(e)))"model_id"!==l?a[l]=""===s?null:s:r=""===s?null:s;let i={litellm_params:Object.keys(a).length>0?a:void 0,model_info:void 0!==r?{id:r}:void 0};console.log("handleEditSubmit payload:",i);try{await (0,g.um)(l,i),A.ZP.success("Model updated successfully, restart server to see updates"),s(!1),t(null)}catch(e){console.log("Error occurred")}};var e3=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[i]=I.Z.useForm(),n={},o="",d="";if(t){var c,m;n={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),n.model_id=d)}return(0,r.jsx)(E.Z,{title:"Edit '"+o+"' LiteLLM Params",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(I.Z,{form:i,onFinish:a,initialValues:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"api_key",name:"api_key",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"custom_llm_provider",name:"custom_llm_provider",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"model",name:"model",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},e6=s(47323),e8=s(53410),e7=e=>{var l,s,t;let{visible:a,onCancel:n,onSubmit:o,initialData:d,mode:c,config:m}=e,[u]=I.Z.useForm();console.log("Initial Data:",d),(0,i.useEffect)(()=>{if(a){if("edit"===c&&d)u.setFieldsValue({...d,role:d.role||m.defaultRole});else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,d,c,u,m.defaultRole,m.roleOptions]);let h=async e=>{try{let l=Object.entries(e).reduce((e,l)=>{let[s,t]=l;return{...e,[s]:"string"==typeof t?t.trim():t}},{});o(l),u.resetFields(),A.ZP.success("Successfully ".concat("add"===c?"added":"updated"," member"))}catch(e){A.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var l;return(0,r.jsx)(C.default,{children:null===(l=e.options)||void 0===l?void 0:l.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,r.jsx)(E.Z,{title:m.title||("add"===c?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:n,children:(0,r.jsxs)(I.Z,{form:u,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),m.showEmail&&m.showUserId&&(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(w.Z,{children:"OR"})}),m.showUserId&&(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(M.Z,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"Role"}),"edit"===c&&d&&(0,r.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(s=d.role,(null===(t=m.roleOptions.find(e=>e.value===s))||void 0===t?void 0:t.label)||s),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsx)(C.default,{children:"edit"===c&&d?[...m.roleOptions.filter(e=>e.value===d.role),...m.roleOptions.filter(e=>e.value!==d.role)].map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:e.label},e.value))})}),null===(l=m.additionalFields)||void 0===l?void 0:l.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,r.jsxs)("div",{className:"text-right mt-6",children:[(0,r.jsx)(O.ZP,{onClick:n,className:"mr-2",children:"Cancel"}),(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"add"===c?"Add Member":"Save Changes"})]})]})})},e9=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a,title:n="Add Team Member",roles:o=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:d="user"}=e,[c]=I.Z.useForm(),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)("user_email"),f=async(e,l)=>{if(!e){u([]);return}x(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,g.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));u(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},_=(0,i.useCallback)(en()((e,l)=>f(e,l),300),[]),v=(e,l)=>{j(l),_(e,l)},y=(e,l)=>{let s=l.user;c.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:c.getFieldValue("role")})};return(0,r.jsx)(E.Z,{title:n,open:l,onCancel:()=>{c.resetFields(),u([]),s()},footer:null,width:800,children:(0,r.jsxs)(I.Z,{form:c,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:d},children:[(0,r.jsx)(I.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>v(e,"user_email"),onSelect:(e,l)=>y(e,l),options:"user_email"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(I.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(C.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>v(e,"user_id"),onSelect:(e,l)=>y(e,l),options:"user_id"===p?m:[],loading:h,allowClear:!0})}),(0,r.jsx)(I.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:d,children:o.map(e=>(0,r.jsx)(C.default.Option,{value:e.value,children:(0,r.jsxs)(U.Z,{title:e.description,children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(O.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},le=e=>{var l;let{teamId:s,onClose:t,accessToken:a,is_team_admin:n,is_proxy_admin:o,userModels:d,editTeam:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p,j]=(0,i.useState)(!1),[f]=I.Z.useForm(),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(null),[k,E]=(0,i.useState)(!1);console.log("userModels in team info",d);let P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.Xm)(a,s);u(e)}catch(e){A.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.cu)(a,s,l),A.ZP.success("Team member added successfully"),j(!1),f.resetFields(),L()}catch(e){A.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},z=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.sN)(a,s,l),A.ZP.success("Team member updated successfully"),b(!1),L()}catch(e){A.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},V=async e=>{try{if(null==a)return;await (0,g.Lp)(a,s,e),A.ZP.success("Team member removed successfully"),L()}catch(e){A.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},q=async e=>{try{var l;if(!a)return;let t={team_id:s,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...null==m?void 0:null===(l=m.team_info)||void 0===l?void 0:l.metadata,guardrails:e.guardrails||[]}};await (0,g.Gh)(a,t),A.ZP.success("Team settings updated successfully"),E(!1),L()}catch(e){A.ZP.error("Failed to update team settings"),console.error("Error updating team:",e)}};if(h)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==m?void 0:m.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:K}=m;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:K.team_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:K.team_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",K.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===K.max_budget?"Unlimited":"$".concat(K.max_budget)]}),K.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",K.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",K.rpm_limit||"Unlimited"]}),K.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",K.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"User Email"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:m.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{N(e),b(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>V(e),icon:eT.Z,size:"sm"})]})})]},l))})]})}),(0,r.jsx)(v.Z,{onClick:()=>j(!0),children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Team Settings"}),P&&!k&&(0,r.jsx)(v.Z,{onClick:()=>E(!0),children:"Edit Settings"})]}),k?(0,r.jsxs)(I.Z,{form:f,onFinish:q,initialValues:{...K,team_alias:K.team_alias,models:K.models,tpm_limit:K.tpm_limit,rpm_limit:K.rpm_limit,max_budget:K.max_budget,budget_duration:K.budget_duration,guardrails:(null===(l=K.metadata)||void 0===l?void 0:l.guardrails)||[],metadata:K.metadata?JSON.stringify(K.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(M.Z,{type:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:10})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>E(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team Name"}),(0,r.jsx)("div",{children:K.team_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"font-mono",children:K.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(K.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:K.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",K.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",K.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==K.max_budget?"$".concat(K.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",K.budget_duration||"Never"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(ew.Z,{color:K.blocked?"red":"green",children:K.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,r.jsx)(e7,{visible:y,onCancel:()=>b(!1),onSubmit:z,initialData:Z,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,r.jsx)(e9,{isVisible:p,onCancel:()=>j(!1),onSubmit:R,accessToken:a})]})},ll=s(30150);function ls(e){var l,s,t,a,n,o,d,c,m,u,h,x,p,j,f,b,Z,N,k,C;let{modelId:E,onClose:P,modelData:T,accessToken:M,userID:L,userRole:D,editModel:R,setEditModalVisible:F,setSelectedModel:U}=e,[z]=I.Z.useForm(),[V,q]=(0,i.useState)(T),[K,B]=(0,i.useState)(!1),[H,J]=(0,i.useState)(!1),[G,W]=(0,i.useState)(!1),[Y,$]=(0,i.useState)(!1),X="Admin"===D,Q=async e=>{try{if(!M)return;W(!0);let l={model_name:e.model_name,litellm_params:{...V.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6},model_info:{id:E}};await (0,g.um)(M,l),q({...V,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l.litellm_params}),A.ZP.success("Model settings updated successfully"),J(!1),$(!1)}catch(e){console.error("Error updating model:",e),A.ZP.error("Failed to update model settings")}finally{W(!1)}};if(!T)return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsx)(w.Z,{children:"Model not found"})]});let ee=async()=>{try{if(!M)return;await (0,g.Og)(M,E),A.ZP.success("Model deleted successfully"),P()}catch(e){console.error("Error deleting the model:",e),A.ZP.error("Failed to delete model")}};return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(eP.Z,{}),onClick:P,className:"mb-4",children:"Back to Models"}),(0,r.jsxs)(S.Z,{children:["Public Model Name: ",e4(T)]}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),X&&(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(v.Z,{icon:eT.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete Model"})})]}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mb-6",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Raw JSON"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Provider"}),(0,r.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,r.jsx)("img",{src:eQ(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,s=l.parentElement;if(s){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",s.replaceChild(e,l)}}}),(0,r.jsx)(S.Z,{children:T.provider||"Not Set"})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"LiteLLM Model"}),(0,r.jsx)("pre",{children:(0,r.jsx)(S.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Pricing"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,r.jsxs)(w.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,r.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Model Settings"}),X&&!Y&&(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Edit Model"})]}),(0,r.jsx)(I.Z,{form:z,onFinish:Q,initialValues:{model_name:V.model_name,litellm_model_name:V.litellm_model_name,api_base:null===(l=V.litellm_params)||void 0===l?void 0:l.api_base,custom_llm_provider:null===(s=V.litellm_params)||void 0===s?void 0:s.custom_llm_provider,organization:null===(t=V.litellm_params)||void 0===t?void 0:t.organization,tpm:null===(a=V.litellm_params)||void 0===a?void 0:a.tpm,rpm:null===(n=V.litellm_params)||void 0===n?void 0:n.rpm,max_retries:null===(o=V.litellm_params)||void 0===o?void 0:o.max_retries,timeout:null===(d=V.litellm_params)||void 0===d?void 0:d.timeout,stream_timeout:null===(c=V.litellm_params)||void 0===c?void 0:c.stream_timeout,input_cost:(null===(m=V.litellm_params)||void 0===m?void 0:m.input_cost_per_token)?1e6*V.litellm_params.input_cost_per_token:1e6*T.input_cost,output_cost:(null===(u=V.litellm_params)||void 0===u?void 0:u.output_cost_per_token)?1e6*V.litellm_params.output_cost_per_token:1e6*T.output_cost},layout:"vertical",onValuesChange:()=>J(!0),children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"LiteLLM Model Name"}),Y?(0,r.jsx)(I.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter LiteLLM model name"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:V.litellm_model_name})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"input_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter input cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(h=V.litellm_params)||void 0===h?void 0:h.input_cost_per_token)?(1e6*V.litellm_params.input_cost_per_token).toFixed(4):1e6*T.input_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),Y?(0,r.jsx)(I.Z.Item,{name:"output_cost",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter output cost"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(x=V.litellm_params)||void 0===x?void 0:x.output_cost_per_token)?(1e6*V.litellm_params.output_cost_per_token).toFixed(4):1e6*T.output_cost})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"API Base"}),Y?(0,r.jsx)(I.Z.Item,{name:"api_base",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter API base"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=V.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Custom LLM Provider"}),Y?(0,r.jsx)(I.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom LLM provider"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=V.litellm_params)||void 0===j?void 0:j.custom_llm_provider)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization"}),Y?(0,r.jsx)(I.Z.Item,{name:"organization",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"Enter organization"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=V.litellm_params)||void 0===f?void 0:f.organization)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"tpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter TPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(b=V.litellm_params)||void 0===b?void 0:b.tpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),Y?(0,r.jsx)(I.Z.Item,{name:"rpm",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter RPM"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=V.litellm_params)||void 0===Z?void 0:Z.rpm)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Max Retries"}),Y?(0,r.jsx)(I.Z.Item,{name:"max_retries",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter max retries"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=V.litellm_params)||void 0===N?void 0:N.max_retries)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(k=V.litellm_params)||void 0===k?void 0:k.timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),Y?(0,r.jsx)(I.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,r.jsx)(ll.Z,{placeholder:"Enter stream timeout"})}):(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=V.litellm_params)||void 0===C?void 0:C.stream_timeout)||"Not Set"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),Y&&(0,r.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,r.jsx)(v.Z,{variant:"secondary",onClick:()=>{z.resetFields(),J(!1),$(!1)},children:"Cancel"}),(0,r.jsx)(v.Z,{variant:"primary",onClick:()=>z.submit(),loading:G,children:"Save Changes"})]})]})})]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),K&&(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 Model"}),(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 model?"})})]})})}),(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)(O.ZP,{onClick:ee,className:"ml-2",danger:!0,children:"Delete"}),(0,r.jsx)(O.ZP,{onClick:()=>B(!1),children:"Cancel"})]})]})]})})]})}var lt=s(67960),la=s(47451),lr=s(69410),li=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,i=I.Z.useFormInstance(),n=e=>{let l=e.target.value,s=(i.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:l,litellm_model:l}:e);i.setFieldsValue({model_mappings:s})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(I.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(I.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(y.Z,{placeholder:t(l)}):s.length>0?(0,r.jsx)(C.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let l=Array.isArray(e)?e:[e];if(l.includes("all-wildcard"))i.setFieldsValue({model_name:void 0,model_mappings:[]});else{let e=l.map(e=>({public_name:e,litellm_model:e}));i.setFieldsValue({model_mappings:e})}},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,r.jsx)(y.Z,{placeholder:t(l)})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e,s=l("model")||[];return(Array.isArray(s)?s:[s]).includes("custom")&&(0,r.jsx)(I.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(y.Z,{placeholder:"Enter custom model name",onChange:n})})}})]}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},ln=()=>{let e=I.Z.useFormInstance(),[l,s]=(0,i.useState)(0),t=I.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],n=I.Z.useWatch("custom_model_name",e),o=!a.includes("all-wildcard");if((0,i.useEffect)(()=>{if(n&&a.includes("custom")){let l=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:n,litellm_model:n}:e);e.setFieldValue("model_mappings",l),s(e=>e+1)}},[n,a,e]),(0,i.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let l=a.map(e=>"custom"===e&&n?{public_name:n,litellm_model:n}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",l),s(e=>e+1)}},[a,n,e]),!o)return null;let d=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(l,s,t)=>(0,r.jsx)(y.Z,{value:l,onChange:l=>{let s=[...e.getFieldValue("model_mappings")];s[t].public_name=l.target.value,e.setFieldValue("model_mappings",s)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,r.jsx)(Y.Z,{dataSource:e.getFieldValue("model_mappings"),columns:d,pagination:!1,size:"small"},l)}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};let{Link:lo}=J.default;var ld=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(I.Z.Item,{label:"OpenAI Organization ID",name:"organization",children:(0,r.jsx)(y.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(y.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(y.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(W.Z,{...s,children:(0,r.jsx)(O.ZP,{icon:(0,r.jsx)(X.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsx)(w.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),t===a.AssemblyAI&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsxs)(C.default,{placeholder:"Select API Base",children:[(0,r.jsx)(C.default.Option,{value:"https://api.assemblyai.com",children:"https://api.assemblyai.com"}),(0,r.jsx)(C.default.Option,{value:"https://api.eu.assemblyai.com",children:"https://api.eu.assemblyai.com"})]})}),(t===a.Azure||t===a.Azure_AI_Studio||t===a.OpenAI_Compatible)&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(y.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(y.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(I.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(y.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(la.Z,{children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(lo,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:""})}),(0,r.jsx)(I.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)(y.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(I.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(y.Z,{placeholder:"sk-",type:"password"})})]})},lc=s(63709),lm=s(90464);let{Link:lu}=J.default;var lh=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s,teams:t}=e,[a]=I.Z.useForm(),[n,o]=i.useState(!1),[d,c]=i.useState("per_token"),m=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),u=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(b.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(Z.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(I.Z.Item,{label:"Team",name:"team_id",className:"mb-4",children:(0,r.jsx)(B,{teams:t})}),(0,r.jsx)(I.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(lc.Z,{onChange:e=>{o(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),n&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(I.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(C.default,{defaultValue:"per_token",onChange:e=>c(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}):(0,r.jsx)(I.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:m}],className:"mb-4",children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)(I.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(lc.Z,{onChange:e=>{let l=a.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(l){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(I.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(la.Z,{className:"mb-4",children:[(0,r.jsx)(lr.Z,{span:10}),(0,r.jsx)(lr.Z,{span:10,children:(0,r.jsxs)(w.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(lu,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(I.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:u}],children:(0,r.jsx)(lm.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})};let{Title:lx,Link:lp}=J.default;var lg=e=>{let{form:l,handleOk:s,selectedProvider:t,setSelectedProvider:i,providerModels:n,setProviderModelsFn:o,getPlaceholder:d,uploadProps:c,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lx,{level:2,children:"Add new model"}),(0,r.jsx)(lt.Z,{children:(0,r.jsx)(I.Z,{form:l,onFinish:s,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.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)(C.default,{showSearch:!0,value:t,onChange:e=>{i(e),o(e),l.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eX[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(li,{selectedProvider:t,providerModels:n,getPlaceholder:d}),(0,r.jsx)(ln,{}),(0,r.jsx)(ld,{selectedProvider:t,uploadProps:c}),(0,r.jsx)(lh,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:h}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(U.Z,{title:"Get help on our github",children:(0,r.jsx)(J.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]})},lj=s(49084);function lf(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"model_info.created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No models found"})})})})})]})})})}let l_=(e,l,s,t,a,i,n)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>l(t.model_info.id),children:[t.model_info.id.slice(0,7),"..."]})})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:l}=e,s=t(l.original)||"-";return(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("p",{className:"text-xs",children:s.length>20?s.slice(0,20)+"...":s})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[s.provider&&(0,r.jsx)("img",{src:eQ(s.provider).logo,alt:"".concat(s.provider," logo"),className:"w-4 h-4",onError:e=>{let l=e.target,t=l.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=s.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,l)}}}),(0,r.jsx)("p",{className:"text-xs",children:s.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)(U.Z,{title:s.litellm_model_name,children:(0,r.jsx)("pre",{className:"text-xs",children:s.litellm_model_name?s.litellm_model_name.slice(0,20)+(s.litellm_model_name.length>20?"...":""):"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_at?new Date(s.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.updated_at?new Date(s.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("span",{className:"text-xs",children:s.model_info.created_by||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.input_cost||"-"})}},{header:()=>(0,r.jsx)(U.Z,{title:"Cost per 1M tokens",children:(0,r.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("pre",{className:"text-xs",children:s.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:l}=e,t=l.original;return t.model_info.team_id?(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:t.model_info.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>s(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:l}=e,s=l.original;return(0,r.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(s.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:s.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{l(t.model_info.id),n(!1)}})]})}}],{Title:lv,Link:ly}=J.default,lb={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lZ=e=>{let{accessToken:l,token:s,userRole:t,userID:n,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m,teams:u}=e,[h,x]=(0,i.useState)([]),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(""),[Z,N]=(0,i.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[k,C]=(0,i.useState)([]),[E,P]=(0,i.useState)(a.OpenAI),[O,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)([]),[K,B]=(0,i.useState)(null),[G,W]=(0,i.useState)([]),[Y,$]=(0,i.useState)([]),[X,Q]=(0,i.useState)([]),[ee,el]=(0,i.useState)([]),[es,et]=(0,i.useState)([]),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)([]),[eo,ed]=(0,i.useState)([]),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,i.useState)(null),[eg,ej]=(0,i.useState)(0),[ef,e_]=(0,i.useState)({}),[ev,ey]=(0,i.useState)([]),[eb,eZ]=(0,i.useState)(!1),[ew,eP]=(0,i.useState)(null),[eT,eM]=(0,i.useState)(null),[eL,eD]=(0,i.useState)([]),[eR,eF]=(0,i.useState)(!1),[eU,ez]=(0,i.useState)(null),[eV,eq]=(0,i.useState)(!1),[eK,eB]=(0,i.useState)(null),eH=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!n||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),B(e);let r=null==ew?void 0:ew.token;void 0===r&&(r=null);let i=eT;void 0===i&&(i=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,g.o6)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model metrics response:",o),$(o.data),Q(o.all_api_bases);let d=await (0,g.Rg)(l,e,s.toISOString(),a.toISOString());el(d.data),et(d.all_api_bases);let c=await (0,g.N8)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,g.fP)(l,n,t,e,s.toISOString(),a.toISOString(),r,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,g.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);e_(t);let r=await (0,g.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ey(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,i.useEffect)(()=>{eH(K,eu.from,eu.to)},[ew,eT]);let eJ=()=>{b(new Date().toLocaleString())},eG=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,g.K_)(l,{router_settings:{model_group_retry_policy:ex}}),A.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),A.ZP.error("Failed to save retry settings")}};if((0,i.useEffect)(()=>{if(!l||!s||!t||!n)return;let e=async()=>{try{var e,s,a,r,i,o,d,m,u,h,x,p;let j=await (0,g.hy)(l);C(j);let f=await (0,g.AZ)(l,n,t);console.log("Model data response:",f.data),c(f);let _=new Set;for(let e=0;e0&&(y=v[v.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",K);let b=await (0,g.o6)(l,n,t,y,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(s=eu.to)||void 0===s?void 0:s.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model metrics response:",b),$(b.data),Q(b.all_api_bases);let Z=await (0,g.Rg)(l,y,null===(a=eu.from)||void 0===a?void 0:a.toISOString(),null===(r=eu.to)||void 0===r?void 0:r.toISOString());el(Z.data),et(Z.all_api_bases);let N=await (0,g.N8)(l,n,t,y,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(o=eu.to)||void 0===o?void 0:o.toISOString(),null==ew?void 0:ew.token,eT);console.log("Model exceptions response:",N),er(N.data),en(N.exception_types);let w=await (0,g.fP)(l,n,t,y,null===(d=eu.from)||void 0===d?void 0:d.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eT),S=await (0,g.n$)(l,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);e_(S);let k=await (0,g.v9)(l,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],y);ey(k),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",k),console.log("slowResponses:",w),em(w);let I=await (0,g.j2)(l);eD(null==I?void 0:I.end_users);let A=(await (0,g.BL)(l,n,t)).router_settings;console.log("routerSettingsInfo:",A);let E=A.model_group_retry_policy,P=A.num_retries;console.log("model_group_retry_policy:",E),console.log("default_retries:",P),ep(E),ej(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&n&&e();let a=async()=>{let e=await (0,g.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==j&&a(),eJ()},[l,s,t,n,j,y]),!o||!l||!s||!t||!n)return(0,r.jsx)("div",{children:"Loading..."});let eW=[],eY=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(j)),null!=j&&"object"==typeof j&&e in j)?j[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(i=null==a?void 0:a.input_cost_per_token,n=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=i,o.data[e].output_cost=n,o.data[e].litellm_model_name=s,eY.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(e8=l.litellm_params)||void 0===e8?void 0:e8.api_base,o.data[e].cleanedLitellmParams=m,eW.push(l.model_name),console.log(o.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=J.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 e7=async()=>{try{A.ZP.info("Running health check..."),M("");let e=await (0,g.EY)(l);M(e)}catch(e){console.error("Error running health check:",e),M("Error running health check")}};w.Z,m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{eP(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>{eM(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{eP(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(H.Z,{value:String(l),disabled:!0,onClick:()=>{eP(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(w.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(H.Z,{value:"all-customers",onClick:()=>{eM(null)},children:"All Customers"},"all-customers"),null==eL?void 0:eL.map((e,l)=>(0,r.jsxs)(H.Z,{value:e,disabled:!0,onClick:()=>{eM(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]}),console.log("selectedProvider: ".concat(E)),console.log("providerModels.length: ".concat(Z.length));let e9=Object.keys(a).find(e=>a[e]===E);return(e9&&k.find(e=>e.name===e$[e9]),eK)?(0,r.jsx)("div",{className:"w-full h-full",children:(0,r.jsx)(le,{teamId:eK,onClose:()=>eB(null),accessToken:l,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:eW,editTeam:!1})}):(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:eU?(0,r.jsx)(ls,{modelId:eU,editModel:!0,onClose:()=>{ez(null),eq(!1)},modelData:o.data.find(e=>e.model_info.id===eU),accessToken:l,userID:n,userRole:t,setEditModalVisible:D,setSelectedModel:F}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"All Models"}),(0,r.jsx)(ek.Z,{children:"Add Model"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(ek.Z,{children:"Model Analytics"}),(0,r.jsx)(ek.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[y&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",y]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||void 0,onValueChange:e=>B("all"===e?"all":e),value:K||void 0,children:[(0,r.jsx)(H.Z,{value:"all",children:"All Models"}),U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))]})]}),(0,r.jsx)(lf,{columns:l_(m,ez,eB,e4,e=>{F(e),D(!0)},eJ,eq),data:o.data.filter(e=>"all"===K||e.model_name===K||!K),isLoading:!1})]}),(0,r.jsx)(e3,{visible:L,onCancel:()=>{D(!1),F(null)},model:R,onSubmit:e=>e5(e,l,D,F)})]}),(0,r.jsx)(eA.Z,{className:"h-full",children:(0,r.jsx)(lg,{form:p,handleOk:()=>{p.validateFields().then(e=>{e2(e,l,p,eJ)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:E,setSelectedProvider:P,providerModels:Z,setProviderModelsFn:e=>{let l=e1(e,j);N(l),console.log("providerModels: ".concat(l))},getPlaceholder:e0,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?A.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&A.ZP.error("".concat(e.file.name," file upload failed."))}},showAdvancedSettings:eR,setShowAdvancedSettings:eF,teams:u})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(v.Z,{onClick:e7,children:"Run `/health`"}),O&&(0,r.jsx)("pre",{children:JSON.stringify(O,null,2)})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(w.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(eN.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:K||U[0],value:K||U[0],onValueChange:e=>B(e),children:U.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>B(e),children:e},l))})]}),(0,r.jsxs)(S.Z,{children:["Retry Policy for ",K]}),(0,r.jsx)(w.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lb&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(lb).map((e,l)=>{var s;let[t,a]=e,i=null==ex?void 0:null===(s=ex[K])||void 0===s?void 0:s[a];return null==i&&(i=eg),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(T.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{ep(l=>{var s;let t=null!==(s=null==l?void 0:l[K])&&void 0!==s?s:{};return{...null!=l?l:{},[K]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(v.Z,{className:"mt-6 mr-8",onClick:eG,children:"Save"})]})]})]})})},lN=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:n}=e,[o,d]=(0,i.useState)(a),[c]=I.Z.useForm();(0,i.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{n(e),c.resetFields(),t()};return a?(0,r.jsx)(E.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(I.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(C.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(H.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(I.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)(I.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(T.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lw=s(15731);let lS=(e,l,s)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)(U.Z,{title:l.original.user_id,children:(0,r.jsx)("span",{className:"text-xs",children:l.original.user_id?"".concat(l.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:l=>{var s;let{row:t}=l;return(0,r.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(s=e[t.original.user_role])||void 0===s?void 0:s.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.spend?l.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.max_budget?l.original.max_budget:"Unlimited"})}},{header:()=>(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{children:"SSO ID"}),(0,r.jsx)(U.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,r.jsx)(lw.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:null!==l.original.sso_user_id?l.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:l}=e;return(0,r.jsx)(_.Z,{numItems:2,children:l.original.key_count>0?(0,r.jsxs)(ew.Z,{size:"xs",color:"indigo",children:[l.original.key_count," Keys"]}):(0,r.jsx)(ew.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.created_at?new Date(l.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:l}=e;return(0,r.jsx)("span",{className:"text-xs",children:l.original.updated_at?new Date(l.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>l(t.original)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>s(t.original.user_id)})]})}}];function lk(e){let{data:l=[],columns:s,isLoading:t=!1}=e,[a,n]=i.useState([{id:"created_at",desc:!0}]),o=(0,ep.b7)({data:l,columns:s,state:{sorting:a},onSortingChange:n,getCoreRowModel:(0,eg.sC)(),getSortedRowModel:(0,eg.tj)(),enableSorting:!0});return(0,r.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(ej.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,r.jsx)(ev.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(eb.Z,{children:e.headers.map(e=>(0,r.jsx)(ey.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,ep.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,r.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,r.jsx)(ez.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,r.jsx)(eV.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,r.jsx)(lj.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,r.jsx)(ef.Z,{children:t?(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):l.length>0?o.getRowModel().rows.map(e=>(0,r.jsx)(eb.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,r.jsx)(e_.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,ep.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:s.length,className:"h-8 text-center",children:(0,r.jsx)("div",{className:"text-center text-gray-500",children:(0,r.jsx)("p",{children:"No users found"})})})})})]})})})}console.log=function(){};var lC=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:n,teams:o,setKeys:d}=e,[c,m]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(1),[_,y]=i.useState(null),[b,Z]=(0,i.useState)(null),[N,w]=(0,i.useState)(!1),[S,k]=(0,i.useState)(null),[C,I]=(0,i.useState)(!1),[E,P]=(0,i.useState)(null),[O,T]=(0,i.useState)({}),[M,L]=(0,i.useState)("");window.addEventListener("beforeunload",function(){sessionStorage.clear()});let D=async()=>{if(E&&l)try{if(await (0,g.Eb)(l,[E]),A.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==E);h(e)}}catch(e){console.error("Error deleting user:",e),A.ZP.error("Failed to delete user")}I(!1),P(null)},R=async()=>{k(null),w(!1)},F=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&n){try{await (0,g.pf)(l,e,null),A.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),k(null),w(!1)}};if((0,i.useEffect)(()=>{if(!l||!s||!a||!n)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(j));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,g.Br)(l,null,a,!0,j,25);sessionStorage.setItem("userList_".concat(j),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)T(JSON.parse(s));else{let e=await (0,g.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),T(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&n&&e()},[l,s,a,n,j]),!u||!l||!s||!a||!n)return(0,r.jsx)("div",{children:"Loading..."});let U=lS(O,e=>{k(e),w(!0)},e=>{P(e),I(!0)});return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,r.jsx)("div",{className:"flex space-x-3",children:(0,r.jsx)(er,{userID:n,accessToken:l,teams:o,possibleUIRoles:O})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",c&&c.users&&c.users.length>0?(c.page-1)*c.page_size+1:0," ","-"," ",c&&c.users?Math.min(c.page*c.page_size,c.total):0," ","of ",c?c.total:0," results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:!c||j<=1,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",c?c.page:"-"," of"," ",c?c.total_pages:"-"]}),(0,r.jsx)("button",{onClick:()=>f(e=>e+1),disabled:!c||j>=c.total_pages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})})}),(0,r.jsx)(lk,{data:u||[],columns:U,isLoading:!u})]}),(0,r.jsx)(lN,{visible:N,possibleUIRoles:O,onCancel:R,user:S,onSubmit:F}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",E]})]})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(v.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})},lI=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,i.useState)([]);(0,i.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,g.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let n=async e=>{if(l&&s)try{await (0,g.cu)(l,e,{user_id:s,role:"user"}),A.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),A.ZP.error("Failed to join team")}};return(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Description"}),(0,r.jsx)(ey.Z,{children:"Members"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsxs)(ef.Z,{children:[t.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.team_alias})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.description||"No description available"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ew.Z,{size:"xs",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{size:"xs",variant:"secondary",onClick:()=>n(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(w.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lA=(e,l)=>{let s=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),s=e.models):s=l,R(s,l)};var lE=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:n,userRole:o,organizations:d}=e,[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{console.log("inside useeffect - ".concat(c)),t&&j(t,n,o,u,a),eP()},[c]);let[S]=I.Z.useForm(),[k]=I.Z.useForm(),{Title:P,Paragraph:R}=J.default,[z,V]=(0,i.useState)(""),[q,K]=(0,i.useState)(!1),[B,H]=(0,i.useState)(null),[G,W]=(0,i.useState)(null),[Y,$]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,el]=(0,i.useState)(!1),[es,et]=(0,i.useState)(!1),[ea,er]=(0,i.useState)([]),[ei,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)(null),[ec,em]=(0,i.useState)([]),[eu,eh]=(0,i.useState)({}),[ex,ep]=(0,i.useState)([]);(0,i.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lA(x,ea);console.log("models: ".concat(e)),em(e),S.setFieldValue("models",[])},[x,ea]),(0,i.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,g.t3)(t)).guardrails.map(e=>e.guardrail_name);ep(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let eg=async e=>{ed(e),en(!0)},eZ=async()=>{if(null!=eo&&null!=l&&null!=t){try{await (0,g.rs)(t,eo),j(t,n,o,u,a)}catch(e){console.error("Error deleting the team:",e)}en(!1),ed(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===t)return;let e=await L(n,o,t);e&&er(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,n,o,l]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,i=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],n=(null==e?void 0:e.organization_id)||(null==u?void 0:u.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));A.ZP.info("Creating Team");let o=await (0,g.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),A.ZP.success("Team created"),S.resetFields(),Q(!1)}}catch(e){console.error("Error creating the team:",e),A.ZP.error("Error creating the team: "+e,20)}},eP=()=>{m(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:G?(0,r.jsx)(le,{teamId:G,onClose:()=>{W(null),$(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;le.team_id===G)),is_proxy_admin:"Admin"==o,userModels:ea,editTeam:Y}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Your Teams"}),(0,r.jsx)(ek.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[c&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",c]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eP})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(w.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Team Name"}),(0,r.jsx)(ey.Z,{children:"Team ID"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"Organization"}),(0,r.jsx)(ey.Z,{children:"Info"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.filter(e=>!u||e.organization_id===u.organization_id).sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.team_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{W(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(w.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(w.Z,{children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)})},l))}):null}),(0,r.jsx)(e_.Z,{children:e.organization_id}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].keys&&eu[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(w.Z,{children:[eu&&e.team_id&&eu[e.team_id]&&eu[e.team_id].members_with_roles&&eu[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(e_.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{W(e.team_id),$(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>eg(e.team_id),icon:eT.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ei&&(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)(v.Z,{onClick:eZ,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{en(!1),ed(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o||"Org Admin"==o?(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>Q(!0),children:"+ Create New Team"}),(0,r.jsx)(E.Z,{title:"Create Team",visible:X,width:800,footer:null,onOk:()=>{Q(!1),S.resetFields()},onCancel:()=>{Q(!1),S.resetFields()},children:(0,r.jsxs)(I.Z,{form:S,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Organization"," ",(0,r.jsx)(U.Z,{title:(0,r.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:u?u.organization_id:null,className:"mt-8",children:(0,r.jsx)(C.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{S.setFieldValue("organization_id",e),p((null==d?void 0:d.find(l=>l.organization_id===e))||null)},filterOption:(e,l)=>{var s;return!!l&&((null===(s=l.children)||void 0===s?void 0:s.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==d?void 0:d.map(e=>(0,r.jsxs)(C.default.Option,{value:e.organization_id,children:[(0,r.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,r.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Models"," ",(0,r.jsx)(U.Z,{title:"These are the models that your selected organization has access to",children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ec.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,r.jsx)(y.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)(I.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(U.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(F.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(C.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ex.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lI,{accessToken:t,userID:n})})]})]})})},lP=e=>{var l;let{organizationId:s,onClose:t,accessToken:a,is_org_admin:n,is_proxy_admin:o,userModels:d,editOrg:c}=e,[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!0),[p]=I.Z.useForm(),[j,f]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[k,E]=(0,i.useState)(null),P=n||o,L=async()=>{try{if(x(!0),!a)return;let e=await (0,g.t$)(a,s);u(e)}catch(e){A.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{x(!1)}};(0,i.useEffect)(()=>{L()},[s,a]);let R=async e=>{try{if(null==a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.vh)(a,s,l),A.ZP.success("Organization member added successfully"),b(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},F=async e=>{try{if(!a)return;let l={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,g.LY)(a,s,l),A.ZP.success("Organization member updated successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},U=async e=>{try{if(!a)return;await (0,g.Sb)(a,s,e.user_id),A.ZP.success("Organization member deleted successfully"),N(!1),p.resetFields(),L()}catch(e){A.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},z=async e=>{try{if(!a)return;let l={organization_id:s,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,g.VA)(a,l),A.ZP.success("Organization settings updated successfully"),f(!1),L()}catch(e){A.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return h?(0,r.jsx)("div",{className:"p-4",children:"Loading..."}):m?(0,r.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(O.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,r.jsx)(S.Z,{children:m.organization_alias}),(0,r.jsx)(w.Z,{className:"text-gray-500 font-mono",children:m.organization_id})]})}),(0,r.jsxs)(eC.Z,{defaultIndex:c?2:0,children:[(0,r.jsxs)(eI.Z,{className:"mb-4",children:[(0,r.jsx)(ek.Z,{children:"Overview"}),(0,r.jsx)(ek.Z,{children:"Members"}),(0,r.jsx)(ek.Z,{children:"Settings"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Organization Details"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["Created: ",new Date(m.created_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Updated: ",new Date(m.updated_at).toLocaleDateString()]}),(0,r.jsxs)(w.Z,{children:["Created By: ",m.created_by]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(S.Z,{children:["$",m.spend.toFixed(6)]}),(0,r.jsxs)(w.Z,{children:["of ",null===m.litellm_budget_table.max_budget?"Unlimited":"$".concat(m.litellm_budget_table.max_budget)]}),m.litellm_budget_table.budget_duration&&(0,r.jsxs)(w.Z,{className:"text-gray-500",children:["Reset: ",m.litellm_budget_table.budget_duration]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(w.Z,{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)(w.Z,{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]}),m.litellm_budget_table.max_parallel_requests&&(0,r.jsxs)(w.Z,{children:["Max Parallel Requests: ",m.litellm_budget_table.max_parallel_requests]})]})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"User ID"}),(0,r.jsx)(ey.Z,{children:"Role"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Created At"}),(0,r.jsx)(ey.Z,{})]})}),(0,r.jsx)(ef.Z,{children:null===(l=m.members)||void 0===l?void 0:l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{className:"font-mono",children:e.user_role})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["$",e.spend.toFixed(6)]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,r.jsx)(e_.Z,{children:P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{E({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),N(!0)}}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>{U(e)}})]})})]},l))})]})}),P&&(0,r.jsx)(v.Z,{onClick:()=>{b(!0)},children:"Add Member"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(S.Z,{children:"Organization Settings"}),P&&!j&&(0,r.jsx)(v.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,r.jsxs)(I.Z,{form:p,onFinish:z,initialValues:{organization_alias:m.organization_alias,models:m.models,tpm_limit:m.litellm_budget_table.tpm_limit,rpm_limit:m.litellm_budget_table.rpm_limit,max_budget:m.litellm_budget_table.max_budget,budget_duration:m.litellm_budget_table.budget_duration,metadata:m.metadata?JSON.stringify(m.metadata,null,2):""},layout:"vertical",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(M.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),d.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,style:{width:"100%"}})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,r.jsx)(O.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,r.jsx)(v.Z,{type:"submit",children:"Save Changes"})]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization Name"}),(0,r.jsx)("div",{children:m.organization_alias})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Organization ID"}),(0,r.jsx)("div",{className:"font-mono",children:m.organization_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)("div",{children:new Date(m.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:m.models.map((e,l)=>(0,r.jsx)(ew.Z,{color:"red",children:e},l))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Rate Limits"}),(0,r.jsxs)("div",{children:["TPM: ",m.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,r.jsxs)("div",{children:["RPM: ",m.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"font-medium",children:"Budget"}),(0,r.jsxs)("div",{children:["Max: ",null!==m.litellm_budget_table.max_budget?"$".concat(m.litellm_budget_table.max_budget):"No Limit"]}),(0,r.jsxs)("div",{children:["Reset: ",m.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,r.jsx)(e9,{isVisible:y,onCancel:()=>b(!1),onSubmit:R,accessToken:a,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,r.jsx)(e7,{visible:Z,onCancel:()=>N(!1),onSubmit:F,initialData:k,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,r.jsx)("div",{className:"p-4",children:"Organization not found"})};let lO=async(e,l)=>{l(await (0,g.r6)(e))};var lT=e=>{let{organizations:l,userRole:s,userModels:t,accessToken:a,lastRefreshed:n,handleRefreshClick:o,currentOrg:d,guardrailsList:c=[],setOrganizations:m,premiumUser:u}=e,[h,x]=(0,i.useState)(null),[p,j]=(0,i.useState)(!1),[b,Z]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[k,P]=(0,i.useState)(!1),[O]=I.Z.useForm();(0,i.useEffect)(()=>{0===l.length&&a&&lO(a,m)},[l,a]);let L=e=>{e&&(S(e),Z(!0))},R=async()=>{if(N&&a)try{await (0,g.cq)(a,N),A.ZP.success("Organization deleted successfully"),Z(!1),S(null),lO(a,m)}catch(e){console.error("Error deleting organization:",e)}},F=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,g.H1)(a,e),P(!1),O.resetFields(),lO(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?h?(0,r.jsx)(lP,{organizationId:h,onClose:()=>{x(null),j(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===s,userModels:t,editOrg:p}):(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsx)("div",{className:"flex",children:(0,r.jsx)(ek.Z,{children:"Your Organizations"})}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[n&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",n]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:o})]})]}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(w.Z,{children:"Click on “Organization ID” to view organization details."}),(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(eS.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Organization ID"}),(0,r.jsx)(ey.Z,{children:"Organization Name"}),(0,r.jsx)(ey.Z,{children:"Created"}),(0,r.jsx)(ey.Z,{children:"Spend (USD)"}),(0,r.jsx)(ey.Z,{children:"Budget (USD)"}),(0,r.jsx)(ey.Z,{children:"Models"}),(0,r.jsx)(ey.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ey.Z,{children:"Info"}),(0,r.jsx)(ey.Z,{children:"Actions"})]})}),(0,r.jsx)(ef.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var l,t,a,i,n,o,d,c,m;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(U.Z,{title:e.organization_id,children:(0,r.jsxs)(v.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(l=e.organization_id)||void 0===l?void 0:l.slice(0,7),"..."]})})})}),(0,r.jsx)(e_.Z,{children:e.organization_alias}),(0,r.jsx)(e_.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(e_.Z,{children:e.spend}),(0,r.jsx)(e_.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)&&(0,r.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},l):(0,r.jsx)(ew.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(D(e).slice(0,30),"..."):D(e)},l))})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(o=e.litellm_budget_table)||void 0===o?void 0:o.tpm_limit:"Unlimited",(0,r.jsx)("br",{}),"RPM: ",(null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit)?null===(c=e.litellm_budget_table)||void 0===c?void 0:c.rpm_limit:"Unlimited"]})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(w.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,r.jsx)(e_.Z,{children:"Admin"===s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{x(e.organization_id),j(!0)}}),(0,r.jsx)(e6.Z,{onClick:()=>L(e.organization_id),icon:eT.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===s||"Org Admin"===s)&&(0,r.jsxs)(f.Z,{numColSpan:1,children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>P(!0),children:"+ Create New Organization"}),(0,r.jsx)(E.Z,{title:"Create Organization",visible:k,width:800,footer:null,onCancel:()=>{P(!1),O.resetFields()},children:(0,r.jsxs)(I.Z,{form:O,onFinish:F,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(I.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(C.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(C.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,r.jsx)(C.default.Option,{value:e,children:D(e)},e))]})}),(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(I.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(T.Z,{step:1,width:400})}),(0,r.jsx)(I.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(M.Z.TextArea,{rows:4})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(v.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),b?(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 Organization"}),(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 organization?"})})]})})}),(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)(v.Z,{onClick:R,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(v.Z,{onClick:()=>{Z(!1),S(null)},children:"Cancel"})]})]})]})}):(0,r.jsx)(r.Fragment,{})]}):(0,r.jsx)("div",{children:(0,r.jsxs)(w.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lM=s(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lR=e=>{let{isAddSSOModalVisible:l,isInstructionsModalVisible:s,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:i,handleInstructionsOk:n,handleInstructionsCancel:o,form:d}=e,c=e=>{let l=lD[e];return l?l.fields.map(e=>(0,r.jsx)(I.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,r.jsx)(M.Z.Password,{}):(0,r.jsx)(y.Z,{placeholder:e.placeholder})},e.name)):null};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.Z,{title:"Add SSO",visible:l,width:800,footer:null,onOk:t,onCancel:a,children:(0,r.jsxs)(I.Z,{form:d,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,r.jsx)(C.default,{children:Object.entries(lL).map(e=>{let[l,s]=e;return(0,r.jsx)(C.default.Option,{value:l,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[s&&(0,r.jsx)("img",{src:s,alt:l,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,r.jsxs)("span",{children:[l.charAt(0).toUpperCase()+l.slice(1)," SSO"]})]})},l)})})}),(0,r.jsx)(I.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.sso_provider!==l.sso_provider,children:e=>{let{getFieldValue:l}=e,s=l("sso_provider");return s?c(s):null}}),(0,r.jsx)(I.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(y.Z,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(E.Z,{title:"SSO Setup Instructions",visible:s,width:800,footer:null,onOk:n,onCancel:o,children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(w.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(w.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)(O.ZP,{onClick:n,children:"Done"})})]})]})};let lF=()=>{let[e,l]=(0,i.useState)("http://localhost:4000");return(0,i.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lU=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=I.Z.useForm(),[d]=I.Z.useForm(),{Title:c,Paragraph:m}=J.default,[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[Z,N]=(0,i.useState)(!1),[w,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[P,T]=(0,i.useState)(!1),[L,D]=(0,i.useState)(!1),[R,F]=(0,i.useState)(!1),[U,z]=(0,i.useState)(!1),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)([]),[H,G]=(0,i.useState)(null);(0,n.useRouter)();let[W,Y]=(0,i.useState)(null);console.log=function(){};let $=lF(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==a){A.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,g.PT)(s);B(e&&e.length>0?e:[X])}else B([X])}catch(e){console.error("Error fetching allowed IPs:",e),A.ZP.error("Failed to fetch allowed IPs ".concat(e)),B([X])}finally{!0===a&&F(!0)}},el=async e=>{try{if(s){await (0,g.eH)(s,e.ip);let l=await (0,g.PT)(s);B(l),A.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),A.ZP.error("Failed to add IP address ".concat(e))}finally{z(!1)}},es=async e=>{G(e),q(!0)},et=async()=>{if(H&&s)try{await (0,g.$I)(s,H);let e=await (0,g.PT)(s);B(e.length>0?e:[X]),A.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),A.ZP.error("Failed to delete IP address ".concat(e))}finally{q(!1),G(null)}};(0,i.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,g.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,g.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),p(e),Y(await (0,g.lg)(s))}})()},[s]);let ea=async e=>{try{if(null!=s&&null!=x){var l;A.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,g.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,g.XO)(s,a).then(e=>{f(e),b(!0)}),console.log("response for team create call: ".concat(t));let r=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),x.push(t),p(x)),o.resetFields(),S(!1)}}catch(e){console.error("Error creating the key:",e)}},er=async e=>{if(null==s)return;let l=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};l&&Object.entries(l.envVarMap).forEach(l=>{let[s,a]=l;e[s]&&(t[a]=e[s])}),(0,g.K_)(s,{environment_variables:t})};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.jsx)(m,{children:"Go to 'Internal Users' page to add other admins."}),(0,r.jsxs)(_.Z,{children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:()=>!0===a?T(!0):A.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(v.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(lR,{isAddSSOModalVisible:P,isInstructionsModalVisible:L,handleAddSSOOk:()=>{T(!1),o.resetFields()},handleAddSSOCancel:()=>{T(!1),o.resetFields()},handleShowInstructions:e=>{ea(e),er(e),T(!1),D(!0)},handleInstructionsOk:()=>{D(!1)},handleInstructionsCancel:()=>{D(!1)},form:o}),(0,r.jsx)(E.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>F(!1),footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>z(!0),children:"Add IP Address"},"add"),(0,r.jsx)(v.Z,{onClick:()=>F(!1),children:"Close"},"close")],children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"IP Address"}),(0,r.jsx)(ey.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:K.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e}),(0,r.jsx)(e_.Z,{className:"text-right",children:e!==X&&(0,r.jsx)(v.Z,{onClick:()=>es(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(E.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>z(!1),footer:null,children:(0,r.jsxs)(I.Z,{onFinish:el,children:[(0,r.jsx)(I.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(M.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(I.Z.Item,{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(E.Z,{title:"Confirm Delete",visible:V,onCancel:()=>q(!1),onOk:et,footer:[(0,r.jsx)(v.Z,{className:"mx-1",onClick:()=>et(),children:"Yes"},"delete"),(0,r.jsx)(v.Z,{onClick:()=>q(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",H,"?"]})})]}),(0,r.jsxs)(lM.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:Q,target:"_blank",children:[(0,r.jsx)("b",{children:Q})," "]})]})]})]})},lz=s(92858),lV=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:i}=e,[n]=I.Z.useForm();return(0,r.jsxs)(I.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{align:"center",children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?i?(0,r.jsx)(I.Z.Item,{name:e.field_name,children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(I.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(e_.Z,{children:"Integer"===e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(lz.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),n.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(M.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lq=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(0,g.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lV,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,g.jA)(l,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,g.jA)(l,"alerting",["slack"]):(0,g.jA)(l,"alerting",[])),A.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lK=s(86582);let{Title:lB,Paragraph:lH}=J.default;console.log=function(){};var lJ=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[n,o]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[m,u]=(0,i.useState)(!1),[h]=I.Z.useForm(),[x,p]=(0,i.useState)(null),[j,f]=(0,i.useState)([]),[b,Z]=(0,i.useState)(""),[N,S]=(0,i.useState)({}),[k,P]=(0,i.useState)([]),[T,M]=(0,i.useState)(!1),[L,D]=(0,i.useState)([]),[R,F]=(0,i.useState)(null),[U,z]=(0,i.useState)([]),[V,q]=(0,i.useState)(!1),[K,B]=(0,i.useState)(null),J=e=>{k.includes(e)?P(k.filter(l=>l!==e)):P([...k,e])},G={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,i.useEffect)(()=>{l&&s&&t&&(0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),D(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),P(e.active_alerts),Z(s),S(e.alerts_to_webhook)}c(l)})},[l,s,t]);let W=e=>k&&k.includes(e),Y=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,g.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Email settings updated successfully")},$=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,g.K_)(l,{environment_variables:s}),A.ZP.success("Callback added successfully"),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},X=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,g.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),A.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),p(null)}catch(e){A.ZP.error("Failed to add callback: "+e,20)}},Q=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",L),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(n)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(ek.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(ek.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(ek.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsxs)(eA.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(_.Z,{numItems:2,children:(0,r.jsx)(eS.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ey.Z,{children:"Callback Name"})})}),(0,r.jsx)(ef.Z,{children:n.map((e,s)=>(0,r.jsxs)(eb.Z,{className:"flex justify-between",children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>{B(e),q(!0)}}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(w.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{}),(0,r.jsx)(ey.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(G).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)}):(0,r.jsx)(v.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(lz.Z,{id:"switch",name:"switch",checked:W(s),onChange:()=>J(s)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:t})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:s,type:"password",defaultValue:N&&N[s]?N[s]:b})})]},l)})})]}),(0,r.jsx)(v.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(G).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:k}};console.log("payload",s);try{(0,g.K_)(l,s)}catch(e){A.ZP.error("Failed to update alerts: "+e,20)}A.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(lq,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(lB,{level:4,children:"Email Settings"}),(0,r.jsxs)(w.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(e_.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(_.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(w.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(w.Z,{className:"mt-2",children:l}),(0,r.jsx)(y.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},l)})})})},l)})}),(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>Y(),children:"Save Changes"}),(0,r.jsx)(v.Z,{onClick:()=>(0,g.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(E.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>M(!1),footer:null,children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,r.jsx)(I.Z,{form:h,onFinish:X,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lK.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(C.default,{onChange:e=>{let l=L[e];l&&(console.log(l.ui_callback_name),Q(l))},children:L&&Object.values(L).map(e=>(0,r.jsx)(H.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lK.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(y.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(E.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(I.Z,{form:h,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lK.Z,{label:l,name:l,children:(0,r.jsx)(y.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lG=s(92414),lW=s(46030);let{Option:lY}=C.default;var l$=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[n]=I.Z.useForm(),[o,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(E.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),n.resetFields()},onCancel:()=>{d(!1),n.resetFields()},children:(0,r.jsxs)(I.Z,{form:n,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,i=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:i};console.log(o);try{(0,g.K_)(s,{router_settings:o}),a(o)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully"),d(!1),n.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eN.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(H.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(I.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lG.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lX=s(33619);async function lQ(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new lX.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});A.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l0={ttl:3600,lowest_latency_buffer:0},l1=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(b.Z,{children:[(0,r.jsx)(N.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(Z.Z,{children:"latency-based-routing"==l?(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(w.Z,{children:"No specific settings"})})]})};var l2=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[m,u]=(0,i.useState)([]),[h,x]=(0,i.useState)(!1),[p]=I.Z.useForm(),[j,b]=(0,i.useState)(null),[Z,N]=(0,i.useState)(null),[k,C]=(0,i.useState)(null),E={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,i.useEffect)(()=>{l&&s&&t&&((0,g.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,g.YU)(l).then(e=>{u(e)}))},[l,s,t]);let P=async e=>{if(!l)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(n.fallbacks));let s=n.fallbacks.map(l=>(e in l&&delete l[e],l)).filter(e=>Object.keys(e).length>0),t={...n,fallbacks:s};try{await (0,g.K_)(l,{router_settings:t}),o(t),A.ZP.success("Router settings updated successfully")}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},M=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,g.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},L=(e,s)=>{if(l)try{(0,g.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},D=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,Z];if("routing_strategy_args"==l&&"latency-based-routing"==Z){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,g.K_)(l,{router_settings:s})}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eI.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(ek.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(ek.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(ek.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(S.Z,{children:"Router Settings"}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"})]})}),(0,r.jsx)(ef.Z,{children:Object.entries(n).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:E[l]})]}),(0,r.jsx)(e_.Z,{children:"routing_strategy"==l?(0,r.jsxs)(eN.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:N,children:[(0,r.jsx)(H.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(H.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(H.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(y.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(l1,{selectedStrategy:Z,strategyArgs:n&&n.routing_strategy_args&&Object.keys(n.routing_strategy_args).length>0?n.routing_strategy_args:l0,paramExplanation:E})]}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(v.Z,{className:"mt-2",onClick:()=>D(n),children:"Save Changes"})})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Model Name"}),(0,r.jsx)(ey.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(ef.Z,{children:n.fallbacks&&n.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:t}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(v.Z,{onClick:()=>lQ(t,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>P(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(l$,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:n,setRouterSettings:o})]}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Setting"}),(0,r.jsx)(ey.Z,{children:"Value"}),(0,r.jsx)(ey.Z,{children:"Status"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(w.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(e_.Z,{children:"Integer"==e.field_type?(0,r.jsx)(T.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(e_.Z,{children:!0==e.stored_in_db?(0,r.jsx)(ew.Z,{icon:es.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(ew.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(v.Z,{onClick:()=>M(e.field_name,l),children:"Update"}),(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>L(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},l4=s(93142),l5=s(45246),l3=s(96473),l6=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,i.useState)(Object.entries(l)),n=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let i=[...t];i[e]=[l,r],a(i),null==s||s(Object.fromEntries(i))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(l4.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(y.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(y.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(l5.Z,{onClick:()=>n(l)})]},l)}),(0,r.jsx)(O.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(l3.Z,{}),children:"Add Header"})]})};let{Option:l8}=C.default;var l7=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=I.Z.useForm(),[n,o]=(0,i.useState)(!1),[d,c]=(0,i.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(v.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(E.Z,{title:"Add Pass-Through Endpoint",visible:n,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(I.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,g.Vt)(l,e),s(r)}catch(e){A.ZP.error("Failed to update router settings: "+e,20)}A.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,r.jsx)(y.Z,{})}),(0,r.jsx)(I.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,r.jsx)(l6,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},l9=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[n,o]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&s&&t&&(0,g.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,g.EG)(l,e);let s=n.filter(l=>l.path!==e);o(s),A.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eC.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Path"}),(0,r.jsx)(ey.Z,{children:"Target"}),(0,r.jsx)(ey.Z,{children:"Headers"}),(0,r.jsx)(ey.Z,{children:"Action"})]})}),(0,r.jsx)(ef.Z,{children:n.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(w.Z,{children:e.path})}),(0,r.jsx)(e_.Z,{children:e.target}),(0,r.jsx)(e_.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(e6.Z,{icon:eT.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(l7,{accessToken:l,setPassThroughItems:o,passThroughItems:n})]})})}):null},se=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[i]=I.Z.useForm(),n=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call");let l=await (0,g.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),A.ZP.success("API Key Created"),i.resetFields()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,r.jsxs)(I.Z,{form:i,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},sl=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:n,handleUpdateCall:o}=e;console.log("existingBudget",n);let[d]=I.Z.useForm();(0,i.useEffect)(()=>{d.setFieldsValue(n)},[n,d]);let c=async e=>{if(null!=s&&void 0!=s)try{A.ZP.info("Making API Call"),t(!0);let l=await (0,g.qI)(s,e);a(e=>e?[...e,l]:[l]),A.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),A.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(E.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(I.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:n,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,r.jsx)(y.Z,{placeholder:""})}),(0,r.jsx)(I.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(T.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(b.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(N.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(I.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(T.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(I.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(C.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(C.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(C.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(C.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(O.ZP,{htmlType:"submit",children:"Save"})})]})})},ss=s(17906),st=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)(!1),[a,n]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[c,m]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&(0,g.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),n(!0))},h=async(e,s)=>{if(null==l)return;A.ZP.info("Request made"),await (0,g.NV)(l,e);let t=[...c];t.splice(s,1),m(t),A.ZP.success("Budget Deleted.")},x=async()=>{null!=l&&(0,g.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(v.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(se,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(sl,{accessToken:l,isModalVisible:a,setIsModalVisible:n,setBudgetList:m,existingBudget:o,handleUpdateCall:x}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(w.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Budget ID"}),(0,r.jsx)(ey.Z,{children:"Max Budget"}),(0,r.jsx)(ey.Z,{children:"TPM"}),(0,r.jsx)(ey.Z,{children:"RPM"})]})}),(0,r.jsx)(ef.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.budget_id}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(e_.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(e_.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(e6.Z,{icon:e8.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(e6.Z,{icon:eT.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(w.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(ek.Z,{children:"Test it (Curl)"}),(0,r.jsx)(ek.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},sa=s(77398),sr=s.n(sa),si=s(20016);async function sn(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let so=e=>{let{ipAddress:l}=e,[s,t]=i.useState("-");return i.useEffect(()=>{if(!l)return;let e=!0;return sn(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},sd=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},sc=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:sd(l)})},sm=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(sc,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let l="failure"!==(e.getValue()||"Success").toLowerCase();return(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(l?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:l?"Success":"Failure"})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(U.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(so,{ipAddress:e.getValue()})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let l=String(e.getValue()||"-");return(0,r.jsx)(U.Z,{title:l,children:(0,r.jsxs)("span",{className:"font-mono",children:[l.slice(0,5),"..."]})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:eQ(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(U.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();if(!l||0===Object.keys(l).length)return"-";let s=Object.entries(l),t=s[0],a=s.slice(1);return(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,r.jsx)(U.Z,{title:(0,r.jsx)("div",{className:"flex flex-col gap-1",children:s.map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{children:[l,": ",String(s)]},l)})}),children:(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],su=async(e,l,s,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,l],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,g.qk)(s,e.request_id,l);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}},sh=e=>{var l;let{errorInfo:s}=e,[t,a]=i.useState({}),[n,o]=i.useState(!1),d=e=>{a(l=>({...l,[e]:!l[e]}))},c=s.traceback&&(l=s.traceback)?Array.from(l.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let s=e[1],t=e[2],a=s.split("/").pop()||s,r=e.index||0,i=l.indexOf('File "',r+1),n=i>-1?l.substring(r,i).trim():l.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:s,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_class||"Unknown Error"})]}),(0,r.jsxs)("div",{className:"flex mt-2",children:[(0,r.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Message:"}),(0,r.jsx)("span",{className:"text-red-700",children:s.error_message||"Unknown error occurred"})]})]}),s.traceback&&(0,r.jsxs)("div",{className:"mt-4",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("button",{onClick:()=>{let e=!n;if(o(e),c.length>0){let l={};c.forEach((s,t)=>{l[t]=e}),a(l)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:n?"Collapse All":"Expand All"}),(0,r.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(s.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,r.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:c.map((e,l)=>(0,r.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,r.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>d(l),children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,r.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,r.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,r.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[l]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[l]||!1)&&e.code&&(0,r.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},l))})]})]})]})},sx=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sp=["Internal User","Internal Viewer"],sg=e=>{let{show:l}=e;return l?(0,r.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,r.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,r.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,r.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,r.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,r.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};function sj(e){var l,s,t;let{accessToken:a,token:n,userRole:o,userID:d}=e,[m,u]=(0,i.useState)(""),[h,x]=(0,i.useState)(!1),[p,j]=(0,i.useState)(!1),[f,_]=(0,i.useState)(1),[v]=(0,i.useState)(50),y=(0,i.useRef)(null),b=(0,i.useRef)(null),Z=(0,i.useRef)(null),[N,w]=(0,i.useState)(sr()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,i.useState)(sr()().format("YYYY-MM-DDTHH:mm")),[C,I]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!1),[P,O]=(0,i.useState)(""),[T,M]=(0,i.useState)(""),[L,D]=(0,i.useState)(""),[R,F]=(0,i.useState)(""),[U,z]=(0,i.useState)("Team ID"),[V,q]=(0,i.useState)(o&&sp.includes(o)),K=(0,c.NL)();(0,i.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),b.current&&!b.current.contains(e.target)&&x(!1),Z.current&&!Z.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{o&&sp.includes(o)&&q(!0)},[o]);let B=(0,si.a)({queryKey:["logs","table",f,v,N,S,L,R,V?d:null],queryFn:async()=>{if(!a||!n||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:v,total_pages:0};let e=sr()(N).utc().format("YYYY-MM-DD HH:mm:ss"),l=C?sr()(S).utc().format("YYYY-MM-DD HH:mm:ss"):sr()().utc().format("YYYY-MM-DD HH:mm:ss"),s=await (0,g.h3)(a,R||void 0,L||void 0,void 0,e,l,f,v,V?d:void 0);return await su(s.data,e,a,K),s.data=s.data.map(l=>{let s=K.getQueryData(["logDetails",l.request_id,e]);return(null==s?void 0:s.messages)&&(null==s?void 0:s.response)&&(l.messages=s.messages,l.response=s.response),l}),s},enabled:!!a&&!!n&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!n||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let H=(null===(s=B.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!m||e.request_id.includes(m)||e.model.includes(m)||e.user&&e.user.includes(m)))||[],J=()=>{if(C)return"".concat(sr()(N).format("MMM D, h:mm A")," - ").concat(sr()(S).format("MMM D, h:mm A"));let e=sr()(),l=sr()(N),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:m,onChange:e=>u(e.target.value)}),(0,r.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>x(!h),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filter"]}),h&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>j(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[U,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(U===e?"bg-blue-50 text-blue-600":""),onClick:()=>{z(e),j(!1),"Team ID"===e?M(""):O("")},children:[U===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===U?P:T,onChange:e=>{"Team ID"===U?O(e.target.value):M(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{O(""),M("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{O(""),M(""),x(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{D(P),F(T),_(1),x(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:Z,children:[(0,r.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),J()]}),A&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(J()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(sr()().format("YYYY-MM-DDTHH:mm")),w(sr()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),I(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(C?"bg-blue-50 text-blue-600":""),onClick:()=>I(!C),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{B.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,r.jsx)("svg",{className:"w-4 h-4 ".concat(B.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsx)("span",{children:"Refresh"})]})]}),C&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:N,onChange:e=>{w(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",B.isLoading?"...":B.data?(f-1)*v+1:0," ","-"," ",B.isLoading?"...":B.data?Math.min(f*v,B.data.total):0," ","of"," ",B.isLoading?"...":B.data?B.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",B.isLoading?"...":f," of"," ",B.isLoading?"...":B.data?B.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:B.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>_(e=>{var l;return Math.min((null===(l=B.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:B.isLoading||f===((null===(t=B.data)||void 0===t?void 0:t.total_pages)||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,r.jsx)(eZ,{columns:sm,data:H,renderSubComponent:sf,getRowCanExpand:()=>!0})]})]})}function sf(e){var l,s,t,a,i,n;let{row:o}=e,d=e=>{let l={...e};return"proxy_server_request"in l&&delete l.proxy_server_request,l},c=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},m=()=>{var e;return(null===(e=o.original.metadata)||void 0===e?void 0:e.proxy_server_request)?c(o.original.metadata.proxy_server_request):c(o.original.messages)},u=(null===(l=o.original.metadata)||void 0===l?void 0:l.status)==="failure",h=u?null===(s=o.original.metadata)||void 0===s?void 0:s.error_information:null,x=o.original.messages&&(Array.isArray(o.original.messages)?o.original.messages.length>0:Object.keys(o.original.messages).length>0),p=o.original.response&&Object.keys(c(o.original.response)).length>0,g=()=>u&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:c(o.original.response);return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{className:"font-mono text-sm",children:o.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:o.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,r.jsx)("span",{children:o.original.custom_llm_provider||"-"})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:o.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:o.original.endTime})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,r.jsxs)("span",{children:[o.original.total_tokens," (",o.original.prompt_tokens,"+",o.original.completion_tokens,")"]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,r.jsxs)("span",{children:["$",Number(o.original.spend||0).toFixed(6)]})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:o.original.cache_hit})]}),(null==o?void 0:null===(t=o.original)||void 0===t?void 0:t.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,r.jsx)("span",{children:null==o?void 0:null===(a=o.original)||void 0===a?void 0:a.requester_ip_address})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,r.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=o.original.metadata)||void 0===i?void 0:i.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(n=o.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]})]})]})]}),(0,r.jsx)(sg,{show:!x||!p}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(m(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",disabled:!x,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(m(),null,2)})})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsxs)("h3",{className:"text-lg font-medium",children:["Response",u&&(0,r.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==h?void 0:h.error_code)||400]})]}),(0,r.jsx)("button",{onClick:()=>navigator.clipboard.writeText(JSON.stringify(g(),null,2)),className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!p,children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:p?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(g(),null,2)}):(0,r.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]}),u&&h&&(0,r.jsx)(sh,{errorInfo:h}),o.original.request_tags&&Object.keys(o.original.request_tags).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(o.original.request_tags).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})})})]}),o.original.metadata&&Object.keys(o.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,r.jsx)("button",{onClick:()=>{let e=d(o.original.metadata);navigator.clipboard.writeText(JSON.stringify(e,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,r.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d(o.original.metadata),null,2)})})]})]})}var s_=s(92699),sv=e=>{let{proxySettings:l}=e,s="";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(w.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(ek.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(ek.Z,{children:"LlamaIndex"}),(0,r.jsx)(ek.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(s,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(s,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(ss.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(s,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},sy=s(243),sb=s(94263);async function sZ(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new lX.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){A.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var sN=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:n}=e,[o,d]=(0,i.useState)(n?"custom":"session"),[c,m]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,p]=(0,i.useState)([]),[j,b]=(0,i.useState)(void 0),[Z,N]=(0,i.useState)(!1),[S,k]=(0,i.useState)([]),I=(0,i.useRef)(null),E=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e="session"===o?l:c;if(console.log("useApiKey:",e),!e||!s||!t||!a){console.log("useApiKey or token or userRole or userID is missing = ",e,s,t,a);return}(async()=>{try{let l=await (0,g.So)(null!=e?e:"",a,t);if(console.log("model_info:",l),(null==l?void 0:l.data.length)>0){let e=new Map;l.data.forEach(l=>{e.set(l.id,{value:l.id,label:l.id})});let s=Array.from(e.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),b(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t,o,c]),(0,i.useEffect)(()=>{E.current&&setTimeout(()=>{var e;null===(e=E.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[x]);let P=(e,l,s)=>{p(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},O=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){A.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},i=[...x.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];p([...x,r]);try{j&&await sZ(i,(e,l)=>P("assistant",e,l),j,e)}catch(e){console.error("Error fetching model response",e),P("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=J.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)(_.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsx)(eI.Z,{children:(0,r.jsx)(ek.Z,{children:"Chat"})}),(0,r.jsx)(eE.Z,{children:(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"API Key Source"}),(0,r.jsx)(C.default,{disabled:n,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(f.Z,{className:"mx-2",children:[(0,r.jsx)(w.Z,{children:"Select Model:"}),(0,r.jsx)(C.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),b(e),N("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model"}],style:{width:"350px"},showSearch:!0}),Z&&(0,r.jsx)(y.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{b(e)},500)}})]})]}),(0,r.jsx)(v.Z,{onClick:()=>{p([]),A.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(ej.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ev.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsxs)(ef.Z,{children:[x.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(sy.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...i}=e,n=/language-(\w+)/.exec(t||"");return!s&&n?(0,r.jsx)(ss.Z,{style:sb.Z,language:n[1],PreTag:"div",...i,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...i,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{ref:E,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(y.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&O()},placeholder:"Type your message..."}),(0,r.jsx)(v.Z,{onClick:O,className:"ml-2",children:"Send"})]})})]})})]})})})})},sw=s(19226),sS=s(45937),sk=s(92403),sC=s(28595),sI=s(68208),sA=s(9775),sE=s(41361),sP=s(37527),sO=s(12660),sT=s(88009),sM=s(48231),sL=s(41169),sD=s(44625),sR=s(57400),sF=s(55322);let{Sider:sU}=sw.default,sz=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(sk.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(sC.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(sI.Z,{}),roles:sx},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(sA.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(sE.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(h.Z,{}),roles:sx},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sO.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(sT.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sM.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(sL.Z,{}),roles:sx,children:[{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sD.Z,{}),roles:sx},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(sP.Z,{}),roles:sx},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,r.jsx)(sR.Z,{}),roles:sx}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sO.Z,{}),roles:sx},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sF.Z,{}),roles:sx},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sF.Z,{}),roles:sx}]}];var sV=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sz.find(l=>l.page===e);if(l)return l.key;for(let l of sz)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),i=sz.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(sw.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(sU,{theme:"light",width:220,children:(0,r.jsx)(sS.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sq=s(40278),sK=s(96889),sB=s(97765);console.log=function(){};var sH=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:n,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,i.useState)(null!==a?a:0),[m,u]=(0,i.useState)(o?o.max_budget:null);(0,i.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(n);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,n]);let[h,x]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,g.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,i.useEffect)(()=>{null!==a&&c(a)},[a]);let p=[];o&&o.models&&(p=o.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=o.models:p&&0===p.length&&(p=h);let j=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",j]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})},sJ=s(69907),sG=s(53003),sW=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let sY=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var s$=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:n,premiumUser:o}=e,d=new Date,[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,k]=(0,i.useState)([]),[C,I]=(0,i.useState)([]),[A,E]=(0,i.useState)([]),[P,O]=(0,i.useState)([]),[T,M]=(0,i.useState)([]),[L,D]=(0,i.useState)({}),[R,F]=(0,i.useState)([]),[U,z]=(0,i.useState)(""),[V,q]=(0,i.useState)(["all-tags"]),[K,B]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[J,G]=(0,i.useState)(null),[W,Y]=(0,i.useState)(0),$=new Date(d.getFullYear(),d.getMonth(),1),X=new Date(d.getFullYear(),d.getMonth()+1,0),Q=er($),ee=er(X);function el(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",n),console.log("premium user in usage",o);let es=async()=>{if(l)try{let e=await (0,g.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,i.useEffect)(()=>{ea(K.from,K.to)},[K,V]);let et=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,g.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),y(a)},ea=async(e,s)=>{if(!e||!s||!l)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),k((await (0,g.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(Q)),console.log("End date is ".concat(ee));let ei=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},en=(e,l,s,t)=>{let a=[],r=new Date(l),i=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let l=i(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(l)try{let e=await (0,g.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));Y(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>l&&s?(0,g.OU)(l,s,Q,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),ec=async()=>{l&&await ei(async()=>(await (0,g.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{l&&await ei(async()=>(await (0,g.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{l&&await ei(async()=>{let e=await (0,g.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return Z(en(e.daily_spend,t,a,e.teams)),E(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},O,"Error fetching team spend")},eh=()=>{l&&ei(async()=>(await (0,g.X)(l)).tag_names,I,"Error fetching tag names")},ex=()=>{l&&ei(()=>{var e,s;return(0,g.J$)(l,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(s=K.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>k(e.spend_per_tag),"Error fetching top tags")},ep=()=>{l&&ei(()=>(0,g.b1)(l,null,void 0,void 0),y,"Error fetching top end users")},eg=async()=>{if(l)try{let e=await (0,g.wd)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},eZ=async()=>{if(l)try{let e=await (0,g.xA)(l,Q,ee),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));F(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,i.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await es();e&&(G(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",J),eo(),ed(),ec(),em(),eg(),eZ(),sY(t)&&(eu(),eh(),ex(),ep()))}})()},[l,s,t,a,Q,ee]),null==J?void 0:J.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(w.Z,{className:"mt-4",children:["SpendLogs in DB has ",J.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(v.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"mt-2",children:[(0,r.jsx)(ek.Z,{children:"All Up"}),sY(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ek.Z,{children:"Team Based Usage"}),(0,r.jsx)(ek.Z,{children:"Customer Usage"}),(0,r.jsx)(ek.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(ek.Z,{children:"Cost"}),(0,r.jsx)(ek.Z,{children:"Activity"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(w.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,r.jsx)(sH,{userID:a,userRole:t,accessToken:l,userSpend:W,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Monthly Spend"}),(0,r.jsx)(sq.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top API Keys"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Top Models"}),(0,r.jsx)(sq.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(f.Z,{numColSpan:1}),(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sW.Z,{className:"mt-4 h-40",variant:"pie",data:T,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Provider"}),(0,r.jsx)(ey.Z,{children:"Spend"})]})}),(0,r.jsx)(ef.Z,{children:T.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.provider}),(0,r.jsx)(e_.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"All Up"}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(L.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(L.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:L.daily_data,valueFormatter:el,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:e.model}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",el(e.sum_api_requests)]}),(0,r.jsx)(sJ.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:el,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsxs)(sB.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",el(e.sum_total_tokens)]}),(0,r.jsx)(sq.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:el,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(f.Z,{numColSpan:2,children:[(0,r.jsxs)(eS.Z,{className:"mb-2",children:[(0,r.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sK.Z,{data:P})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(sq.Z,{className:"h-72",data:b,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(f.Z,{numColSpan:2})]})}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Time Range"}),(0,r.jsx)(sG.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,r.jsxs)(f.Z,{children:[(0,r.jsx)(w.Z,{children:"Select Key"}),(0,r.jsxs)(eN.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(H.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(H.Z,{value:String(l),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(eS.Z,{className:"mt-4",children:(0,r.jsxs)(ej.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Customer"}),(0,r.jsx)(ey.Z,{children:"Spend"}),(0,r.jsx)(ey.Z,{children:"Total Events"})]})}),(0,r.jsx)(ef.Z,{children:null==j?void 0:j.map((e,l)=>{var s;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(e_.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eA.Z,{children:[(0,r.jsxs)(_.Z,{numItems:2,children:[(0,r.jsx)(f.Z,{numColSpan:1,children:(0,r.jsx)(sG.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,r.jsx)(f.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lW.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lG.Z,{value:V,onValueChange:e=>q(e),children:[(0,r.jsx)(lW.Z,{value:"all-tags",onClick:()=>q(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(H.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(_.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(f.Z,{numColSpan:2,children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(S.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(w.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(sq.Z,{className:"h-72",data:N,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(f.Z,{numColSpan:2})]})]})]})]})})},sX=s(51853);let sQ=e=>{let{responseTimeMs:l}=e;return null==l?null:(0,r.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,r.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,r.jsxs)("span",{children:[l.toFixed(0),"ms"]})]})},s0=e=>{let l=e;if("string"==typeof l)try{l=JSON.parse(l)}catch(e){}return l},s1=e=>{let{label:l,value:s}=e,[t,a]=i.useState(!1),[n,o]=i.useState(!1),d=(null==s?void 0:s.toString())||"N/A",c=d.length>50?d.substring(0,50)+"...":d;return(0,r.jsx)("tr",{className:"hover:bg-gray-50",children:(0,r.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,r.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm text-gray-600",children:l}),(0,r.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?d:c})]})]}),(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,r.jsx)(sX.Z,{className:"h-4 w-4"})})]})})})},s2=e=>{var l,s,t,a,i,n,o,d,c,m,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=s0(j.litellm_params)||{},_=s0(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=s0(null==g?void 0:g.litellm_cache_params)||{},_=s0(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(i=n.connection_pool)||void 0===i?void 0:null===(a=i.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(o=_.connection_kwargs)||void 0===o?void 0:o.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(m=_.redis_client)||void 0===m?void 0:null===(c=m.connection_pool)||void 0===c?void 0:null===(d=c.connection_kwargs)||void 0===d?void 0:d.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,l,s,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(s=t.connection_pool)||void 0===s?void 0:null===(l=s.connection_kwargs)||void 0===l?void 0:l.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,r.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,r.jsxs)(eC.Z,{children:[(0,r.jsxs)(eI.Z,{className:"border-b border-gray-200 px-4",children:[(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,r.jsx)(ek.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,r.jsx)(es.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,r.jsx)(el.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,r.jsxs)(w.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,r.jsx)("table",{className:"w-full border-collapse",children:(0,r.jsxs)("tbody",{children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,r.jsx)(s1,{label:"Error Message",value:j.message}),(0,r.jsx)(s1,{label:"Traceback",value:j.traceback})]}),(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,r.jsx)(s1,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,r.jsx)(s1,{label:"Ping Response",value:String(g.ping_response)}),(0,r.jsx)(s1,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,r.jsx)(s1,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,r.jsx)(s1,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,r.jsx)(s1,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,r.jsx)(s1,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,r.jsx)(s1,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,r.jsx)(s1,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,r.jsx)(eA.Z,{className:"p-4",children:(0,r.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,r.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},l=JSON.parse(JSON.stringify(e,(e,l)=>{if("string"==typeof l)try{return JSON.parse(l)}catch(e){}return l}));return JSON.stringify(l,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},s4=e=>{let{accessToken:l,healthCheckResponse:s,runCachingHealthCheck:t,responseTimeMs:a}=e,[n,o]=i.useState(null),[d,c]=i.useState(!1),m=async()=>{c(!0);let e=performance.now();await t(),o(performance.now()-e),c(!1)};return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(v.Z,{onClick:m,disabled:d,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:d?"Running Health Check...":"Run Health Check"}),(0,r.jsx)(sQ,{responseTimeMs:n})]}),s&&(0,r.jsx)(s2,{response:s})]})},s5=e=>{if(e)return e.toISOString().split("T")[0]};function s3(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var s6=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:n}=e,[o,d]=(0,i.useState)([]),[c,m]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,v]=(0,i.useState)("0"),[y,b]=(0,i.useState)("0"),[Z,N]=(0,i.useState)("0"),[S,k]=(0,i.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,i.useState)(""),[E,P]=(0,i.useState)("");(0,i.useEffect)(()=>{l&&S&&((async()=>{p(await (0,g.zg)(l,s5(S.from),s5(S.to)))})(),I(new Date().toLocaleString()))},[l]);let O=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),T=Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(x.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let M=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,g.zg)(l,s5(e),s5(s))))};(0,i.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);v(s3(s)),b(s3(t));let r=s+l;r>0?N((s/r*100).toFixed(2)):N("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,S,x]);let L=async()=>{try{A.ZP.info("Running cache health check..."),P("");let e=await (0,g.Tj)(null!==l?l:"");console.log("CACHING HEALTH CHECK RESPONSE",e),P(e)}catch(l){let e;if(console.error("Error running health check:",l),l&&l.message)try{let s=JSON.parse(l.message);s.error&&(s=s.error),e=s}catch(s){e={message:l.message}}else e={message:"Unknown error occurred"};P({error:e})}};return(0,r.jsxs)(eC.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,r.jsxs)(eI.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(ek.Z,{children:"Cache Analytics"}),(0,r.jsx)(ek.Z,{children:(0,r.jsx)("pre",{children:"Cache Health"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,r.jsxs)(w.Z,{children:["Last Refreshed: ",C]}),(0,r.jsx)(e6.Z,{icon:eO.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,r.jsxs)(eE.Z,{children:[(0,r.jsx)(eA.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(_.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:O.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(lG.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:T.map(e=>(0,r.jsx)(lW.Z,{value:e,children:e},e))})}),(0,r.jsx)(f.Z,{children:(0,r.jsx)(sG.Z,{enableSelect:!0,value:S,onValueChange:e=>{k(e),M(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[Z,"%"]})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:j})})]}),(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(sq.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(sB.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(sq.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:s3,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,r.jsx)(eA.Z,{children:(0,r.jsx)(s4,{accessToken:l,healthCheckResponse:E,runCachingHealthCheck:L})})]})]})},s8=e=>{let{accessToken:l}=e,[s,t]=(0,i.useState)([]);return(0,i.useEffect)(()=>{l&&(async()=>{try{let e=await (0,g.t3)(l);console.log("guardrails: ".concat(JSON.stringify(e))),t(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}})()},[l]),(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsxs)(w.Z,{className:"mb-4",children:["Configured guardrails and their current status. Setup guardrails in config.yaml."," ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]}),(0,r.jsx)(eS.Z,{children:(0,r.jsxs)(ej.Z,{children:[(0,r.jsx)(ev.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ey.Z,{children:"Guardrail Name"}),(0,r.jsx)(ey.Z,{children:"Mode"}),(0,r.jsx)(ey.Z,{children:"Status"})]})}),(0,r.jsx)(ef.Z,{children:s&&0!==s.length?null==s?void 0:s.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:e.guardrail_name}),(0,r.jsx)(e_.Z,{children:e.litellm_params.mode}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)("div",{className:"inline-flex rounded-full px-2 py-1 text-xs font-medium\n ".concat(e.litellm_params.default_on?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.litellm_params.default_on?"Always On":"Per Request"})})]},l)):(0,r.jsx)(eb.Z,{children:(0,r.jsx)(e_.Z,{colSpan:3,className:"mt-4 text-gray-500 text-center py-4",children:"No guardrails configured"})})})]})})]})};let s7=new d.S;function s9(){let[e,l]=(0,i.useState)(""),[s,t]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[m,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[f,_]=(0,i.useState)(null),[v,y]=(0,i.useState)([]),[b,Z]=(0,i.useState)([]),[N,w]=(0,i.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,k]=(0,i.useState)(!0),C=(0,n.useSearchParams)(),[I,A]=(0,i.useState)({data:[]}),[E,P]=(0,i.useState)(null),O=C.get("userID"),T=C.get("invitation_id"),[M,L]=(0,i.useState)(()=>C.get("page")||"api-keys"),[D,R]=(0,i.useState)(null);return(0,i.useEffect)(()=>{P(function(e){let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"))},[]),(0,i.useEffect)(()=>{if(!E)return;let e=(0,o.o)(E);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),R(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),l(s),"Admin Viewer"==s&&L("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?k("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,g.K8)(e.auth_header_name)}},[E]),(0,i.useEffect)(()=>{D&&O&&e&&em(O,e,D,Z),D&&O&&e&&j(D,O,e,null,x),D&&lO(D,y)},[D,O,e]),(0,r.jsx)(i.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:s7,children:T?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(p,{userID:O,userRole:e,premiumUser:s,setProxySettings:w,proxySettings:N}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sV,{setPage:e=>{let l=new URLSearchParams(C);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),L(e)},userRole:e,defaultSelectedKey:M})}),"api-keys"==M?(0,r.jsx)(eY,{userID:O,userRole:e,premiumUser:s,teams:h,keys:f,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:x,setKeys:_,organizations:v}):"models"==M?(0,r.jsx)(lZ,{userID:O,userRole:e,token:E,keys:f,accessToken:D,modelData:I,setModelData:A,premiumUser:s,teams:h}):"llm-playground"==M?(0,r.jsx)(sN,{userID:O,userRole:e,token:E,accessToken:D,disabledPersonalKeyCreation:a}):"users"==M?(0,r.jsx)(lC,{userID:O,userRole:e,token:E,keys:f,teams:h,accessToken:D,setKeys:_}):"teams"==M?(0,r.jsx)(lE,{teams:h,setTeams:x,searchParams:C,accessToken:D,userID:O,userRole:e,organizations:v}):"organizations"==M?(0,r.jsx)(lT,{organizations:v,setOrganizations:y,userModels:b,accessToken:D,userRole:e,premiumUser:s}):"admin-panel"==M?(0,r.jsx)(lU,{setTeams:x,searchParams:C,accessToken:D,showSSOBanner:S,premiumUser:s}):"api_ref"==M?(0,r.jsx)(sv,{proxySettings:N}):"settings"==M?(0,r.jsx)(lJ,{userID:O,userRole:e,accessToken:D,premiumUser:s}):"budgets"==M?(0,r.jsx)(st,{accessToken:D}):"guardrails"==M?(0,r.jsx)(s8,{accessToken:D}):"general-settings"==M?(0,r.jsx)(l2,{userID:O,userRole:e,accessToken:D,modelData:I}):"model-hub"==M?(0,r.jsx)(s_.Z,{accessToken:D,publicPage:!1,premiumUser:s}):"caching"==M?(0,r.jsx)(s6,{userID:O,userRole:e,token:E,accessToken:D,premiumUser:s}):"pass-through-settings"==M?(0,r.jsx)(l9,{userID:O,userRole:e,accessToken:D,modelData:I}):"logs"==M?(0,r.jsx)(sj,{userID:O,userRole:e,token:E,accessToken:D}):(0,r.jsx)(s$,{userID:O,userRole:e,token:E,accessToken:D,keys:f,premiumUser:s})]})]})})})}}},function(e){e.O(0,[665,990,441,261,899,914,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js b/ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_buildManifest.js rename to ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_buildManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js b/ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/FMvuTRMhZEulJpWx99WMb/_ssgManifest.js rename to ui/litellm-dashboard/out/_next/static/sW550-yvC4l9ZFA0scEUc/_ssgManifest.js diff --git a/ui/litellm-dashboard/out/index.html b/ui/litellm-dashboard/out/index.html index 07624d4899..ae2e51152b 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 0830197521..32025bae5b 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-a006114359094d34.js"],"default",1] +3:I[92222,["665","static/chunks/3014691f-0b72c78cfebbd712.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","899","static/chunks/899-354f59ecde307dfa.js","914","static/chunks/914-000d10374f86fc1a.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","931","static/chunks/app/page-e28453cd004ff93c.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/model_hub.html b/ui/litellm-dashboard/out/model_hub.html index 3633aad3e7..c379b2e0cc 100644 --- a/ui/litellm-dashboard/out/model_hub.html +++ b/ui/litellm-dashboard/out/model_hub.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/model_hub.txt b/ui/litellm-dashboard/out/model_hub.txt index 54a3766fb8..2bef2383df 100644 --- a/ui/litellm-dashboard/out/model_hub.txt +++ b/ui/litellm-dashboard/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["441","static/chunks/441-79926bf2b9d89e04.js","261","static/chunks/261-cb27c20c4f8ec4c6.js","250","static/chunks/250-51513f2f6dabf571.js","699","static/chunks/699-6b82f8e7b98ca1a3.js","418","static/chunks/app/model_hub/page-6f97b95f1023b0e9.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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/out/onboarding.html b/ui/litellm-dashboard/out/onboarding.html index 3b4d5d430f..11decf6639 100644 --- a/ui/litellm-dashboard/out/onboarding.html +++ b/ui/litellm-dashboard/out/onboarding.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/onboarding.txt b/ui/litellm-dashboard/out/onboarding.txt index e05b041088..ec0568e731 100644 --- a/ui/litellm-dashboard/out/onboarding.txt +++ b/ui/litellm-dashboard/out/onboarding.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-8ba945cf183c937c.js"],"default",1] +3:I[12011,["665","static/chunks/3014691f-0b72c78cfebbd712.js","441","static/chunks/441-79926bf2b9d89e04.js","899","static/chunks/899-354f59ecde307dfa.js","250","static/chunks/250-51513f2f6dabf571.js","461","static/chunks/app/onboarding/page-f2e9aa9e77b66520.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["FMvuTRMhZEulJpWx99WMb",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] +0:["sW550-yvC4l9ZFA0scEUc",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/f41c66e22715ab00.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"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":[]}]}]}]],null],null],["$L6",null]]]] 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 From 4c8b4fefc9638c0cf65d6353ae895b1fa908bf0e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 4 Mar 2025 13:29:08 -0800 Subject: [PATCH 12/12] Revert "(UI) - Improvements to session handling logic (#8970)" This reverts commit c015fb34f1e120d4631ab58ebd76879b27c76bd7. --- litellm/proxy/management_endpoints/ui_sso.py | 8 +- .../management_helpers/ui_session_handler.py | 24 ----- litellm/proxy/proxy_server.py | 14 +-- .../src/app/onboarding/page.tsx | 6 +- ui/litellm-dashboard/src/app/page.tsx | 9 +- .../src/components/user_dashboard.tsx | 11 ++- ui/litellm-dashboard/src/utils/cookieUtils.ts | 96 +++++-------------- 7 files changed, 52 insertions(+), 116 deletions(-) delete mode 100644 litellm/proxy/management_helpers/ui_session_handler.py diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index d092fd8800..2e2720c104 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -43,7 +43,6 @@ from litellm.proxy.management_endpoints.sso_helper_utils import ( ) from litellm.proxy.management_endpoints.team_endpoints import team_member_add from litellm.proxy.management_endpoints.types import CustomOpenID -from litellm.proxy.management_helpers.ui_session_handler import UISessionHandler from litellm.secret_managers.main import str_to_bool if TYPE_CHECKING: @@ -691,10 +690,9 @@ async def auth_callback(request: Request): # noqa: PLR0915 ) if user_id is not None and isinstance(user_id, str): litellm_dashboard_ui += "?userID=" + user_id - - return UISessionHandler.generate_authenticated_redirect_response( - redirect_url=litellm_dashboard_ui, jwt_token=jwt_token - ) + redirect_response = RedirectResponse(url=litellm_dashboard_ui, status_code=303) + redirect_response.set_cookie(key="token", value=jwt_token, secure=True) + return redirect_response async def insert_sso_user( diff --git a/litellm/proxy/management_helpers/ui_session_handler.py b/litellm/proxy/management_helpers/ui_session_handler.py deleted file mode 100644 index 6afe158c33..0000000000 --- a/litellm/proxy/management_helpers/ui_session_handler.py +++ /dev/null @@ -1,24 +0,0 @@ -import time - -from fastapi.responses import RedirectResponse - - -class UISessionHandler: - @staticmethod - def generate_authenticated_redirect_response( - redirect_url: str, jwt_token: str - ) -> RedirectResponse: - redirect_response = RedirectResponse(url=redirect_url, status_code=303) - redirect_response.set_cookie( - key=UISessionHandler._generate_token_name(), - value=jwt_token, - secure=True, - samesite="strict", - ) - return redirect_response - - @staticmethod - def _generate_token_name() -> str: - current_timestamp = int(time.time()) - cookie_name = f"token_{current_timestamp}" - return cookie_name diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index bcca95b310..19d0ebe9ea 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7372,8 +7372,6 @@ async def login(request: Request): # noqa: PLR0915 import multipart except ImportError: subprocess.run(["pip", "install", "python-multipart"]) - from litellm.proxy.management_helpers.ui_session_handler import UISessionHandler - global master_key if master_key is None: raise ProxyException( @@ -7491,9 +7489,9 @@ async def login(request: Request): # noqa: PLR0915 algorithm="HS256", ) litellm_dashboard_ui += "?userID=" + user_id - return UISessionHandler.generate_authenticated_redirect_response( - redirect_url=litellm_dashboard_ui, jwt_token=jwt_token - ) + redirect_response = RedirectResponse(url=litellm_dashboard_ui, status_code=303) + redirect_response.set_cookie(key="token", value=jwt_token) + return redirect_response elif _user_row is not None: """ When sharing invite links @@ -7559,9 +7557,11 @@ async def login(request: Request): # noqa: PLR0915 algorithm="HS256", ) litellm_dashboard_ui += "?userID=" + user_id - return UISessionHandler.generate_authenticated_redirect_response( - redirect_url=litellm_dashboard_ui, jwt_token=jwt_token + redirect_response = RedirectResponse( + url=litellm_dashboard_ui, status_code=303 ) + redirect_response.set_cookie(key="token", value=jwt_token) + return redirect_response else: raise ProxyException( message=f"Invalid credentials used to access UI.\nNot valid credentials for {username}", diff --git a/ui/litellm-dashboard/src/app/onboarding/page.tsx b/ui/litellm-dashboard/src/app/onboarding/page.tsx index 0c194ba0cb..e46e46fcb5 100644 --- a/ui/litellm-dashboard/src/app/onboarding/page.tsx +++ b/ui/litellm-dashboard/src/app/onboarding/page.tsx @@ -20,12 +20,12 @@ import { } from "@/components/networking"; import { jwtDecode } from "jwt-decode"; import { Form, Button as Button2, message } from "antd"; -import { getAuthToken, setAuthToken } from "@/utils/cookieUtils"; +import { getCookie } from "@/utils/cookieUtils"; export default function Onboarding() { const [form] = Form.useForm(); const searchParams = useSearchParams()!; - const token = getAuthToken(); + const token = getCookie('token'); const inviteID = searchParams.get("invitation_id"); const [accessToken, setAccessToken] = useState(null); const [defaultUserEmail, setDefaultUserEmail] = useState(""); @@ -88,7 +88,7 @@ export default function Onboarding() { litellm_dashboard_ui += "?userID=" + user_id; // set cookie "token" to jwtToken - setAuthToken(jwtToken); + document.cookie = "token=" + jwtToken; console.log("redirecting to:", litellm_dashboard_ui); window.location.href = litellm_dashboard_ui; diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index fa07c08615..2612cab594 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -30,7 +30,12 @@ import { Organization } from "@/components/networking"; import GuardrailsPanel from "@/components/guardrails"; import { fetchUserModels } from "@/components/create_key_button"; import { fetchTeams } from "@/components/common_components/fetch_teams"; -import { getAuthToken } from "@/utils/cookieUtils"; +function getCookie(name: string) { + const cookieValue = document.cookie + .split("; ") + .find((row) => row.startsWith(name + "=")); + return cookieValue ? cookieValue.split("=")[1] : null; +} function formatUserRole(userRole: string) { if (!userRole) { @@ -112,7 +117,7 @@ export default function CreateKeyPage() { const [accessToken, setAccessToken] = useState(null); useEffect(() => { - const token = getAuthToken(); + const token = getCookie("token"); setToken(token); }, []); diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index 9f4230e6b2..22b47d525f 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -21,7 +21,6 @@ import { useSearchParams, useRouter } from "next/navigation"; import { Team } from "./key_team_helpers/key_list"; import { jwtDecode } from "jwt-decode"; import { Typography } from "antd"; -import { getAuthToken } from "@/utils/cookieUtils"; import { clearTokenCookies } from "@/utils/cookieUtils"; const isLocal = process.env.NODE_ENV === "development"; if (isLocal != true) { @@ -46,6 +45,14 @@ export type UserInfo = { spend: number; } +function getCookie(name: string) { + console.log("COOKIES", document.cookie) + const cookieValue = document.cookie + .split('; ') + .find(row => row.startsWith(name + '=')); + return cookieValue ? cookieValue.split('=')[1] : null; +} + interface UserDashboardProps { userID: string | null; userRole: string | null; @@ -87,7 +94,7 @@ const UserDashboard: React.FC = ({ // Assuming useSearchParams() hook exists and works in your setup const searchParams = useSearchParams()!; - const token = getAuthToken(); + const token = getCookie('token'); const invitation_id = searchParams.get("invitation_id"); diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts index e181606e93..a09cf4e97f 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -13,82 +13,32 @@ export function clearTokenCookies() { const paths = ['/', '/ui']; const sameSiteValues = ['Lax', 'Strict', 'None']; - // Get all cookies - const allCookies = document.cookie.split("; "); - const tokenPattern = /^token_\d+$/; - - // Find all token cookies - const tokenCookieNames = allCookies - .map(cookie => cookie.split("=")[0]) - .filter(name => name === "token" || tokenPattern.test(name)); - - // Clear each token cookie with various combinations - tokenCookieNames.forEach(cookieName => { - paths.forEach(path => { - // Basic clearing - document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; - - // With domain - document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; - - // Try different SameSite values - sameSiteValues.forEach(sameSite => { - const secureFlag = sameSite === 'None' ? ' Secure;' : ''; - document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; - document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; - }); + paths.forEach(path => { + // Basic clearing + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; + + // With domain + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; + + // Try different SameSite values + sameSiteValues.forEach(sameSite => { + const secureFlag = sameSite === 'None' ? ' Secure;' : ''; + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; + document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; }); }); console.log("After clearing cookies:", document.cookie); } -export function setAuthToken(token: string) { - // Generate a token name with current timestamp - const currentTimestamp = Math.floor(Date.now() / 1000); - const tokenName = `token_${currentTimestamp}`; - - // Set the cookie with the timestamp-based name - document.cookie = `${tokenName}=${token}; path=/; domain=${window.location.hostname};`; -} - -export function getAuthToken() { - // Check if we're in a browser environment - if (typeof window === 'undefined' || typeof document === 'undefined') { - return null; - } - - const tokenPattern = /^token_(\d+)$/; - const allCookies = document.cookie.split("; "); - - const tokenCookies = allCookies - .map(cookie => { - const parts = cookie.split("="); - const name = parts[0]; - - // Explicitly skip cookies named just "token" - if (name === "token") { - return null; - } - - // Only match cookies with the token_{timestamp} format - const match = name.match(tokenPattern); - if (match) { - return { - name, - timestamp: parseInt(match[1], 10), - value: parts.slice(1).join("=") - }; - } - return null; - }) - .filter((cookie): cookie is { name: string; timestamp: number; value: string } => cookie !== null); - - if (tokenCookies.length > 0) { - // Sort by timestamp (newest first) - tokenCookies.sort((a, b) => b.timestamp - a.timestamp); - return tokenCookies[0].value; - } - - return null; -} +/** + * Gets a cookie value by name + * @param name The name of the cookie to retrieve + * @returns The cookie value or null if not found + */ +export function getCookie(name: string) { + const cookieValue = document.cookie + .split('; ') + .find(row => row.startsWith(name + '=')); + return cookieValue ? cookieValue.split('=')[1] : null; +} \ No newline at end of file