From 4bafbc5c081045569acac07a02861908c06c4e83 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 20 Sep 2025 16:27:21 -0700 Subject: [PATCH] ui new build --- .../_buildManifest.js | 0 .../_ssgManifest.js | 0 .../{154-a64e60332235c8d7.js => 154-b1f2a106d0e0d77b.js} | 2 +- ...{layout-21dfaab0131d6703.js => layout-df4939b4f2ec37d7.js} | 2 +- .../{page-0dbadf20167b786c.js => page-13b00ef4a072d920.js} | 2 +- .../{page-f469bae327299fbb.js => page-304b7041a3fa39f7.js} | 2 +- .../{page-7828c2c64e97362a.js => page-d0d85032bb87ba51.js} | 2 +- .../out/_next/static/chunks/app/page-73b19c9fbf8cc64f.js | 1 + .../out/_next/static/chunks/app/page-bb7f38c1ba8189cf.js | 1 - ...n-app-4f7318ae681a6d94.js => main-app-bb35cb240fbb9dca.js} | 2 +- litellm/proxy/_experimental/out/index.html | 2 +- litellm/proxy/_experimental/out/index.txt | 4 ++-- litellm/proxy/_experimental/out/model_hub.txt | 4 ++-- .../out/{model_hub_table/index.html => model_hub_table.html} | 2 +- litellm/proxy/_experimental/out/model_hub_table.txt | 4 ++-- litellm/proxy/_experimental/out/onboarding.html | 1 + litellm/proxy/_experimental/out/onboarding.txt | 4 ++-- 17 files changed, 18 insertions(+), 17 deletions(-) rename litellm/proxy/_experimental/out/_next/static/{y_NiU8YZI67ST5KsTLGlv => 0oPk2eYtSaTLaPyVixqA8}/_buildManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/{y_NiU8YZI67ST5KsTLGlv => 0oPk2eYtSaTLaPyVixqA8}/_ssgManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/chunks/{154-a64e60332235c8d7.js => 154-b1f2a106d0e0d77b.js} (53%) rename litellm/proxy/_experimental/out/_next/static/chunks/app/{layout-21dfaab0131d6703.js => layout-df4939b4f2ec37d7.js} (59%) rename litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/{page-0dbadf20167b786c.js => page-13b00ef4a072d920.js} (63%) rename litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/{page-f469bae327299fbb.js => page-304b7041a3fa39f7.js} (69%) rename litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/{page-7828c2c64e97362a.js => page-d0d85032bb87ba51.js} (98%) create mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-73b19c9fbf8cc64f.js delete mode 100644 litellm/proxy/_experimental/out/_next/static/chunks/app/page-bb7f38c1ba8189cf.js rename litellm/proxy/_experimental/out/_next/static/chunks/{main-app-4f7318ae681a6d94.js => main-app-bb35cb240fbb9dca.js} (54%) rename litellm/proxy/_experimental/out/{model_hub_table/index.html => model_hub_table.html} (95%) create mode 100644 litellm/proxy/_experimental/out/onboarding.html diff --git a/litellm/proxy/_experimental/out/_next/static/y_NiU8YZI67ST5KsTLGlv/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/0oPk2eYtSaTLaPyVixqA8/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/y_NiU8YZI67ST5KsTLGlv/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/0oPk2eYtSaTLaPyVixqA8/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/y_NiU8YZI67ST5KsTLGlv/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/0oPk2eYtSaTLaPyVixqA8/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/y_NiU8YZI67ST5KsTLGlv/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/0oPk2eYtSaTLaPyVixqA8/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/154-a64e60332235c8d7.js b/litellm/proxy/_experimental/out/_next/static/chunks/154-b1f2a106d0e0d77b.js similarity index 53% rename from litellm/proxy/_experimental/out/_next/static/chunks/154-a64e60332235c8d7.js rename to litellm/proxy/_experimental/out/_next/static/chunks/154-b1f2a106d0e0d77b.js index 22ca25cae1..07c0d6f59e 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/154-a64e60332235c8d7.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/154-b1f2a106d0e0d77b.js @@ -1 +1 @@ -"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[154],{31283:function(e,t,o){o.d(t,{o:function(){return a.Z}});var a=o(49566)},63610:function(e,t,o){o.d(t,{d:function(){return h}});var a=o(57437),r=o(2265),n=o(64482),l=o(52787),c=o(20577),i=o(13634),s=o(31283),d=o(15424),u=o(89970),p=o(19250);let h=["metadata","config","enforced_params","aliases"],g=(e,t)=>h.includes(e)||"json"===t.format,m=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},f=(e,t,o)=>{let a={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"})[o]||"Text input";return g(e,t)?"".concat(a,"\nMust be valid JSON format"):t.enum?"Select from available options\nAllowed values: ".concat(t.enum.join(", ")):a};t.Z=e=>{let{schemaComponent:t,excludedFields:o=[],form:h,overrideLabels:w={},overrideTooltips:y={},customValidation:j={},defaultValues:_={}}=e,[C,k]=(0,r.useState)(null),[v,T]=(0,r.useState)(null);(0,r.useEffect)(()=>{(async()=>{try{let e=(await (0,p.getOpenAPISchema)()).components.schemas[t];if(!e)throw Error('Schema component "'.concat(t,'" not found'));k(e);let a={};Object.keys(e.properties).filter(e=>!o.includes(e)&&void 0!==_[e]).forEach(e=>{a[e]=_[e]}),h.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),T(e instanceof Error?e.message:"Failed to fetch schema")}})()},[t,h,o]);let E=e=>{if(e.type)return e.type;if(e.anyOf){let t=e.anyOf.map(e=>e.type);if(t.includes("number")||t.includes("integer"))return"number";t.includes("string")}return"string"},S=(e,t)=>{var o;let r;let p=E(t),h=null==C?void 0:null===(o=C.required)||void 0===o?void 0:o.includes(e),k=w[e]||t.title||e,v=y[e]||t.description,T=[];h&&T.push({required:!0,message:"".concat(k," is required")}),j[e]&&T.push({validator:j[e]}),g(e,t)&&T.push({validator:async(e,t)=>{if(t&&!m(t))throw Error("Please enter valid JSON")}});let S=v?(0,a.jsxs)("span",{children:[k," ",(0,a.jsx)(u.Z,{title:v,children:(0,a.jsx)(d.Z,{style:{marginLeft:"4px"}})})]}):k;return r=g(e,t)?(0,a.jsx)(n.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):t.enum?(0,a.jsx)(l.default,{children:t.enum.map(e=>(0,a.jsx)(l.default.Option,{value:e,children:e},e))}):"number"===p||"integer"===p?(0,a.jsx)(c.Z,{style:{width:"100%"},precision:"integer"===p?0:void 0}):"duration"===e?(0,a.jsx)(s.o,{placeholder:"eg: 30s, 30h, 30d"}):(0,a.jsx)(s.o,{placeholder:v||""}),(0,a.jsx)(i.Z.Item,{label:S,name:e,className:"mt-8",rules:T,initialValue:_[e],help:(0,a.jsx)("div",{className:"text-xs text-gray-500",children:f(e,t,p)}),children:r},e)};return v?(0,a.jsxs)("div",{className:"text-red-500",children:["Error: ",v]}):(null==C?void 0:C.properties)?(0,a.jsx)("div",{children:Object.entries(C.properties).filter(e=>{let[t]=e;return!o.includes(t)}).map(e=>{let[t,o]=e;return S(t,o)})}):null}},9114:function(e,t,o){var a=o(2265),r=o(57271),n=o(85968);function l(){return"topRight"}function c(e,t){var o;return"string"==typeof e?{message:t,description:e}:{message:null!==(o=e.message)&&void 0!==o?o:t,...e}}function i(e){return"number"==typeof e?e:"string"==typeof e&&/^\d+$/.test(e)?parseInt(e,10):void 0}let s=["invalid api key","invalid authorization header format","authentication error","invalid proxy server token","invalid jwt token","invalid jwt submitted","unauthorized access to metrics endpoint"],d=["admin-only endpoint","not allowed to access model","user does not have permission","access forbidden","invalid credentials used to access ui","user not allowed to access proxy"],u=["db not connected","database not initialized","no db connected","prisma client not initialized","service unhealthy"],p=["no models configured on proxy","llm router not initialized","no deployments available","no healthy deployment available","not allowed to access model due to tags configuration","invalid model name passed in"],h=["deployment over user-defined ratelimit","crossed tpm / rpm / max parallel request limit","max parallel request limit"],g=["budget exceeded","crossed budget","provider budget"],m=["must be a litellm enterprise user","only be available for liteLLM enterprise users","missing litellm-enterprise package","only available on the docker image","enterprise feature","premium user"],f=["invalid json payload","invalid request type","invalid key format","invalid hash key","invalid sort column","invalid sort order","invalid limit","invalid file type","invalid field","invalid date format"],w=["model not found","model with id","credential not found","user not found","team not found","organization not found","mcp server with id","tool '"],y=["already exists","team member is already in team","user already exists"],j=["violated openai moderation policy","violated jailbreak threshold","violated prompt_injection threshold","violated content safety policy","violated lasso guardrail policy","blocked by pillar security guardrail","violated azure prompt shield guardrail policy","content blocked by model armor","response blocked by model armor","streaming response blocked by model armor","guardrail","moderation"],_=["invalid purpose","service must be specified","invalid response - response.response is none"],C=["cloudzero settings not configured","failed to decrypt cloudzero api key","cloudzero settings not found"],k=["created successfully","updated successfully","deleted successfully","credential created successfully","model added successfully","team created successfully","user created successfully","organization created successfully","cloudzero settings initialized successfully","cloudzero settings updated successfully","cloudzero export completed successfully","mock llm request made","mock slack alert sent","mock email alert sent","spend for all api keys and teams reset successfully","monthlyglobalspend view refreshed","cache cleared successfully","cache set successfully","ip ","deleted successfully"],v=["rate limit reached for deployment","deployment cooldown period active"],T=["this feature is only available for litellm enterprise users","enterprise features are not available","regenerating virtual keys is an enterprise feature","trying to set allowed_routes. this is an enterprise feature"],E=["invalid maximum_spend_logs_retention_interval value","error has invalid or non-convertible code","failed to save health check to database"];t.Z={error(e){var t,o;let a=c(e,"Error");r.ZP.error({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:6})},warning(e){var t,o;let a=c(e,"Warning");r.ZP.warning({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:5})},info(e){var t,o;let a=c(e,"Info");r.ZP.info({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:4})},success(e){var t,o;if(a.isValidElement(e)){r.ZP.success({message:"Success",description:e,placement:l(),duration:3.5});return}let n=c(e,"Success");r.ZP.success({...n,placement:null!==(t=n.placement)&&void 0!==t?t:l(),duration:null!==(o=n.duration)&&void 0!==o?o:3.5})},fromBackend(e,t){var o,a,c,S,b,F,P,O,B,N,x,G;let J=null!==(G=null!==(x=i(null==e?void 0:null===(N=e.response)||void 0===N?void 0:N.status))&&void 0!==x?x:i(null==e?void 0:e.status_code))&&void 0!==G?G:i(null==e?void 0:e.code),A=function(e){var t,o,a,r,l,c,i,s,d,u,p,h;if("string"==typeof e)return e;let g=null!==(h=null!==(p=null!==(u=null!==(d=null!==(s=null==e?void 0:null===(a=e.response)||void 0===a?void 0:null===(o=a.data)||void 0===o?void 0:null===(t=o.error)||void 0===t?void 0:t.message)&&void 0!==s?s:null==e?void 0:null===(l=e.response)||void 0===l?void 0:null===(r=l.data)||void 0===r?void 0:r.message)&&void 0!==d?d:null==e?void 0:null===(i=e.response)||void 0===i?void 0:null===(c=i.data)||void 0===c?void 0:c.error)&&void 0!==u?u:null==e?void 0:e.detail)&&void 0!==p?p:null==e?void 0:e.message)&&void 0!==h?h:e;return(0,n.O)(g)}(e),U={...null!=t?t:{},description:A,placement:null!==(o=null==t?void 0:t.placement)&&void 0!==o?o:l()};if(void 0!==J||e instanceof Error||"string"==typeof e||e&&"object"==typeof e&&("error"in e||"detail"in e)){let e=function(e,t){var o,a,r,n,l;let c=(t||"").toLowerCase();return s.some(e=>c.includes(e))?"Authentication Error":d.some(e=>c.includes(e))?"Access Denied":(null==u?void 0:null===(o=u.some)||void 0===o?void 0:o.call(u,e=>c.includes(e)))||503===e?"Service Unavailable":(null==g?void 0:null===(a=g.some)||void 0===a?void 0:a.call(g,e=>c.includes(e)))?"Budget Exceeded":(null==m?void 0:null===(r=m.some)||void 0===r?void 0:r.call(m,e=>c.includes(e)))?"Feature Unavailable":(null==p?void 0:null===(n=p.some)||void 0===n?void 0:n.call(p,e=>c.includes(e)))?"Routing Error":y.some(e=>c.includes(e))?"Already Exists":j.some(e=>c.includes(e))?"Content Blocked":_.some(e=>c.includes(e))?"Validation Error":C.some(e=>c.includes(e))?"Integration Error":f.some(e=>c.includes(e))?"Validation Error":404===e||c.includes("not found")||w.some(e=>c.includes(e))?"Not Found":429===e||c.includes("rate limit")||c.includes("tpm")||c.includes("rpm")||(null==h?void 0:null===(l=h.some)||void 0===l?void 0:l.call(h,e=>c.includes(e)))?"Rate Limit Exceeded":e&&e>=500?"Server Error":401===e?"Authentication Error":403===e?"Access Denied":c.includes("enterprise")||c.includes("premium")?"Info":e&&e>=400?"Request Error":"Error"}(J,A),o={...U,message:e};if("Rate Limit Exceeded"===e||"Info"===e||"Budget Exceeded"===e||"Feature Unavailable"===e||"Content Blocked"===e||"Integration Error"===e){r.ZP.warning({...o,duration:null!==(a=null==t?void 0:t.duration)&&void 0!==a?a:7});return}if("Server Error"===e){r.ZP.error({...o,duration:null!==(c=null==t?void 0:t.duration)&&void 0!==c?c:8});return}if("Request Error"===e||"Authentication Error"===e||"Access Denied"===e||"Not Found"===e||"Error"===e){r.ZP.error({...o,duration:null!==(S=null==t?void 0:t.duration)&&void 0!==S?S:6});return}r.ZP.info({...o,duration:null!==(b=null==t?void 0:t.duration)&&void 0!==b?b:4});return}let R=function(e){let t=(e||"").toLowerCase();return k.some(e=>t.includes(e))?{kind:"success",title:"Success"}:T.some(e=>t.includes(e))?{kind:"warning",title:"Feature Notice"}:E.some(e=>t.includes(e))?{kind:"warning",title:"Configuration Warning"}:v.some(e=>t.includes(e))?{kind:"warning",title:"Rate Limit"}:null}(A),I={...U,message:null!==(F=null==R?void 0:R.title)&&void 0!==F?F:"Info"};if((null==R?void 0:R.kind)==="success"){r.ZP.success({...I,duration:null!==(P=null==t?void 0:t.duration)&&void 0!==P?P:3.5});return}if((null==R?void 0:R.kind)==="warning"){r.ZP.warning({...I,duration:null!==(O=null==t?void 0:t.duration)&&void 0!==O?O:6});return}r.ZP.info({...I,duration:null!==(B=null==t?void 0:t.duration)&&void 0!==B?B:4})},clear(){r.ZP.destroy()}}},19250:function(e,t,o){o.r(t),o.d(t,{DEFAULT_ORGANIZATION:function(){return h},PredictedSpendLogsCall:function(){return tl},addAllowedIP:function(){return em},adminGlobalActivity:function(){return eJ},adminGlobalActivityExceptions:function(){return eR},adminGlobalActivityExceptionsPerDeployment:function(){return eI},adminGlobalActivityPerModel:function(){return eU},adminGlobalCacheActivity:function(){return eA},adminSpendLogsCall:function(){return eB},adminTopEndUsersCall:function(){return ex},adminTopKeysCall:function(){return eN},adminTopModelsCall:function(){return eM},adminspendByProvider:function(){return eG},alertingSettingsCall:function(){return A},allEndUsersCall:function(){return eb},allTagNamesCall:function(){return eS},availableTeamListCall:function(){return W},budgetCreateCall:function(){return N},budgetDeleteCall:function(){return B},budgetUpdateCall:function(){return x},cachingHealthCheckCall:function(){return tv},callMCPTool:function(){return tZ},cancelModelCostMapReload:function(){return S},claimOnboardingToken:function(){return el},convertPromptFileToJson:function(){return tx},createGuardrailCall:function(){return tJ},createMCPServer:function(){return tz},createPassThroughEndpoint:function(){return tf},createPromptCall:function(){return tO},credentialCreateCall:function(){return eQ},credentialDeleteCall:function(){return e1},credentialGetCall:function(){return e0},credentialListCall:function(){return eX},credentialUpdateCall:function(){return e2},defaultProxyBaseUrl:function(){return c},deleteAllowedIP:function(){return ef},deleteCallback:function(){return ou},deleteConfigFieldSetting:function(){return ty},deleteGuardrailCall:function(){return oe},deleteMCPServer:function(){return tD},deletePassThroughEndpointsCall:function(){return tj},deletePromptCall:function(){return tN},fetchMCPAccessGroups:function(){return tM},fetchMCPServers:function(){return tI},formatDate:function(){return l},getAllowedIPs:function(){return eg},getBudgetList:function(){return ts},getBudgetSettings:function(){return td},getCallbacksCall:function(){return tu},getConfigFieldSetting:function(){return tg},getDefaultTeamSettings:function(){return t$},getEmailEventSettings:function(){return t7},getGeneralSettingsCall:function(){return tp},getGuardrailInfo:function(){return oa},getGuardrailProviderSpecificParams:function(){return oo},getGuardrailUISettings:function(){return ot},getGuardrailsList:function(){return tb},getInternalUserSettings:function(){return tU},getModelCostMapReloadStatus:function(){return b},getOnboardingCredentials:function(){return en},getOpenAPISchema:function(){return k},getPassThroughEndpointInfo:function(){return od},getPassThroughEndpointsCall:function(){return th},getPossibleUserRoles:function(){return eK},getPromptInfo:function(){return tP},getPromptsList:function(){return tF},getProxyBaseUrl:function(){return u},getProxyUISettings:function(){return tS},getPublicModelHubInfo:function(){return C},getRemainingUsers:function(){return oi},getSSOSettings:function(){return on},getTeamPermissionsCall:function(){return tX},getTotalSpendCall:function(){return er},getUiConfig:function(){return _},healthCheckCall:function(){return tC},healthCheckHistoryCall:function(){return tT},individualModelHealthCheckCall:function(){return tk},invitationClaimCall:function(){return J},invitationCreateCall:function(){return G},keyCreateCall:function(){return R},keyCreateServiceAccountCall:function(){return U},keyDeleteCall:function(){return M},keyInfoCall:function(){return ez},keyInfoV1Call:function(){return eD},keyListCall:function(){return eV},keySpendLogsCall:function(){return ev},keyUpdateCall:function(){return e4},latestHealthChecksCall:function(){return tE},listMCPTools:function(){return tV},makeModelGroupPublic:function(){return j},mcpToolsCall:function(){return op},modelAvailableCall:function(){return ek},modelCostMap:function(){return v},modelCreateCall:function(){return F},modelDeleteCall:function(){return O},modelExceptionsCall:function(){return e_},modelHubCall:function(){return eh},modelHubPublicModelsCall:function(){return ep},modelInfoCall:function(){return ed},modelInfoV1Call:function(){return eu},modelMetricsCall:function(){return ew},modelMetricsSlowResponsesCall:function(){return ej},modelPatchUpdateCall:function(){return e5},modelSettingsCall:function(){return P},modelUpdateCall:function(){return e6},organizationCreateCall:function(){return $},organizationDeleteCall:function(){return X},organizationInfoCall:function(){return K},organizationListCall:function(){return Y},organizationMemberAddCall:function(){return tt},organizationMemberDeleteCall:function(){return to},organizationMemberUpdateCall:function(){return ta},organizationUpdateCall:function(){return Q},patchPromptCall:function(){return tG},perUserAnalyticsCall:function(){return ok},proxyBaseUrl:function(){return s},regenerateKeyCall:function(){return ec},reloadModelCostMap:function(){return T},resetEmailEventSettings:function(){return t8},scheduleModelCostMapReload:function(){return E},serverRootPath:function(){return i},serviceHealthCheck:function(){return ti},sessionSpendLogsCall:function(){return t1},setCallbacksCall:function(){return t_},setGlobalLitellmHeaderName:function(){return y},slackBudgetAlertsHealthCheck:function(){return tc},spendUsersCall:function(){return eZ},streamingModelMetricsCall:function(){return ey},tagCreateCall:function(){return tq},tagDailyActivityCall:function(){return eo},tagDauCall:function(){return ow},tagDeleteCall:function(){return tK},tagDistinctCall:function(){return o_},tagInfoCall:function(){return tW},tagListCall:function(){return tY},tagMauCall:function(){return oj},tagUpdateCall:function(){return tH},tagWauCall:function(){return oy},tagsSpendLogsCall:function(){return eE},teamBulkMemberAddCall:function(){return e9},teamCreateCall:function(){return e$},teamDailyActivityCall:function(){return ea},teamDeleteCall:function(){return L},teamInfoCall:function(){return Z},teamListCall:function(){return H},teamMemberAddCall:function(){return e7},teamMemberDeleteCall:function(){return te},teamMemberUpdateCall:function(){return e8},teamPermissionsUpdateCall:function(){return t0},teamSpendLogsCall:function(){return eT},teamUpdateCall:function(){return e3},testConnectionRequest:function(){return eL},testMCPConnectionRequest:function(){return oh},testMCPToolsListRequest:function(){return og},transformRequestCall:function(){return ee},uiAuditLogsCall:function(){return oc},uiSpendLogDetailsCall:function(){return tA},uiSpendLogsCall:function(){return eO},updateConfigFieldSetting:function(){return tw},updateDefaultTeamSettings:function(){return tQ},updateEmailEventSettings:function(){return t9},updateGuardrailCall:function(){return or},updateInternalUserSettings:function(){return tR},updateMCPServer:function(){return tL},updatePassThroughEndpoint:function(){return os},updatePassThroughFieldSetting:function(){return tm},updatePromptCall:function(){return tB},updateSSOSettings:function(){return ol},updateUsefulLinksCall:function(){return eC},userAgentAnalyticsCall:function(){return of},userAgentSummaryCall:function(){return oC},userBulkUpdateUserCall:function(){return tn},userCreateCall:function(){return I},userDailyActivityAggregatedCall:function(){return eW},userDailyActivityCall:function(){return et},userDeleteCall:function(){return z},userFilterUICall:function(){return eF},userGetAllUsersCall:function(){return eY},userGetRequesedtModelsCall:function(){return eH},userInfoCall:function(){return V},userListCall:function(){return D},userRequestModelCall:function(){return eq},userSpendLogsCall:function(){return eP},userUpdateUserCall:function(){return tr},v2TeamListCall:function(){return q},vectorStoreCreateCall:function(){return t2},vectorStoreDeleteCall:function(){return t3},vectorStoreInfoCall:function(){return t5},vectorStoreListCall:function(){return t4},vectorStoreSearchCall:function(){return om},vectorStoreUpdateCall:function(){return t6}});var a=o(42264),r=o(63610),n=o(9114);let l=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)},c=null,i="/",s=null;console.log=function(){};let d=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=window.location.origin,a=t||o;console.log("proxyBaseUrl:",s),console.log("serverRootPath:",e),e.length>0&&!a.endsWith(e)&&"/"!=e&&(a+=e,s=a),console.log("Updated proxyBaseUrl:",s)},u=()=>s||window.location.origin,p={GET:"GET",DELETE:"DELETE"},h="default_organization",g=0,m=async e=>{let t=Date.now();t-g>6e4?(e.includes("Authentication Error - Expired Key")&&(n.Z.info("UI Session Expired. Logging out."),g=t,document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=window.location.pathname),g=t):console.log("Error suppressed to prevent spam:",e)},f="Authorization",w="x-mcp-auth";function y(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Authorization";console.log("setGlobalLitellmHeaderName: ".concat(e)),f=e}let j=async(e,t)=>{let o=s?"".concat(s,"/model_group/make_public"):"/model_group/make_public";return(await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({model_groups:t})})).json()},_=async()=>{console.log("Getting UI config");let e=await fetch(c?"".concat(c,"/litellm/.well-known/litellm-ui-config"):"/litellm/.well-known/litellm-ui-config"),t=await e.json();return console.log("jsonData in getUiConfig:",t),d(t.server_root_path,t.proxy_base_url),t},C=async()=>{let e=await fetch(c?"".concat(c,"/public/model_hub/info"):"/public/model_hub/info");return await e.json()},k=async()=>{let e=s?"".concat(s,"/openapi.json"):"/openapi.json",t=await fetch(e);return await t.json()},v=async e=>{try{let t=s?"".concat(s,"/get/litellm_model_cost_map"):"/get/litellm_model_cost_map",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("received litellm model cost data: ".concat(a)),a}catch(e){throw console.error("Failed to get model cost map:",e),e}},T=async e=>{try{let t=s?"".concat(s,"/reload/model_cost_map"):"/reload/model_cost_map",o=await fetch(t,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("Model cost map reload response: ".concat(a)),a}catch(e){throw console.error("Failed to reload model cost map:",e),e}},E=async(e,t)=>{try{let o=s?"".concat(s,"/schedule/model_cost_map_reload?hours=").concat(t):"/schedule/model_cost_map_reload?hours=".concat(t),a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),r=await a.json();return console.log("Schedule model cost map reload response: ".concat(r)),r}catch(e){throw console.error("Failed to schedule model cost map reload:",e),e}},S=async e=>{try{let t=s?"".concat(s,"/schedule/model_cost_map_reload"):"/schedule/model_cost_map_reload",o=await fetch(t,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("Cancel model cost map reload response: ".concat(a)),a}catch(e){throw console.error("Failed to cancel model cost map reload:",e),e}},b=async e=>{try{let t=s?"".concat(s,"/schedule/model_cost_map_reload/status"):"/schedule/model_cost_map_reload/status";console.log("Fetching status from URL:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){console.error("Status request failed with status: ".concat(o.status));let e=await o.text();throw console.error("Error response:",e),Error("HTTP ".concat(o.status,": ").concat(e))}let a=await o.json();return console.log("Model cost map reload status:",a),a}catch(e){throw console.error("Failed to get model cost map reload status:",e),e}},F=async(e,t)=>{try{let o=s?"".concat(s,"/model/new"):"/model/new",r=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return console.log("API Response:",l),a.ZP.destroy(),n.Z.success("Model ".concat(t.model_name," created successfully")),l}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let t=s?"".concat(s,"/model/settings"):"/model/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){console.error("Failed to get model settings:",e)}},O=async(e,t)=>{console.log("model_id in model delete call: ".concat(t));try{let o=s?"".concat(s,"/model/delete"):"/model/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},B=async(e,t)=>{if(console.log("budget_id in budget delete call: ".concat(t)),null!=e)try{let o=s?"".concat(s,"/budget/delete"):"/budget/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},N=async(e,t)=>{try{console.log("Form Values in budgetCreateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/budget/new"):"/budget/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},x=async(e,t)=>{try{console.log("Form Values in budgetUpdateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/budget/update"):"/budget/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},G=async(e,t)=>{try{let o=s?"".concat(s,"/invitation/new"):"/invitation/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},J=async(e,t)=>{try{console.log("Form Values in invitationCreateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/invitation/claim"):"/invitation/claim",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},A=async e=>{try{let t=s?"".concat(s,"/alerting/settings"):"/alerting/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},U=async(e,t)=>{try{for(let e of(console.log("Form Values in keyCreateServiceAccountCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),r.d))if(t[e]){console.log("formValues.".concat(e,":"),t[e]);try{t[e]=JSON.parse(t[e])}catch(t){throw Error("Failed to parse ".concat(e,": ")+t)}}console.log("Form Values after check:",t);let o=s?"".concat(s,"/key/service-account/generate"):"/key/service-account/generate",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await a.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},R=async(e,t,o)=>{try{for(let e of(console.log("Form Values in keyCreateCall:",o),o.description&&(o.metadata||(o.metadata={}),o.metadata.description=o.description,delete o.description,o.metadata=JSON.stringify(o.metadata)),r.d))if(o[e]){console.log("formValues.".concat(e,":"),o[e]);try{o[e]=JSON.parse(o[e])}catch(t){throw Error("Failed to parse ".concat(e,": ")+t)}}console.log("Form Values after check:",o);let a=s?"".concat(s,"/key/generate"):"/key/generate",n=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...o})});if(!n.ok){let e=await n.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},I=async(e,t,o)=>{try{if(console.log("Form Values in keyCreateCall:",o),o.description&&(o.metadata||(o.metadata={}),o.metadata.description=o.description,delete o.description,o.metadata=JSON.stringify(o.metadata)),o.auto_create_key=!1,o.metadata){console.log("formValues.metadata:",o.metadata);try{o.metadata=JSON.parse(o.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",o);let a=s?"".concat(s,"/user/new"):"/user/new",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...o})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},M=async(e,t)=>{try{let o=s?"".concat(s,"/key/delete"):"/key/delete";console.log("in keyDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},z=async(e,t)=>{try{let o=s?"".concat(s,"/user/delete"):"/user/delete";console.log("in userDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_ids:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete user(s):",e),e}},L=async(e,t)=>{try{let o=s?"".concat(s,"/team/delete"):"/team/delete";console.log("in teamDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[t]})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete key:",e),e}},D=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:null,i=arguments.length>8&&void 0!==arguments[8]?arguments[8]:null,d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:null;try{let u=s?"".concat(s,"/user/list"):"/user/list";console.log("in userListCall");let p=new URLSearchParams;if(t&&t.length>0){let e=t.join(",");p.append("user_ids",e)}o&&p.append("page",o.toString()),a&&p.append("page_size",a.toString()),r&&p.append("user_email",r),n&&p.append("role",n),l&&p.append("team",l),c&&p.append("sso_user_ids",c),i&&p.append("sort_by",i),d&&p.append("sort_order",d);let h=p.toString();h&&(u+="?".concat(h));let g=await fetch(u,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!g.ok){let e=await g.json(),t=ov(e);throw m(t),Error(t)}let w=await g.json();return console.log("/user/list API Response:",w),w}catch(e){throw console.error("Failed to create key:",e),e}},V=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=arguments.length>4?arguments[4]:void 0,n=arguments.length>5?arguments[5]:void 0,l=arguments.length>6&&void 0!==arguments[6]&&arguments[6];console.log("userInfoCall: ".concat(t,", ").concat(o,", ").concat(a,", ").concat(r,", ").concat(n,", ").concat(l));try{let c;if(a){c=s?"".concat(s,"/user/list"):"/user/list";let e=new URLSearchParams;null!=r&&e.append("page",r.toString()),null!=n&&e.append("page_size",n.toString()),c+="?".concat(e.toString())}else c=s?"".concat(s,"/user/info"):"/user/info",("Admin"!==o&&"Admin Viewer"!==o||l)&&t&&(c+="?user_id=".concat(t));console.log("Requesting user data from:",c);let i=await fetch(c,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("API Response:",d),d}catch(e){throw console.error("Failed to fetch user data:",e),e}},Z=async(e,t)=>{try{let o=s?"".concat(s,"/team/info"):"/team/info";t&&(o="".concat(o,"?team_id=").concat(t)),console.log("in teamInfoCall");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;arguments.length>5&&void 0!==arguments[5]&&arguments[5],arguments.length>6&&void 0!==arguments[6]&&arguments[6],arguments.length>7&&void 0!==arguments[7]&&arguments[7],arguments.length>8&&void 0!==arguments[8]&&arguments[8];try{let n=s?"".concat(s,"/v2/team/list"):"/v2/team/list";console.log("in teamInfoCall");let l=new URLSearchParams;o&&l.append("user_id",o.toString()),t&&l.append("organization_id",t.toString()),a&&l.append("team_id",a.toString()),r&&l.append("team_alias",r.toString());let c=l.toString();c&&(n+="?".concat(c));let i=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("/v2/team/list API Response:",d),d}catch(e){throw console.error("Failed to create key:",e),e}},H=async function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/team/list"):"/team/list";console.log("in teamInfoCall");let l=new URLSearchParams;o&&l.append("user_id",o.toString()),t&&l.append("organization_id",t.toString()),a&&l.append("team_id",a.toString()),r&&l.append("team_alias",r.toString());let c=l.toString();c&&(n+="?".concat(c));let i=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("/team/list API Response:",d),d}catch(e){throw console.error("Failed to create key:",e),e}},W=async e=>{try{let t=s?"".concat(s,"/team/available"):"/team/available";console.log("in availableTeamListCall");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("/team/available_teams API Response:",a),a}catch(e){throw e}},Y=async e=>{try{let t=s?"".concat(s,"/organization/list"):"/organization/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,t)=>{try{let o=s?"".concat(s,"/organization/info"):"/organization/info";t&&(o="".concat(o,"?organization_id=").concat(t)),console.log("in teamInfoCall");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},$=async(e,t)=>{try{if(console.log("Form Values in organizationCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw console.error("Failed to parse metadata:",e),Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/organization/new"):"/organization/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},Q=async(e,t)=>{try{console.log("Form Values in organizationUpdateCall:",t);let o=s?"".concat(s,"/organization/update"):"/organization/update",a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Update Team Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},X=async(e,t)=>{try{let o=s?"".concat(s,"/organization/delete"):"/organization/delete",a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_ids:[t]})});if(!a.ok){let e=await a.text();throw m(e),Error("Error deleting organization: ".concat(e))}return await a.json()}catch(e){throw console.error("Failed to delete organization:",e),e}},ee=async(e,t)=>{try{let o=s?"".concat(s,"/utils/transform_request"):"/utils/transform_request",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},et=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;try{let r=s?"".concat(s,"/user/daily/activity"):"/user/daily/activity",n=new URLSearchParams;n.append("start_date",l(t)),n.append("end_date",l(o)),n.append("page_size","1000"),n.append("page",a.toString());let c=n.toString();c&&(r+="?".concat(c));let i=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}return await i.json()}catch(e){throw console.error("Failed to create key:",e),e}},eo=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/tag/daily/activity"):"/tag/daily/activity",c=new URLSearchParams;c.append("start_date",l(t)),c.append("end_date",l(o)),c.append("page_size","1000"),c.append("page",a.toString()),r&&c.append("tags",r.join(","));let i=c.toString();i&&(n+="?".concat(i));let d=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!d.ok){let e=await d.json(),t=ov(e);throw m(t),Error(t)}return await d.json()}catch(e){throw console.error("Failed to create key:",e),e}},ea=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/team/daily/activity"):"/team/daily/activity",c=new URLSearchParams;c.append("start_date",l(t)),c.append("end_date",l(o)),c.append("page_size","1000"),c.append("page",a.toString()),r&&c.append("team_ids",r.join(",")),c.append("exclude_team_ids","litellm-dashboard");let i=c.toString();i&&(n+="?".concat(i));let d=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!d.ok){let e=await d.json(),t=ov(e);throw m(t),Error(t)}return await d.json()}catch(e){throw console.error("Failed to create key:",e),e}},er=async e=>{try{let t=s?"".concat(s,"/global/spend"):"/global/spend",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},en=async e=>{try{let t=s?"".concat(s,"/onboarding/get_token"):"/onboarding/get_token";t+="?invite_link=".concat(e);let o=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},el=async(e,t,o,a)=>{let r=s?"".concat(s,"/onboarding/claim_token"):"/onboarding/claim_token";try{let n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({invitation_link:t,user_id:o,password:a})});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to delete key:",e),e}},ec=async(e,t,o)=>{try{let a=s?"".concat(s,"/key/").concat(t,"/regenerate"):"/key/".concat(t,"/regenerate"),r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Regenerate key Response:",n),n}catch(e){throw console.error("Failed to regenerate key:",e),e}},ei=!1,es=null,ed=async(e,t,o)=>{try{console.log("modelInfoCall:",e,t,o);let a=s?"".concat(s,"/v2/model/info"):"/v2/model/info",r=new URLSearchParams;r.append("include_team_models","true"),r.toString()&&(a+="?".concat(r.toString()));let l=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw e+="error shown=".concat(ei),ei||(e.includes("No model list passed")&&(e="No Models Exist. Click Add Model to get started."),n.Z.info(e),ei=!0,es&&clearTimeout(es),es=setTimeout(()=>{ei=!1},1e4)),Error("Network response was not ok")}let c=await l.json();return console.log("modelInfoCall:",c),c}catch(e){throw console.error("Failed to create key:",e),e}},eu=async(e,t)=>{try{let o=s?"".concat(s,"/v1/model/info"):"/v1/model/info";o+="?litellm_model_id=".concat(t);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("modelInfoV1Call:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},ep=async()=>{let e=s?"".concat(s,"/public/model_hub"):"/public/model_hub";return(await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}})).json()},eh=async e=>{try{let t=s?"".concat(s,"/model_group/info"):"/model_group/info",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("modelHubCall:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},eg=async e=>{try{let t=s?"".concat(s,"/get/allowed_ips"):"/get/allowed_ips",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("getAllowedIPs:",a),a.data}catch(e){throw console.error("Failed to get allowed IPs:",e),e}},em=async(e,t)=>{try{let o=s?"".concat(s,"/add/allowed_ip"):"/add/allowed_ip",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({ip:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("addAllowedIP:",r),r}catch(e){throw console.error("Failed to add allowed IP:",e),e}},ef=async(e,t)=>{try{let o=s?"".concat(s,"/delete/allowed_ip"):"/delete/allowed_ip",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({ip:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("deleteAllowedIP:",r),r}catch(e){throw console.error("Failed to delete allowed IP:",e),e}},ew=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics"):"/model/metrics";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},ey=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/model/streaming_metrics"):"/model/streaming_metrics";t&&(r="".concat(r,"?_selected_model_group=").concat(t,"&startTime=").concat(o,"&endTime=").concat(a));let n=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}return await n.json()}catch(e){throw console.error("Failed to create key:",e),e}},ej=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics/slow_responses"):"/model/metrics/slow_responses";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},e_=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics/exceptions"):"/model/metrics/exceptions";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},eC=async(e,t)=>{try{let o=s?"".concat(s,"/model_hub/update_useful_links"):"/model_hub/update_useful_links",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({useful_links:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},ek=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,n=(arguments.length>5&&void 0!==arguments[5]&&arguments[5],arguments.length>6&&void 0!==arguments[6]&&arguments[6]);console.log("in /models calls, globalLitellmHeaderName",f);try{let t=s?"".concat(s,"/models"):"/models",o=new URLSearchParams;o.append("include_model_access_groups","True"),!0===a&&o.append("return_wildcard_routes","True"),!0===n&&o.append("only_model_access_groups","True"),r&&o.append("team_id",r.toString()),o.toString()&&(t+="?".concat(o.toString()));let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},ev=async(e,t)=>{try{let o=s?"".concat(s,"/global/spend/logs"):"/global/spend/logs";console.log("in keySpendLogsCall:",o);let a=await fetch("".concat(o,"?api_key=").concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},eT=async e=>{try{let t=s?"".concat(s,"/global/spend/teams"):"/global/spend/teams";console.log("in teamSpendLogsCall:",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eE=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/tags"):"/global/spend/tags";t&&o&&(r="".concat(r,"?start_date=").concat(t,"&end_date=").concat(o)),a&&(r+="".concat(r,"&tags=").concat(a.join(","))),console.log("in tagsSpendLogsCall:",r);let n=await fetch("".concat(r),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},eS=async e=>{try{let t=s?"".concat(s,"/global/spend/all_tag_names"):"/global/spend/all_tag_names";console.log("in global/spend/all_tag_names call",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eb=async e=>{try{let t=s?"".concat(s,"/global/all_end_users"):"/global/all_end_users";console.log("in global/all_end_users call",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eF=async(e,t)=>{try{let o=s?"".concat(s,"/user/filter/ui"):"/user/filter/ui";t.get("user_email")&&(o+="?user_email=".concat(t.get("user_email"))),t.get("user_id")&&(o+="?user_id=".concat(t.get("user_id")));let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},eP=async(e,t,o,a,r,n)=>{try{console.log("user role in spend logs call: ".concat(o));let t=s?"".concat(s,"/spend/logs"):"/spend/logs";t="App Owner"==o?"".concat(t,"?user_id=").concat(a,"&start_date=").concat(r,"&end_date=").concat(n):"".concat(t,"?start_date=").concat(r,"&end_date=").concat(n);let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to create key:",e),e}},eO=async(e,t,o,a,r,n,l,c,i,d,u,p,h)=>{try{let g=s?"".concat(s,"/spend/logs/ui"):"/spend/logs/ui",w=new URLSearchParams;t&&w.append("api_key",t),o&&w.append("team_id",o),a&&w.append("request_id",a),r&&w.append("start_date",r),n&&w.append("end_date",n),l&&w.append("page",l.toString()),c&&w.append("page_size",c.toString()),i&&w.append("user_id",i),d&&w.append("end_user",d),u&&w.append("status_filter",u),p&&w.append("model",p),h&&w.append("key_alias",h);let y=w.toString();y&&(g+="?".concat(y));let j=await fetch(g,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!j.ok){let e=await j.json(),t=ov(e);throw m(t),Error(t)}let _=await j.json();return console.log("Spend Logs Response:",_),_}catch(e){throw console.error("Failed to fetch spend logs:",e),e}},eB=async e=>{try{let t=s?"".concat(s,"/global/spend/logs"):"/global/spend/logs",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eN=async e=>{try{let t=s?"".concat(s,"/global/spend/keys?limit=5"):"/global/spend/keys?limit=5",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},ex=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/end_users"):"/global/spend/end_users",n="";n=t?JSON.stringify({api_key:t,startTime:o,endTime:a}):JSON.stringify({startTime:o,endTime:a});let l={method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:n},c=await fetch(r,l);if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}let i=await c.json();return console.log(i),i}catch(e){throw console.error("Failed to create key:",e),e}},eG=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/provider"):"/global/spend/provider";o&&a&&(r+="?start_date=".concat(o,"&end_date=").concat(a)),t&&(r+="&api_key=".concat(t));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eJ=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity"):"/global/activity";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eA=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity/cache_hits"):"/global/activity/cache_hits";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eU=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity/model"):"/global/activity/model";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eR=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/activity/exceptions"):"/global/activity/exceptions";t&&o&&(r+="?start_date=".concat(t,"&end_date=").concat(o)),a&&(r+="&model_group=".concat(a));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eI=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/activity/exceptions/deployment"):"/global/activity/exceptions/deployment";t&&o&&(r+="?start_date=".concat(t,"&end_date=").concat(o)),a&&(r+="&model_group=".concat(a));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eM=async e=>{try{let t=s?"".concat(s,"/global/spend/models?limit=5"):"/global/spend/models?limit=5",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},ez=async(e,t)=>{try{let o=s?"".concat(s,"/v2/key/info"):"/v2/key/info",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:t})});if(!a.ok){let e=await a.text();if(e.includes("Invalid proxy server token passed"))throw Error("Invalid proxy server token passed");throw m(e),Error("Network response was not ok")}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},eL=async(e,t,o)=>{try{console.log("Sending model connection test request:",JSON.stringify(t));let r=s?"".concat(s,"/health/test_connection"):"/health/test_connection",n=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify({litellm_params:t,mode:o})}),l=n.headers.get("content-type");if(!l||!l.includes("application/json")){let e=await n.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(n.status,": ").concat(n.statusText,"). Check network tab for details."))}let c=await n.json();if(!n.ok||"error"===c.status){if("error"===c.status);else{var a;return{status:"error",message:(null===(a=c.error)||void 0===a?void 0:a.message)||"Connection test failed: ".concat(n.status," ").concat(n.statusText)}}}return c}catch(e){throw console.error("Model connection test error:",e),e}},eD=async(e,t)=>{try{console.log("entering keyInfoV1Call");let o=s?"".concat(s,"/key/info"):"/key/info";o="".concat(o,"?key=").concat(t);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(console.log("response",a),!a.ok){let e=await a.text();m(e),n.Z.fromBackend("Failed to fetch key info - "+e)}let r=await a.json();return console.log("data",r),r}catch(e){throw console.error("Failed to fetch key info:",e),e}},eV=async function(e,t,o,a,r,n,l,c){let i=arguments.length>8&&void 0!==arguments[8]?arguments[8]:null,d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:null;try{let u=s?"".concat(s,"/key/list"):"/key/list";console.log("in keyListCall");let p=new URLSearchParams;o&&p.append("team_id",o.toString()),t&&p.append("organization_id",t.toString()),a&&p.append("key_alias",a),n&&p.append("key_hash",n),r&&p.append("user_id",r.toString()),l&&p.append("page",l.toString()),c&&p.append("size",c.toString()),i&&p.append("sort_by",i),d&&p.append("sort_order",d),p.append("return_full_object","true"),p.append("include_team_keys","true"),p.append("include_created_by_keys","true");let h=p.toString();h&&(u+="?".concat(h));let g=await fetch(u,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!g.ok){let e=await g.json(),t=ov(e);throw m(t),Error(t)}let w=await g.json();return console.log("/team/list API Response:",w),w}catch(e){throw console.error("Failed to create key:",e),e}},eZ=async(e,t)=>{try{let o=s?"".concat(s,"/spend/users"):"/spend/users";console.log("in spendUsersCall:",o);let a=await fetch("".concat(o,"?user_id=").concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to get spend for user",e),e}},eq=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/user/request_model"):"/user/request_model",n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({models:[t],user_id:o,justification:a})});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},eH=async e=>{try{let t=s?"".concat(s,"/user/get_requests"):"/user/get_requests";console.log("in userGetRequesedtModelsCall:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to get requested models:",e),e}},eW=async(e,t,o)=>{try{let a=s?"".concat(s,"/user/daily/activity/aggregated"):"/user/daily/activity/aggregated",r=new URLSearchParams,n=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};r.append("start_date",n(t)),r.append("end_date",n(o));let l=r.toString();l&&(a+="?".concat(l));let c=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch aggregated user daily activity:",e),e}},eY=async(e,t)=>{try{let o=s?"".concat(s,"/user/get_users?role=").concat(t):"/user/get_users?role=".concat(t);console.log("in userGetAllUsersCall:",o);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to get requested models:",e),e}},eK=async e=>{try{let t=s?"".concat(s,"/user/available_roles"):"/user/available_roles",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("response from user/available_role",a),a}catch(e){throw e}},e$=async(e,t)=>{try{if(console.log("Form Values in teamCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/team/new"):"/team/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},eQ=async(e,t)=>{try{if(console.log("Form Values in credentialCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/credentials"):"/credentials",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},eX=async e=>{try{let t=s?"".concat(s,"/credentials"):"/credentials";console.log("in credentialListCall");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("/credentials API Response:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},e0=async(e,t,o)=>{try{let a=s?"".concat(s,"/credentials"):"/credentials";t?a+="/by_name/".concat(t):o&&(a+="/by_model/".concat(o)),console.log("in credentialListCall");let r=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("/credentials API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},e1=async(e,t)=>{try{let o=s?"".concat(s,"/credentials/").concat(t):"/credentials/".concat(t);console.log("in credentialDeleteCall:",t);let a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete key:",e),e}},e2=async(e,t,o)=>{try{if(console.log("Form Values in credentialUpdateCall:",o),o.metadata){console.log("formValues.metadata:",o.metadata);try{o.metadata=JSON.parse(o.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let a=s?"".concat(s,"/credentials/").concat(t):"/credentials/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},e4=async(e,t)=>{try{if(console.log("Form Values in keyUpdateCall:",t),t.model_tpm_limit){console.log("formValues.model_tpm_limit:",t.model_tpm_limit);try{t.model_tpm_limit=JSON.parse(t.model_tpm_limit)}catch(e){throw Error("Failed to parse model_tpm_limit: "+e)}}if(t.model_rpm_limit){console.log("formValues.model_rpm_limit:",t.model_rpm_limit);try{t.model_rpm_limit=JSON.parse(t.model_rpm_limit)}catch(e){throw Error("Failed to parse model_rpm_limit: "+e)}}let o=s?"".concat(s,"/key/update"):"/key/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let r=await a.json();return console.log("Update key Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},e3=async(e,t)=>{try{console.log("Form Values in teamUpateCall:",t);let o=s?"".concat(s,"/team/update"):"/team/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),n.Z.fromBackend("Failed to update team settings: "+e),Error(e)}let r=await a.json();return console.log("Update Team Response:",r),r}catch(e){throw console.error("Failed to update team:",e),e}},e5=async(e,t,o)=>{try{console.log("Form Values in modelUpateCall:",t);let a=s?"".concat(s,"/model/").concat(o,"/update"):"/model/".concat(o,"/update"),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error update from the server:",e),Error("Network response was not ok")}let n=await r.json();return console.log("Update model Response:",n),n}catch(e){throw console.error("Failed to update model:",e),e}},e6=async(e,t)=>{try{console.log("Form Values in modelUpateCall:",t);let o=s?"".concat(s,"/model/update"):"/model/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error update from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("Update model Response:",r),r}catch(e){throw console.error("Failed to update model:",e),e}},e7=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let r=s?"".concat(s,"/team/member_add"):"/team/member_add",n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,member:o})});if(!n.ok){var a;let e=await n.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(a=t.detail)||void 0===a?void 0:a.error)||"Failed to add team member",r=Error(o);throw r.raw=t,r}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},e9=async(e,t,o,a,r)=>{try{console.log("Bulk add team members:",{teamId:t,members:o,maxBudgetInTeam:a});let l=s?"".concat(s,"/team/bulk_member_add"):"/team/bulk_member_add",c={team_id:t};r?c.all_users=!0:c.members=o,null!=a&&(c.max_budget_in_team=a);let i=await fetch(l,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(c)});if(!i.ok){var n;let e=await i.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(n=t.detail)||void 0===n?void 0:n.error)||"Failed to bulk add team members",a=Error(o);throw a.raw=t,a}let d=await i.json();return console.log("Bulk team member add API Response:",d),d}catch(e){throw console.error("Failed to bulk add team members:",e),e}},e8=async(e,t,o)=>{try{console.log("Form Values in teamMemberUpdateCall:",o),console.log("Budget value:",o.max_budget_in_team),console.log("TPM limit:",o.tpm_limit),console.log("RPM limit:",o.rpm_limit);let r=s?"".concat(s,"/team/member_update"):"/team/member_update",n={team_id:t,role:o.role,user_id:o.user_id};void 0!==o.user_email&&(n.user_email=o.user_email),void 0!==o.max_budget_in_team&&null!==o.max_budget_in_team&&(n.max_budget_in_team=o.max_budget_in_team),void 0!==o.tpm_limit&&null!==o.tpm_limit&&(n.tpm_limit=o.tpm_limit),void 0!==o.rpm_limit&&null!==o.rpm_limit&&(n.rpm_limit=o.rpm_limit),console.log("Final request body:",n);let l=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){var a;let e=await l.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(a=t.detail)||void 0===a?void 0:a.error)||"Failed to add team member",r=Error(o);throw r.raw=t,r}let c=await l.json();return console.log("API Response:",c),c}catch(e){throw console.error("Failed to update team member:",e),e}},te=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let a=s?"".concat(s,"/team/member_delete"):"/team/member_delete",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,...void 0!==o.user_email&&{user_email:o.user_email},...void 0!==o.user_id&&{user_id:o.user_id}})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},tt=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let a=s?"".concat(s,"/organization/member_add"):"/organization/member_add",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,member:o})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create organization member:",e),e}},to=async(e,t,o)=>{try{console.log("Form Values in organizationMemberDeleteCall:",o);let a=s?"".concat(s,"/organization/member_delete"):"/organization/member_delete",r=await fetch(a,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,user_id:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to delete organization member:",e),e}},ta=async(e,t,o)=>{try{console.log("Form Values in organizationMemberUpdateCall:",o);let a=s?"".concat(s,"/organization/member_update"):"/organization/member_update",r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,...o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to update organization member:",e),e}},tr=async(e,t,o)=>{try{console.log("Form Values in userUpdateUserCall:",t);let a=s?"".concat(s,"/user/update"):"/user/update",r={...t};null!==o&&(r.user_role=o),r=JSON.stringify(r);let n=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:r});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},tn=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];try{let r;console.log("Form Values in userUpdateUserCall:",t);let n=s?"".concat(s,"/user/bulk_update"):"/user/bulk_update";if(a)r=JSON.stringify({all_users:!0,user_updates:t});else if(o&&o.length>0){let e=[];for(let a of o)e.push({user_id:a,...t});r=JSON.stringify({users:e})}else throw Error("Must provide either userIds or set allUsers=true");let l=await fetch(n,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:r});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log("API Response:",c),c}catch(e){throw console.error("Failed to create key:",e),e}},tl=async(e,t)=>{try{let o=s?"".concat(s,"/global/predict/spend/logs"):"/global/predict/spend/logs",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},tc=async e=>{try{let t=s?"".concat(s,"/health/services?service=slack_budget_alerts"):"/health/services?service=slack_budget_alerts";console.log("Checking Slack Budget Alerts service health");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}let a=await o.json();return n.Z.success("Test Slack Alert worked - check your Slack!"),console.log("Service Health Response:",a),a}catch(e){throw console.error("Failed to perform health check:",e),e}},ti=async(e,t)=>{try{let o=s?"".concat(s,"/health/services?service=").concat(t):"/health/services?service=".concat(t);console.log("Checking Slack Budget Alerts service health");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error(e)}return await a.json()}catch(e){throw console.error("Failed to perform health check:",e),e}},ts=async e=>{try{let t=s?"".concat(s,"/budget/list"):"/budget/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},td=async e=>{try{let t=s?"".concat(s,"/budget/settings"):"/budget/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tu=async(e,t,o)=>{try{let t=s?"".concat(s,"/get/config/callbacks"):"/get/config/callbacks",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tp=async e=>{try{let t=s?"".concat(s,"/config/list?config_type=general_settings"):"/config/list?config_type=general_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},th=async e=>{try{let t=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tg=async(e,t)=>{try{let o=s?"".concat(s,"/config/field/info?field_name=").concat(t):"/config/field/info?field_name=".concat(t),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tm=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,field_value:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Successfully updated value!"),l}catch(e){throw console.error("Failed to set callbacks:",e),e}},tf=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tw=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/field/update"):"/config/field/update",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,field_value:o,config_type:"general_settings"})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Successfully updated value!"),l}catch(e){throw console.error("Failed to set callbacks:",e),e}},ty=async(e,t)=>{try{let o=s?"".concat(s,"/config/field/delete"):"/config/field/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,config_type:"general_settings"})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return n.Z.success("Field reset on proxy"),r}catch(e){throw console.error("Failed to get callbacks:",e),e}},tj=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint?endpoint_id=").concat(t):"/config/pass_through_endpoint?endpoint_id=".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},t_=async(e,t)=>{try{let o=s?"".concat(s,"/config/update"):"/config/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tC=async e=>{try{let t=s?"".concat(s,"/health"):"/health",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to call /health:",e),e}},tk=async(e,t)=>{try{let o=s?"".concat(s,"/health?model=").concat(encodeURIComponent(t)):"/health?model=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to call /health for model ".concat(t,":"),e),e}},tv=async e=>{try{let t=s?"".concat(s,"/cache/ping"):"/cache/ping",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}return await o.json()}catch(e){throw console.error("Failed to call /cache/ping:",e),e}},tT=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:100,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;try{let n=s?"".concat(s,"/health/history"):"/health/history",l=new URLSearchParams;t&&l.append("model",t),o&&l.append("status_filter",o),l.append("limit",a.toString()),l.append("offset",r.toString()),l.toString()&&(n+="?".concat(l.toString()));let c=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.text();throw m(e),Error(e)}return await c.json()}catch(e){throw console.error("Failed to call /health/history:",e),e}},tE=async e=>{try{let t=s?"".concat(s,"/health/latest"):"/health/latest",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}return await o.json()}catch(e){throw console.error("Failed to call /health/latest:",e),e}},tS=async e=>{try{console.log("Getting proxy UI settings"),console.log("proxyBaseUrl in getProxyUISettings:",s);let t=s?"".concat(s,"/sso/get/ui_settings"):"/sso/get/ui_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tb=async e=>{try{let t=s?"".concat(s,"/v2/guardrails/list"):"/v2/guardrails/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get guardrails list:",e),e}},tF=async e=>{try{let t=s?"".concat(s,"/prompts/list"):"/prompts/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get prompts list:",e),e}},tP=async(e,t)=>{try{let o=s?"".concat(s,"/prompts/").concat(t,"/info"):"/prompts/".concat(t,"/info"),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to get prompt info:",e),e}},tO=async(e,t)=>{try{let o=s?"".concat(s,"/prompts"):"/prompts",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create prompt:",e),e}},tB=async(e,t,o)=>{try{let a=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),r=await fetch(a,{method:"PUT",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to update prompt:",e),e}},tN=async(e,t)=>{try{let o=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to delete prompt:",e),e}},tx=async(e,t)=>{try{let o=new FormData;o.append("file",t);let a=s?"".concat(s,"/utils/dotprompt_json_converter"):"/utils/dotprompt_json_converter",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e)},body:o});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to convert prompt file:",e),e}},tG=async(e,t,o)=>{try{let a=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to patch prompt:",e),e}},tJ=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails"):"/guardrails",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({guardrail:t})});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Create guardrail response:",r),r}catch(e){throw console.error("Failed to create guardrail:",e),e}},tA=async(e,t,o)=>{try{let a=s?"".concat(s,"/spend/logs/ui/").concat(t,"?start_date=").concat(encodeURIComponent(o)):"/spend/logs/ui/".concat(t,"?start_date=").concat(encodeURIComponent(o));console.log("Fetching log details from:",a);let r=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Fetched log details:",n),n}catch(e){throw console.error("Failed to fetch log details:",e),e}},tU=async e=>{try{let t=s?"".concat(s,"/get/internal_user_settings"):"/get/internal_user_settings";console.log("Fetching SSO settings from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched SSO settings:",a),a}catch(e){throw console.error("Failed to fetch SSO settings:",e),e}},tR=async(e,t)=>{try{let o=s?"".concat(s,"/update/internal_user_settings"):"/update/internal_user_settings";console.log("Updating internal user settings:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Updated internal user settings:",r),n.Z.success("Internal user settings updated successfully"),r}catch(e){throw console.error("Failed to update internal user settings:",e),e}},tI=async e=>{try{let t=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server";console.log("Fetching MCP servers from:",t);let o=await fetch(t,{method:p.GET,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched MCP servers:",a),a}catch(e){throw console.error("Failed to fetch MCP servers:",e),e}},tM=async e=>{try{let t=s?"".concat(s,"/v1/mcp/access_groups"):"/v1/mcp/access_groups";console.log("Fetching MCP access groups from:",t);let o=await fetch(t,{method:p.GET,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched MCP access groups:",a),a.access_groups||[]}catch(e){throw console.error("Failed to fetch MCP access groups:",e),e}},tz=async(e,t)=>{try{console.log("Form Values in createMCPServer:",t);let o=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},tL=async(e,t)=>{try{let o=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server",a=await fetch(o,{method:"PUT",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to update MCP server:",e),e}},tD=async(e,t)=>{try{let o=(s?"".concat(s):"")+"/v1/mcp/server/".concat(t);console.log("in deleteMCPServer:",t);let a=await fetch(o,{method:p.DELETE,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}}catch(e){throw console.error("Failed to delete key:",e),e}},tV=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/mcp-rest/tools/list?server_id=").concat(t):"/mcp-rest/tools/list?server_id=".concat(t);console.log("Fetching MCP tools from:",r);let n={[f]:"Bearer ".concat(e),"Content-Type":"application/json"};a&&o?n["x-mcp-".concat(a,"-authorization")]=o:o&&(n[w]=o);let l=await fetch(r,{method:"GET",headers:n}),c=await l.json();if(console.log("Fetched MCP tools response:",c),!l.ok){if(c.error&&c.message)throw Error(c.message);throw Error("Failed to fetch MCP tools")}return c}catch(e){return console.error("Failed to fetch MCP tools:",e),{tools:[],error:"network_error",message:e instanceof Error?e.message:"Failed to fetch MCP tools"}}},tZ=async(e,t,o,a,r)=>{try{let n=s?"".concat(s,"/mcp-rest/tools/call"):"/mcp-rest/tools/call";console.log("Calling MCP tool:",t,"with arguments:",o);let l={[f]:"Bearer ".concat(e),"Content-Type":"application/json"};r?l["x-mcp-".concat(r,"-authorization")]=a:l[w]=a;let c=await fetch(n,{method:"POST",headers:l,body:JSON.stringify({name:t,arguments:o})});if(!c.ok){let e="Network response was not ok",t=null,o=await c.text();try{let a=JSON.parse(o);a.detail?"string"==typeof a.detail?e=a.detail:"object"==typeof a.detail&&(e=a.detail.message||a.detail.error||"An error occurred",t=a.detail):e=a.message||a.error||e}catch(t){console.error("Failed to parse JSON error response:",t),o&&(e=o)}let a=Error(e);throw a.status=c.status,a.statusText=c.statusText,a.details=t,m(e),a}let i=await c.json();return console.log("MCP tool call response:",i),i}catch(e){throw console.error("Failed to call MCP tool:",e),console.error("Error type:",typeof e),e instanceof Error&&(console.error("Error message:",e.message),console.error("Error stack:",e.stack)),e}},tq=async(e,t)=>{try{let o=s?"".concat(s,"/tag/new"):"/tag/new",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error creating tag:",e),e}},tH=async(e,t)=>{try{let o=s?"".concat(s,"/tag/update"):"/tag/update",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error updating tag:",e),e}},tW=async(e,t)=>{try{let o=s?"".concat(s,"/tag/info"):"/tag/info",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({names:t})});if(!a.ok){let e=await a.text();return await m(e),{}}return await a.json()}catch(e){throw console.error("Error getting tag info:",e),e}},tY=async e=>{try{let t=s?"".concat(s,"/tag/list"):"/tag/list",o=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e)}});if(!o.ok){let e=await o.text();return await m(e),{}}return await o.json()}catch(e){throw console.error("Error listing tags:",e),e}},tK=async(e,t)=>{try{let o=s?"".concat(s,"/tag/delete"):"/tag/delete",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({name:t})});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error deleting tag:",e),e}},t$=async e=>{try{let t=s?"".concat(s,"/get/default_team_settings"):"/get/default_team_settings";console.log("Fetching default team settings from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched default team settings:",a),a}catch(e){throw console.error("Failed to fetch default team settings:",e),e}},tQ=async(e,t)=>{try{let o=s?"".concat(s,"/update/default_team_settings"):"/update/default_team_settings";console.log("Updating default team settings:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Updated default team settings:",r),n.Z.success("Default team settings updated successfully"),r}catch(e){throw console.error("Failed to update default team settings:",e),e}},tX=async(e,t)=>{try{let o=s?"".concat(s,"/team/permissions_list?team_id=").concat(t):"/team/permissions_list?team_id=".concat(t),a=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Team permissions response:",r),r}catch(e){throw console.error("Failed to get team permissions:",e),e}},t0=async(e,t,o)=>{try{let a=s?"".concat(s,"/team/permissions_update"):"/team/permissions_update",r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({team_id:t,team_member_permissions:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Team permissions response:",n),n}catch(e){throw console.error("Failed to update team permissions:",e),e}},t1=async(e,t)=>{try{let o=s?"".concat(s,"/spend/logs/session/ui?session_id=").concat(encodeURIComponent(t)):"/spend/logs/session/ui?session_id=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to fetch session logs:",e),e}},t2=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/new"):"/vector_store/new",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to create vector store")}return await a.json()}catch(e){throw console.error("Error creating vector store:",e),e}},t4=async function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1],arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{let t=s?"".concat(s,"/vector_store/list"):"/vector_store/list",o=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});if(!o.ok){let e=await o.json();throw Error(e.detail||"Failed to list vector stores")}return await o.json()}catch(e){throw console.error("Error listing vector stores:",e),e}},t3=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/delete"):"/vector_store/delete",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({vector_store_id:t})});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to delete vector store")}return await a.json()}catch(e){throw console.error("Error deleting vector store:",e),e}},t5=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/info"):"/vector_store/info",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({vector_store_id:t})});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to get vector store info")}return await a.json()}catch(e){throw console.error("Error getting vector store info:",e),e}},t6=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/update"):"/vector_store/update",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to update vector store")}return await a.json()}catch(e){throw console.error("Error updating vector store:",e),e}},t7=async e=>{try{let t=s?"".concat(s,"/email/event_settings"):"/email/event_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get email event settings")}let a=await o.json();return console.log("Email event settings response:",a),a}catch(e){throw console.error("Failed to get email event settings:",e),e}},t9=async(e,t)=>{try{let o=s?"".concat(s,"/email/event_settings"):"/email/event_settings",a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();throw m(e),Error("Failed to update email event settings")}let r=await a.json();return console.log("Update email event settings response:",r),r}catch(e){throw console.error("Failed to update email event settings:",e),e}},t8=async e=>{try{let t=s?"".concat(s,"/email/event_settings/reset"):"/email/event_settings/reset",o=await fetch(t,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to reset email event settings")}let a=await o.json();return console.log("Reset email event settings response:",a),a}catch(e){throw console.error("Failed to reset email event settings:",e),e}},oe=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails/").concat(t):"/guardrails/".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Delete guardrail response:",r),r}catch(e){throw console.error("Failed to delete guardrail:",e),e}},ot=async e=>{try{let t=s?"".concat(s,"/guardrails/ui/add_guardrail_settings"):"/guardrails/ui/add_guardrail_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get guardrail UI settings")}let a=await o.json();return console.log("Guardrail UI settings response:",a),a}catch(e){throw console.error("Failed to get guardrail UI settings:",e),e}},oo=async e=>{try{let t=s?"".concat(s,"/guardrails/ui/provider_specific_params"):"/guardrails/ui/provider_specific_params",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get guardrail provider specific parameters")}let a=await o.json();return console.log("Guardrail provider specific params response:",a),a}catch(e){throw console.error("Failed to get guardrail provider specific parameters:",e),e}},oa=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails/").concat(t,"/info"):"/guardrails/".concat(t,"/info"),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error("Failed to get guardrail info")}let r=await a.json();return console.log("Guardrail info response:",r),r}catch(e){throw console.error("Failed to get guardrail info:",e),e}},or=async(e,t,o)=>{try{let a=s?"".concat(s,"/guardrails/").concat(t):"/guardrails/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.text();throw m(e),Error("Failed to update guardrail")}let n=await r.json();return console.log("Update guardrail response:",n),n}catch(e){throw console.error("Failed to update guardrail:",e),e}},on=async e=>{try{let t=s?"".concat(s,"/get/sso_settings"):"/get/sso_settings";console.log("Fetching SSO configuration from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched SSO configuration:",a),a}catch(e){throw console.error("Failed to fetch SSO configuration:",e),e}},ol=async(e,t)=>{try{let o=s?"".concat(s,"/update/sso_settings"):"/update/sso_settings";console.log("Updating SSO configuration:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Updated SSO configuration:",r),r}catch(e){throw console.error("Failed to update SSO configuration:",e),e}},oc=async(e,t,o,a,r)=>{try{let t=s?"".concat(s,"/audit"):"/audit",o=new URLSearchParams;a&&o.append("page",a.toString()),r&&o.append("page_size",r.toString());let n=o.toString();n&&(t+="?".concat(n));let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}return await l.json()}catch(e){throw console.error("Failed to fetch audit logs:",e),e}},oi=async e=>{try{let t=s?"".concat(s,"/user/available_users"):"/user/available_users",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e)}});if(!o.ok){if(404===o.status)return null;let e=await o.text();throw m(e),Error("Network response was not ok")}return await o.json()}catch(e){throw console.error("Failed to fetch remaining users:",e),e}},os=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/pass_through_endpoint/").concat(encodeURIComponent(t)):"/config/pass_through_endpoint/".concat(encodeURIComponent(t)),r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Pass through endpoint updated successfully"),l}catch(e){throw console.error("Failed to update pass through endpoint:",e),e}},od=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint?endpoint_id=").concat(encodeURIComponent(t)):"/config/pass_through_endpoint?endpoint_id=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=(await a.json()).endpoints;if(!r||0===r.length)throw Error("Pass through endpoint not found");return r[0]}catch(e){throw console.error("Failed to get pass through endpoint info:",e),e}},ou=async(e,t)=>{try{let o=s?"".concat(s,"/config/callback/delete"):"/config/callback/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({callback_name:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to delete specific callback:",e),e}},op=async e=>{let t=u(),o=await fetch("".concat(t,"/v1/mcp/tools"),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok)throw Error("HTTP error! status: ".concat(o.status));return await o.json()},oh=async(e,t)=>{try{console.log("Testing MCP connection with config:",JSON.stringify(t));let a=s?"".concat(s,"/mcp-rest/test/connection"):"/mcp-rest/test/connection",r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify(t)}),n=r.headers.get("content-type");if(!n||!n.includes("application/json")){let e=await r.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(r.status,": ").concat(r.statusText,"). Check network tab for details."))}let l=await r.json();if(!r.ok||"error"===l.status){if("error"===l.status);else{var o;return{status:"error",message:(null===(o=l.error)||void 0===o?void 0:o.message)||"MCP connection test failed: ".concat(r.status," ").concat(r.statusText)}}}return l}catch(e){throw console.error("MCP connection test error:",e),e}},og=async(e,t)=>{try{console.log("Testing MCP tools list with config:",JSON.stringify(t));let o=s?"".concat(s,"/mcp-rest/test/tools/list"):"/mcp-rest/test/tools/list",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify(t)}),r=a.headers.get("content-type");if(!r||!r.includes("application/json")){let e=await a.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(a.status,": ").concat(a.statusText,"). Check network tab for details."))}let n=await a.json();if((!a.ok||n.error)&&!n.error)return{tools:[],error:"request_failed",message:n.message||"MCP tools list failed: ".concat(a.status," ").concat(a.statusText)};return n}catch(e){throw console.error("MCP tools list test error:",e),e}},om=async(e,t,o)=>{try{let a="".concat(u(),"/v1/vector_stores/").concat(t,"/search"),r=await fetch(a,{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({query:o})});if(!r.ok){let e=await r.text();return await m(e),null}return await r.json()}catch(e){throw console.error("Error testing vector store search:",e),e}},of=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:50,n=arguments.length>5?arguments[5]:void 0;try{let l=s?"".concat(s,"/tag/user-agent/analytics"):"/tag/user-agent/analytics",c=new URLSearchParams,i=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};c.append("start_date",i(t)),c.append("end_date",i(o)),c.append("page",a.toString()),c.append("page_size",r.toString()),n&&c.append("user_agent_filter",n);let d=c.toString();d&&(l+="?".concat(d));let u=await fetch(l,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!u.ok){let e=await u.json(),t=ov(e);throw m(t),Error(t)}return await u.json()}catch(e){throw console.error("Failed to fetch user agent analytics:",e),e}},ow=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/dau"):"/tag/dau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch DAU:",e),e}},oy=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/wau"):"/tag/wau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch WAU:",e),e}},oj=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/mau"):"/tag/mau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch MAU:",e),e}},o_=async e=>{try{let t=s?"".concat(s,"/tag/distinct"):"/tag/distinct",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to fetch distinct tags:",e),e}},oC=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/summary"):"/tag/summary",n=new URLSearchParams,l=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};n.append("start_date",l(t)),n.append("end_date",l(o)),a&&a.length>0&&a.forEach(e=>{n.append("tag_filters",e)});let c=n.toString();c&&(r+="?".concat(c));let i=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}return await i.json()}catch(e){throw console.error("Failed to fetch user agent summary:",e),e}},ok=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:50,a=arguments.length>3?arguments[3]:void 0;try{let r=s?"".concat(s,"/tag/user-agent/per-user-analytics"):"/tag/user-agent/per-user-analytics",n=new URLSearchParams;n.append("page",t.toString()),n.append("page_size",o.toString()),a&&a.length>0&&a.forEach(e=>{n.append("tag_filters",e)});let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch per-user analytics:",e),e}},ov=e=>(null==e?void 0:e.error)&&(e.error.message||e.error)||(null==e?void 0:e.message)||(null==e?void 0:e.detail)||(null==e?void 0:e.error)||JSON.stringify(e)},85968:function(e,t,o){o.d(t,{O:function(){return a}});let a=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let t=JSON.parse(e.message);if(t.error&&t.error.message)return t.error.message;return"string"==typeof t?t:JSON.stringify(t,null,2)}catch(t){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)}},3914:function(e,t,o){function a(){let e=window.location.hostname,t=["Lax","Strict","None"];["/","/ui"].forEach(o=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; domain=").concat(e,";"),t.forEach(t=>{let a="None"===t?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; SameSite=").concat(t,";").concat(a),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; domain=").concat(e,"; SameSite=").concat(t,";").concat(a)})}),console.log("After clearing cookies:",document.cookie)}function r(e){let t=document.cookie.split("; ").find(t=>t.startsWith(e+"="));return t?t.split("=")[1]:null}o.d(t,{b:function(){return a},e:function(){return r}})}}]); \ No newline at end of file +"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[154],{49169:function(e,t,o){o.d(t,{o:function(){return a.Z}});var a=o(49566)},63610:function(e,t,o){o.d(t,{d:function(){return h}});var a=o(57437),r=o(2265),n=o(64482),l=o(52787),c=o(20577),i=o(13634),s=o(49169),d=o(15424),u=o(89970),p=o(19250);let h=["metadata","config","enforced_params","aliases"],g=(e,t)=>h.includes(e)||"json"===t.format,m=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},f=(e,t,o)=>{let a={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"})[o]||"Text input";return g(e,t)?"".concat(a,"\nMust be valid JSON format"):t.enum?"Select from available options\nAllowed values: ".concat(t.enum.join(", ")):a};t.Z=e=>{let{schemaComponent:t,excludedFields:o=[],form:h,overrideLabels:w={},overrideTooltips:y={},customValidation:j={},defaultValues:_={}}=e,[C,k]=(0,r.useState)(null),[v,T]=(0,r.useState)(null);(0,r.useEffect)(()=>{(async()=>{try{let e=(await (0,p.getOpenAPISchema)()).components.schemas[t];if(!e)throw Error('Schema component "'.concat(t,'" not found'));k(e);let a={};Object.keys(e.properties).filter(e=>!o.includes(e)&&void 0!==_[e]).forEach(e=>{a[e]=_[e]}),h.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),T(e instanceof Error?e.message:"Failed to fetch schema")}})()},[t,h,o]);let E=e=>{if(e.type)return e.type;if(e.anyOf){let t=e.anyOf.map(e=>e.type);if(t.includes("number")||t.includes("integer"))return"number";t.includes("string")}return"string"},S=(e,t)=>{var o;let r;let p=E(t),h=null==C?void 0:null===(o=C.required)||void 0===o?void 0:o.includes(e),k=w[e]||t.title||e,v=y[e]||t.description,T=[];h&&T.push({required:!0,message:"".concat(k," is required")}),j[e]&&T.push({validator:j[e]}),g(e,t)&&T.push({validator:async(e,t)=>{if(t&&!m(t))throw Error("Please enter valid JSON")}});let S=v?(0,a.jsxs)("span",{children:[k," ",(0,a.jsx)(u.Z,{title:v,children:(0,a.jsx)(d.Z,{style:{marginLeft:"4px"}})})]}):k;return r=g(e,t)?(0,a.jsx)(n.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):t.enum?(0,a.jsx)(l.default,{children:t.enum.map(e=>(0,a.jsx)(l.default.Option,{value:e,children:e},e))}):"number"===p||"integer"===p?(0,a.jsx)(c.Z,{style:{width:"100%"},precision:"integer"===p?0:void 0}):"duration"===e?(0,a.jsx)(s.o,{placeholder:"eg: 30s, 30h, 30d"}):(0,a.jsx)(s.o,{placeholder:v||""}),(0,a.jsx)(i.Z.Item,{label:S,name:e,className:"mt-8",rules:T,initialValue:_[e],help:(0,a.jsx)("div",{className:"text-xs text-gray-500",children:f(e,t,p)}),children:r},e)};return v?(0,a.jsxs)("div",{className:"text-red-500",children:["Error: ",v]}):(null==C?void 0:C.properties)?(0,a.jsx)("div",{children:Object.entries(C.properties).filter(e=>{let[t]=e;return!o.includes(t)}).map(e=>{let[t,o]=e;return S(t,o)})}):null}},9114:function(e,t,o){var a=o(2265),r=o(57271),n=o(85968);function l(){return"topRight"}function c(e,t){var o;return"string"==typeof e?{message:t,description:e}:{message:null!==(o=e.message)&&void 0!==o?o:t,...e}}function i(e){return"number"==typeof e?e:"string"==typeof e&&/^\d+$/.test(e)?parseInt(e,10):void 0}let s=["invalid api key","invalid authorization header format","authentication error","invalid proxy server token","invalid jwt token","invalid jwt submitted","unauthorized access to metrics endpoint"],d=["admin-only endpoint","not allowed to access model","user does not have permission","access forbidden","invalid credentials used to access ui","user not allowed to access proxy"],u=["db not connected","database not initialized","no db connected","prisma client not initialized","service unhealthy"],p=["no models configured on proxy","llm router not initialized","no deployments available","no healthy deployment available","not allowed to access model due to tags configuration","invalid model name passed in"],h=["deployment over user-defined ratelimit","crossed tpm / rpm / max parallel request limit","max parallel request limit"],g=["budget exceeded","crossed budget","provider budget"],m=["must be a litellm enterprise user","only be available for liteLLM enterprise users","missing litellm-enterprise package","only available on the docker image","enterprise feature","premium user"],f=["invalid json payload","invalid request type","invalid key format","invalid hash key","invalid sort column","invalid sort order","invalid limit","invalid file type","invalid field","invalid date format"],w=["model not found","model with id","credential not found","user not found","team not found","organization not found","mcp server with id","tool '"],y=["already exists","team member is already in team","user already exists"],j=["violated openai moderation policy","violated jailbreak threshold","violated prompt_injection threshold","violated content safety policy","violated lasso guardrail policy","blocked by pillar security guardrail","violated azure prompt shield guardrail policy","content blocked by model armor","response blocked by model armor","streaming response blocked by model armor","guardrail","moderation"],_=["invalid purpose","service must be specified","invalid response - response.response is none"],C=["cloudzero settings not configured","failed to decrypt cloudzero api key","cloudzero settings not found"],k=["created successfully","updated successfully","deleted successfully","credential created successfully","model added successfully","team created successfully","user created successfully","organization created successfully","cloudzero settings initialized successfully","cloudzero settings updated successfully","cloudzero export completed successfully","mock llm request made","mock slack alert sent","mock email alert sent","spend for all api keys and teams reset successfully","monthlyglobalspend view refreshed","cache cleared successfully","cache set successfully","ip ","deleted successfully"],v=["rate limit reached for deployment","deployment cooldown period active"],T=["this feature is only available for litellm enterprise users","enterprise features are not available","regenerating virtual keys is an enterprise feature","trying to set allowed_routes. this is an enterprise feature"],E=["invalid maximum_spend_logs_retention_interval value","error has invalid or non-convertible code","failed to save health check to database"];t.Z={error(e){var t,o;let a=c(e,"Error");r.ZP.error({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:6})},warning(e){var t,o;let a=c(e,"Warning");r.ZP.warning({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:5})},info(e){var t,o;let a=c(e,"Info");r.ZP.info({...a,placement:null!==(t=a.placement)&&void 0!==t?t:l(),duration:null!==(o=a.duration)&&void 0!==o?o:4})},success(e){var t,o;if(a.isValidElement(e)){r.ZP.success({message:"Success",description:e,placement:l(),duration:3.5});return}let n=c(e,"Success");r.ZP.success({...n,placement:null!==(t=n.placement)&&void 0!==t?t:l(),duration:null!==(o=n.duration)&&void 0!==o?o:3.5})},fromBackend(e,t){var o,a,c,S,b,F,P,O,B,N,x,G;let J=null!==(G=null!==(x=i(null==e?void 0:null===(N=e.response)||void 0===N?void 0:N.status))&&void 0!==x?x:i(null==e?void 0:e.status_code))&&void 0!==G?G:i(null==e?void 0:e.code),A=function(e){var t,o,a,r,l,c,i,s,d,u,p,h;if("string"==typeof e)return e;let g=null!==(h=null!==(p=null!==(u=null!==(d=null!==(s=null==e?void 0:null===(a=e.response)||void 0===a?void 0:null===(o=a.data)||void 0===o?void 0:null===(t=o.error)||void 0===t?void 0:t.message)&&void 0!==s?s:null==e?void 0:null===(l=e.response)||void 0===l?void 0:null===(r=l.data)||void 0===r?void 0:r.message)&&void 0!==d?d:null==e?void 0:null===(i=e.response)||void 0===i?void 0:null===(c=i.data)||void 0===c?void 0:c.error)&&void 0!==u?u:null==e?void 0:e.detail)&&void 0!==p?p:null==e?void 0:e.message)&&void 0!==h?h:e;return(0,n.O)(g)}(e),U={...null!=t?t:{},description:A,placement:null!==(o=null==t?void 0:t.placement)&&void 0!==o?o:l()};if(void 0!==J||e instanceof Error||"string"==typeof e||e&&"object"==typeof e&&("error"in e||"detail"in e)){let e=function(e,t){var o,a,r,n,l;let c=(t||"").toLowerCase();return s.some(e=>c.includes(e))?"Authentication Error":d.some(e=>c.includes(e))?"Access Denied":(null==u?void 0:null===(o=u.some)||void 0===o?void 0:o.call(u,e=>c.includes(e)))||503===e?"Service Unavailable":(null==g?void 0:null===(a=g.some)||void 0===a?void 0:a.call(g,e=>c.includes(e)))?"Budget Exceeded":(null==m?void 0:null===(r=m.some)||void 0===r?void 0:r.call(m,e=>c.includes(e)))?"Feature Unavailable":(null==p?void 0:null===(n=p.some)||void 0===n?void 0:n.call(p,e=>c.includes(e)))?"Routing Error":y.some(e=>c.includes(e))?"Already Exists":j.some(e=>c.includes(e))?"Content Blocked":_.some(e=>c.includes(e))?"Validation Error":C.some(e=>c.includes(e))?"Integration Error":f.some(e=>c.includes(e))?"Validation Error":404===e||c.includes("not found")||w.some(e=>c.includes(e))?"Not Found":429===e||c.includes("rate limit")||c.includes("tpm")||c.includes("rpm")||(null==h?void 0:null===(l=h.some)||void 0===l?void 0:l.call(h,e=>c.includes(e)))?"Rate Limit Exceeded":e&&e>=500?"Server Error":401===e?"Authentication Error":403===e?"Access Denied":c.includes("enterprise")||c.includes("premium")?"Info":e&&e>=400?"Request Error":"Error"}(J,A),o={...U,message:e};if("Rate Limit Exceeded"===e||"Info"===e||"Budget Exceeded"===e||"Feature Unavailable"===e||"Content Blocked"===e||"Integration Error"===e){r.ZP.warning({...o,duration:null!==(a=null==t?void 0:t.duration)&&void 0!==a?a:7});return}if("Server Error"===e){r.ZP.error({...o,duration:null!==(c=null==t?void 0:t.duration)&&void 0!==c?c:8});return}if("Request Error"===e||"Authentication Error"===e||"Access Denied"===e||"Not Found"===e||"Error"===e){r.ZP.error({...o,duration:null!==(S=null==t?void 0:t.duration)&&void 0!==S?S:6});return}r.ZP.info({...o,duration:null!==(b=null==t?void 0:t.duration)&&void 0!==b?b:4});return}let R=function(e){let t=(e||"").toLowerCase();return k.some(e=>t.includes(e))?{kind:"success",title:"Success"}:T.some(e=>t.includes(e))?{kind:"warning",title:"Feature Notice"}:E.some(e=>t.includes(e))?{kind:"warning",title:"Configuration Warning"}:v.some(e=>t.includes(e))?{kind:"warning",title:"Rate Limit"}:null}(A),I={...U,message:null!==(F=null==R?void 0:R.title)&&void 0!==F?F:"Info"};if((null==R?void 0:R.kind)==="success"){r.ZP.success({...I,duration:null!==(P=null==t?void 0:t.duration)&&void 0!==P?P:3.5});return}if((null==R?void 0:R.kind)==="warning"){r.ZP.warning({...I,duration:null!==(O=null==t?void 0:t.duration)&&void 0!==O?O:6});return}r.ZP.info({...I,duration:null!==(B=null==t?void 0:t.duration)&&void 0!==B?B:4})},clear(){r.ZP.destroy()}}},19250:function(e,t,o){o.r(t),o.d(t,{DEFAULT_ORGANIZATION:function(){return h},PredictedSpendLogsCall:function(){return tl},addAllowedIP:function(){return em},adminGlobalActivity:function(){return eJ},adminGlobalActivityExceptions:function(){return eR},adminGlobalActivityExceptionsPerDeployment:function(){return eI},adminGlobalActivityPerModel:function(){return eU},adminGlobalCacheActivity:function(){return eA},adminSpendLogsCall:function(){return eB},adminTopEndUsersCall:function(){return ex},adminTopKeysCall:function(){return eN},adminTopModelsCall:function(){return eM},adminspendByProvider:function(){return eG},alertingSettingsCall:function(){return A},allEndUsersCall:function(){return eb},allTagNamesCall:function(){return eS},availableTeamListCall:function(){return W},budgetCreateCall:function(){return N},budgetDeleteCall:function(){return B},budgetUpdateCall:function(){return x},cachingHealthCheckCall:function(){return tv},callMCPTool:function(){return tZ},cancelModelCostMapReload:function(){return S},claimOnboardingToken:function(){return el},convertPromptFileToJson:function(){return tx},createGuardrailCall:function(){return tJ},createMCPServer:function(){return tz},createPassThroughEndpoint:function(){return tf},createPromptCall:function(){return tO},credentialCreateCall:function(){return eQ},credentialDeleteCall:function(){return e1},credentialGetCall:function(){return e0},credentialListCall:function(){return eX},credentialUpdateCall:function(){return e2},defaultProxyBaseUrl:function(){return c},deleteAllowedIP:function(){return ef},deleteCallback:function(){return ou},deleteConfigFieldSetting:function(){return ty},deleteGuardrailCall:function(){return oe},deleteMCPServer:function(){return tD},deletePassThroughEndpointsCall:function(){return tj},deletePromptCall:function(){return tN},fetchMCPAccessGroups:function(){return tM},fetchMCPServers:function(){return tI},formatDate:function(){return l},getAllowedIPs:function(){return eg},getBudgetList:function(){return ts},getBudgetSettings:function(){return td},getCallbacksCall:function(){return tu},getConfigFieldSetting:function(){return tg},getDefaultTeamSettings:function(){return t$},getEmailEventSettings:function(){return t9},getGeneralSettingsCall:function(){return tp},getGuardrailInfo:function(){return oa},getGuardrailProviderSpecificParams:function(){return oo},getGuardrailUISettings:function(){return ot},getGuardrailsList:function(){return tb},getInternalUserSettings:function(){return tU},getModelCostMapReloadStatus:function(){return b},getOnboardingCredentials:function(){return en},getOpenAPISchema:function(){return k},getPassThroughEndpointInfo:function(){return od},getPassThroughEndpointsCall:function(){return th},getPossibleUserRoles:function(){return eK},getPromptInfo:function(){return tP},getPromptsList:function(){return tF},getProxyBaseUrl:function(){return u},getProxyUISettings:function(){return tS},getPublicModelHubInfo:function(){return C},getRemainingUsers:function(){return oi},getSSOSettings:function(){return on},getTeamPermissionsCall:function(){return tX},getTotalSpendCall:function(){return er},getUiConfig:function(){return _},healthCheckCall:function(){return tC},healthCheckHistoryCall:function(){return tT},individualModelHealthCheckCall:function(){return tk},invitationClaimCall:function(){return J},invitationCreateCall:function(){return G},keyCreateCall:function(){return R},keyCreateServiceAccountCall:function(){return U},keyDeleteCall:function(){return M},keyInfoCall:function(){return ez},keyInfoV1Call:function(){return eD},keyListCall:function(){return eV},keySpendLogsCall:function(){return ev},keyUpdateCall:function(){return e4},latestHealthChecksCall:function(){return tE},listMCPTools:function(){return tV},makeModelGroupPublic:function(){return j},mcpToolsCall:function(){return op},modelAvailableCall:function(){return ek},modelCostMap:function(){return v},modelCreateCall:function(){return F},modelDeleteCall:function(){return O},modelExceptionsCall:function(){return e_},modelHubCall:function(){return eh},modelHubPublicModelsCall:function(){return ep},modelInfoCall:function(){return ed},modelInfoV1Call:function(){return eu},modelMetricsCall:function(){return ew},modelMetricsSlowResponsesCall:function(){return ej},modelPatchUpdateCall:function(){return e5},modelSettingsCall:function(){return P},modelUpdateCall:function(){return e6},organizationCreateCall:function(){return $},organizationDeleteCall:function(){return X},organizationInfoCall:function(){return K},organizationListCall:function(){return Y},organizationMemberAddCall:function(){return tt},organizationMemberDeleteCall:function(){return to},organizationMemberUpdateCall:function(){return ta},organizationUpdateCall:function(){return Q},patchPromptCall:function(){return tG},perUserAnalyticsCall:function(){return ok},proxyBaseUrl:function(){return s},regenerateKeyCall:function(){return ec},reloadModelCostMap:function(){return T},resetEmailEventSettings:function(){return t8},scheduleModelCostMapReload:function(){return E},serverRootPath:function(){return i},serviceHealthCheck:function(){return ti},sessionSpendLogsCall:function(){return t1},setCallbacksCall:function(){return t_},setGlobalLitellmHeaderName:function(){return y},slackBudgetAlertsHealthCheck:function(){return tc},spendUsersCall:function(){return eZ},streamingModelMetricsCall:function(){return ey},tagCreateCall:function(){return tq},tagDailyActivityCall:function(){return eo},tagDauCall:function(){return ow},tagDeleteCall:function(){return tK},tagDistinctCall:function(){return o_},tagInfoCall:function(){return tW},tagListCall:function(){return tY},tagMauCall:function(){return oj},tagUpdateCall:function(){return tH},tagWauCall:function(){return oy},tagsSpendLogsCall:function(){return eE},teamBulkMemberAddCall:function(){return e7},teamCreateCall:function(){return e$},teamDailyActivityCall:function(){return ea},teamDeleteCall:function(){return L},teamInfoCall:function(){return Z},teamListCall:function(){return H},teamMemberAddCall:function(){return e9},teamMemberDeleteCall:function(){return te},teamMemberUpdateCall:function(){return e8},teamPermissionsUpdateCall:function(){return t0},teamSpendLogsCall:function(){return eT},teamUpdateCall:function(){return e3},testConnectionRequest:function(){return eL},testMCPConnectionRequest:function(){return oh},testMCPToolsListRequest:function(){return og},transformRequestCall:function(){return ee},uiAuditLogsCall:function(){return oc},uiSpendLogDetailsCall:function(){return tA},uiSpendLogsCall:function(){return eO},updateConfigFieldSetting:function(){return tw},updateDefaultTeamSettings:function(){return tQ},updateEmailEventSettings:function(){return t7},updateGuardrailCall:function(){return or},updateInternalUserSettings:function(){return tR},updateMCPServer:function(){return tL},updatePassThroughEndpoint:function(){return os},updatePassThroughFieldSetting:function(){return tm},updatePromptCall:function(){return tB},updateSSOSettings:function(){return ol},updateUsefulLinksCall:function(){return eC},userAgentAnalyticsCall:function(){return of},userAgentSummaryCall:function(){return oC},userBulkUpdateUserCall:function(){return tn},userCreateCall:function(){return I},userDailyActivityAggregatedCall:function(){return eW},userDailyActivityCall:function(){return et},userDeleteCall:function(){return z},userFilterUICall:function(){return eF},userGetAllUsersCall:function(){return eY},userGetRequesedtModelsCall:function(){return eH},userInfoCall:function(){return V},userListCall:function(){return D},userRequestModelCall:function(){return eq},userSpendLogsCall:function(){return eP},userUpdateUserCall:function(){return tr},v2TeamListCall:function(){return q},vectorStoreCreateCall:function(){return t2},vectorStoreDeleteCall:function(){return t3},vectorStoreInfoCall:function(){return t5},vectorStoreListCall:function(){return t4},vectorStoreSearchCall:function(){return om},vectorStoreUpdateCall:function(){return t6}});var a=o(42264),r=o(63610),n=o(9114);let l=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)},c=null,i="/",s=null;console.log=function(){};let d=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=window.location.origin,a=t||o;console.log("proxyBaseUrl:",s),console.log("serverRootPath:",e),e.length>0&&!a.endsWith(e)&&"/"!=e&&(a+=e,s=a),console.log("Updated proxyBaseUrl:",s)},u=()=>s||window.location.origin,p={GET:"GET",DELETE:"DELETE"},h="default_organization",g=0,m=async e=>{let t=Date.now();t-g>6e4?(e.includes("Authentication Error - Expired Key")&&(n.Z.info("UI Session Expired. Logging out."),g=t,document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=window.location.pathname),g=t):console.log("Error suppressed to prevent spam:",e)},f="Authorization",w="x-mcp-auth";function y(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Authorization";console.log("setGlobalLitellmHeaderName: ".concat(e)),f=e}let j=async(e,t)=>{let o=s?"".concat(s,"/model_group/make_public"):"/model_group/make_public";return(await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({model_groups:t})})).json()},_=async()=>{console.log("Getting UI config");let e=await fetch(c?"".concat(c,"/litellm/.well-known/litellm-ui-config"):"/litellm/.well-known/litellm-ui-config"),t=await e.json();return console.log("jsonData in getUiConfig:",t),d(t.server_root_path,t.proxy_base_url),t},C=async()=>{let e=await fetch(c?"".concat(c,"/public/model_hub/info"):"/public/model_hub/info");return await e.json()},k=async()=>{let e=s?"".concat(s,"/openapi.json"):"/openapi.json",t=await fetch(e);return await t.json()},v=async e=>{try{let t=s?"".concat(s,"/get/litellm_model_cost_map"):"/get/litellm_model_cost_map",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("received litellm model cost data: ".concat(a)),a}catch(e){throw console.error("Failed to get model cost map:",e),e}},T=async e=>{try{let t=s?"".concat(s,"/reload/model_cost_map"):"/reload/model_cost_map",o=await fetch(t,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("Model cost map reload response: ".concat(a)),a}catch(e){throw console.error("Failed to reload model cost map:",e),e}},E=async(e,t)=>{try{let o=s?"".concat(s,"/schedule/model_cost_map_reload?hours=").concat(t):"/schedule/model_cost_map_reload?hours=".concat(t),a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),r=await a.json();return console.log("Schedule model cost map reload response: ".concat(r)),r}catch(e){throw console.error("Failed to schedule model cost map reload:",e),e}},S=async e=>{try{let t=s?"".concat(s,"/schedule/model_cost_map_reload"):"/schedule/model_cost_map_reload",o=await fetch(t,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}}),a=await o.json();return console.log("Cancel model cost map reload response: ".concat(a)),a}catch(e){throw console.error("Failed to cancel model cost map reload:",e),e}},b=async e=>{try{let t=s?"".concat(s,"/schedule/model_cost_map_reload/status"):"/schedule/model_cost_map_reload/status";console.log("Fetching status from URL:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){console.error("Status request failed with status: ".concat(o.status));let e=await o.text();throw console.error("Error response:",e),Error("HTTP ".concat(o.status,": ").concat(e))}let a=await o.json();return console.log("Model cost map reload status:",a),a}catch(e){throw console.error("Failed to get model cost map reload status:",e),e}},F=async(e,t)=>{try{let o=s?"".concat(s,"/model/new"):"/model/new",r=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return console.log("API Response:",l),a.ZP.destroy(),n.Z.success("Model ".concat(t.model_name," created successfully")),l}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let t=s?"".concat(s,"/model/settings"):"/model/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){console.error("Failed to get model settings:",e)}},O=async(e,t)=>{console.log("model_id in model delete call: ".concat(t));try{let o=s?"".concat(s,"/model/delete"):"/model/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},B=async(e,t)=>{if(console.log("budget_id in budget delete call: ".concat(t)),null!=e)try{let o=s?"".concat(s,"/budget/delete"):"/budget/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},N=async(e,t)=>{try{console.log("Form Values in budgetCreateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/budget/new"):"/budget/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},x=async(e,t)=>{try{console.log("Form Values in budgetUpdateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/budget/update"):"/budget/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},G=async(e,t)=>{try{let o=s?"".concat(s,"/invitation/new"):"/invitation/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},J=async(e,t)=>{try{console.log("Form Values in invitationCreateCall:",t),console.log("Form Values after check:",t);let o=s?"".concat(s,"/invitation/claim"):"/invitation/claim",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},A=async e=>{try{let t=s?"".concat(s,"/alerting/settings"):"/alerting/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},U=async(e,t)=>{try{for(let e of(console.log("Form Values in keyCreateServiceAccountCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),r.d))if(t[e]){console.log("formValues.".concat(e,":"),t[e]);try{t[e]=JSON.parse(t[e])}catch(t){throw Error("Failed to parse ".concat(e,": ")+t)}}console.log("Form Values after check:",t);let o=s?"".concat(s,"/key/service-account/generate"):"/key/service-account/generate",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await a.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},R=async(e,t,o)=>{try{for(let e of(console.log("Form Values in keyCreateCall:",o),o.description&&(o.metadata||(o.metadata={}),o.metadata.description=o.description,delete o.description,o.metadata=JSON.stringify(o.metadata)),r.d))if(o[e]){console.log("formValues.".concat(e,":"),o[e]);try{o[e]=JSON.parse(o[e])}catch(t){throw Error("Failed to parse ".concat(e,": ")+t)}}console.log("Form Values after check:",o);let a=s?"".concat(s,"/key/generate"):"/key/generate",n=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...o})});if(!n.ok){let e=await n.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},I=async(e,t,o)=>{try{if(console.log("Form Values in keyCreateCall:",o),o.description&&(o.metadata||(o.metadata={}),o.metadata.description=o.description,delete o.description,o.metadata=JSON.stringify(o.metadata)),o.auto_create_key=!1,o.metadata){console.log("formValues.metadata:",o.metadata);try{o.metadata=JSON.parse(o.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",o);let a=s?"".concat(s,"/user/new"):"/user/new",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...o})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},M=async(e,t)=>{try{let o=s?"".concat(s,"/key/delete"):"/key/delete";console.log("in keyDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},z=async(e,t)=>{try{let o=s?"".concat(s,"/user/delete"):"/user/delete";console.log("in userDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_ids:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete user(s):",e),e}},L=async(e,t)=>{try{let o=s?"".concat(s,"/team/delete"):"/team/delete";console.log("in teamDeleteCall:",t);let a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[t]})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete key:",e),e}},D=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:null,i=arguments.length>8&&void 0!==arguments[8]?arguments[8]:null,d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:null;try{let u=s?"".concat(s,"/user/list"):"/user/list";console.log("in userListCall");let p=new URLSearchParams;if(t&&t.length>0){let e=t.join(",");p.append("user_ids",e)}o&&p.append("page",o.toString()),a&&p.append("page_size",a.toString()),r&&p.append("user_email",r),n&&p.append("role",n),l&&p.append("team",l),c&&p.append("sso_user_ids",c),i&&p.append("sort_by",i),d&&p.append("sort_order",d);let h=p.toString();h&&(u+="?".concat(h));let g=await fetch(u,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!g.ok){let e=await g.json(),t=ov(e);throw m(t),Error(t)}let w=await g.json();return console.log("/user/list API Response:",w),w}catch(e){throw console.error("Failed to create key:",e),e}},V=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=arguments.length>4?arguments[4]:void 0,n=arguments.length>5?arguments[5]:void 0,l=arguments.length>6&&void 0!==arguments[6]&&arguments[6];console.log("userInfoCall: ".concat(t,", ").concat(o,", ").concat(a,", ").concat(r,", ").concat(n,", ").concat(l));try{let c;if(a){c=s?"".concat(s,"/user/list"):"/user/list";let e=new URLSearchParams;null!=r&&e.append("page",r.toString()),null!=n&&e.append("page_size",n.toString()),c+="?".concat(e.toString())}else c=s?"".concat(s,"/user/info"):"/user/info",("Admin"!==o&&"Admin Viewer"!==o||l)&&t&&(c+="?user_id=".concat(t));console.log("Requesting user data from:",c);let i=await fetch(c,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("API Response:",d),d}catch(e){throw console.error("Failed to fetch user data:",e),e}},Z=async(e,t)=>{try{let o=s?"".concat(s,"/team/info"):"/team/info";t&&(o="".concat(o,"?team_id=").concat(t)),console.log("in teamInfoCall");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;arguments.length>5&&void 0!==arguments[5]&&arguments[5],arguments.length>6&&void 0!==arguments[6]&&arguments[6],arguments.length>7&&void 0!==arguments[7]&&arguments[7],arguments.length>8&&void 0!==arguments[8]&&arguments[8];try{let n=s?"".concat(s,"/v2/team/list"):"/v2/team/list";console.log("in teamInfoCall");let l=new URLSearchParams;o&&l.append("user_id",o.toString()),t&&l.append("organization_id",t.toString()),a&&l.append("team_id",a.toString()),r&&l.append("team_alias",r.toString());let c=l.toString();c&&(n+="?".concat(c));let i=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("/v2/team/list API Response:",d),d}catch(e){throw console.error("Failed to create key:",e),e}},H=async function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/team/list"):"/team/list";console.log("in teamInfoCall");let l=new URLSearchParams;o&&l.append("user_id",o.toString()),t&&l.append("organization_id",t.toString()),a&&l.append("team_id",a.toString()),r&&l.append("team_alias",r.toString());let c=l.toString();c&&(n+="?".concat(c));let i=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}let d=await i.json();return console.log("/team/list API Response:",d),d}catch(e){throw console.error("Failed to create key:",e),e}},W=async e=>{try{let t=s?"".concat(s,"/team/available"):"/team/available";console.log("in availableTeamListCall");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("/team/available_teams API Response:",a),a}catch(e){throw e}},Y=async e=>{try{let t=s?"".concat(s,"/organization/list"):"/organization/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,t)=>{try{let o=s?"".concat(s,"/organization/info"):"/organization/info";t&&(o="".concat(o,"?organization_id=").concat(t)),console.log("in teamInfoCall");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},$=async(e,t)=>{try{if(console.log("Form Values in organizationCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw console.error("Failed to parse metadata:",e),Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/organization/new"):"/organization/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},Q=async(e,t)=>{try{console.log("Form Values in organizationUpdateCall:",t);let o=s?"".concat(s,"/organization/update"):"/organization/update",a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Update Team Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},X=async(e,t)=>{try{let o=s?"".concat(s,"/organization/delete"):"/organization/delete",a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_ids:[t]})});if(!a.ok){let e=await a.text();throw m(e),Error("Error deleting organization: ".concat(e))}return await a.json()}catch(e){throw console.error("Failed to delete organization:",e),e}},ee=async(e,t)=>{try{let o=s?"".concat(s,"/utils/transform_request"):"/utils/transform_request",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},et=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;try{let r=s?"".concat(s,"/user/daily/activity"):"/user/daily/activity",n=new URLSearchParams;n.append("start_date",l(t)),n.append("end_date",l(o)),n.append("page_size","1000"),n.append("page",a.toString());let c=n.toString();c&&(r+="?".concat(c));let i=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}return await i.json()}catch(e){throw console.error("Failed to create key:",e),e}},eo=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/tag/daily/activity"):"/tag/daily/activity",c=new URLSearchParams;c.append("start_date",l(t)),c.append("end_date",l(o)),c.append("page_size","1000"),c.append("page",a.toString()),r&&c.append("tags",r.join(","));let i=c.toString();i&&(n+="?".concat(i));let d=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!d.ok){let e=await d.json(),t=ov(e);throw m(t),Error(t)}return await d.json()}catch(e){throw console.error("Failed to create key:",e),e}},ea=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;try{let n=s?"".concat(s,"/team/daily/activity"):"/team/daily/activity",c=new URLSearchParams;c.append("start_date",l(t)),c.append("end_date",l(o)),c.append("page_size","1000"),c.append("page",a.toString()),r&&c.append("team_ids",r.join(",")),c.append("exclude_team_ids","litellm-dashboard");let i=c.toString();i&&(n+="?".concat(i));let d=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!d.ok){let e=await d.json(),t=ov(e);throw m(t),Error(t)}return await d.json()}catch(e){throw console.error("Failed to create key:",e),e}},er=async e=>{try{let t=s?"".concat(s,"/global/spend"):"/global/spend",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},en=async e=>{try{let t=s?"".concat(s,"/onboarding/get_token"):"/onboarding/get_token";t+="?invite_link=".concat(e);let o=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},el=async(e,t,o,a)=>{let r=s?"".concat(s,"/onboarding/claim_token"):"/onboarding/claim_token";try{let n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({invitation_link:t,user_id:o,password:a})});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to delete key:",e),e}},ec=async(e,t,o)=>{try{let a=s?"".concat(s,"/key/").concat(t,"/regenerate"):"/key/".concat(t,"/regenerate"),r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Regenerate key Response:",n),n}catch(e){throw console.error("Failed to regenerate key:",e),e}},ei=!1,es=null,ed=async(e,t,o)=>{try{console.log("modelInfoCall:",e,t,o);let a=s?"".concat(s,"/v2/model/info"):"/v2/model/info",r=new URLSearchParams;r.append("include_team_models","true"),r.toString()&&(a+="?".concat(r.toString()));let l=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw e+="error shown=".concat(ei),ei||(e.includes("No model list passed")&&(e="No Models Exist. Click Add Model to get started."),n.Z.info(e),ei=!0,es&&clearTimeout(es),es=setTimeout(()=>{ei=!1},1e4)),Error("Network response was not ok")}let c=await l.json();return console.log("modelInfoCall:",c),c}catch(e){throw console.error("Failed to create key:",e),e}},eu=async(e,t)=>{try{let o=s?"".concat(s,"/v1/model/info"):"/v1/model/info";o+="?litellm_model_id=".concat(t);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("modelInfoV1Call:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},ep=async()=>{let e=s?"".concat(s,"/public/model_hub"):"/public/model_hub";return(await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}})).json()},eh=async e=>{try{let t=s?"".concat(s,"/model_group/info"):"/model_group/info",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("modelHubCall:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},eg=async e=>{try{let t=s?"".concat(s,"/get/allowed_ips"):"/get/allowed_ips",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("getAllowedIPs:",a),a.data}catch(e){throw console.error("Failed to get allowed IPs:",e),e}},em=async(e,t)=>{try{let o=s?"".concat(s,"/add/allowed_ip"):"/add/allowed_ip",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({ip:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("addAllowedIP:",r),r}catch(e){throw console.error("Failed to add allowed IP:",e),e}},ef=async(e,t)=>{try{let o=s?"".concat(s,"/delete/allowed_ip"):"/delete/allowed_ip",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({ip:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("deleteAllowedIP:",r),r}catch(e){throw console.error("Failed to delete allowed IP:",e),e}},ew=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics"):"/model/metrics";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},ey=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/model/streaming_metrics"):"/model/streaming_metrics";t&&(r="".concat(r,"?_selected_model_group=").concat(t,"&startTime=").concat(o,"&endTime=").concat(a));let n=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}return await n.json()}catch(e){throw console.error("Failed to create key:",e),e}},ej=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics/slow_responses"):"/model/metrics/slow_responses";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},e_=async(e,t,o,a,r,n,l,c)=>{try{let t=s?"".concat(s,"/model/metrics/exceptions"):"/model/metrics/exceptions";a&&(t="".concat(t,"?_selected_model_group=").concat(a,"&startTime=").concat(r,"&endTime=").concat(n,"&api_key=").concat(l,"&customer=").concat(c));let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to create key:",e),e}},eC=async(e,t)=>{try{let o=s?"".concat(s,"/model_hub/update_useful_links"):"/model_hub/update_useful_links",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({useful_links:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},ek=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,n=(arguments.length>5&&void 0!==arguments[5]&&arguments[5],arguments.length>6&&void 0!==arguments[6]&&arguments[6]);console.log("in /models calls, globalLitellmHeaderName",f);try{let t=s?"".concat(s,"/models"):"/models",o=new URLSearchParams;o.append("include_model_access_groups","True"),!0===a&&o.append("return_wildcard_routes","True"),!0===n&&o.append("only_model_access_groups","True"),r&&o.append("team_id",r.toString()),o.toString()&&(t+="?".concat(o.toString()));let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},ev=async(e,t)=>{try{let o=s?"".concat(s,"/global/spend/logs"):"/global/spend/logs";console.log("in keySpendLogsCall:",o);let a=await fetch("".concat(o,"?api_key=").concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},eT=async e=>{try{let t=s?"".concat(s,"/global/spend/teams"):"/global/spend/teams";console.log("in teamSpendLogsCall:",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eE=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/tags"):"/global/spend/tags";t&&o&&(r="".concat(r,"?start_date=").concat(t,"&end_date=").concat(o)),a&&(r+="".concat(r,"&tags=").concat(a.join(","))),console.log("in tagsSpendLogsCall:",r);let n=await fetch("".concat(r),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},eS=async e=>{try{let t=s?"".concat(s,"/global/spend/all_tag_names"):"/global/spend/all_tag_names";console.log("in global/spend/all_tag_names call",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eb=async e=>{try{let t=s?"".concat(s,"/global/all_end_users"):"/global/all_end_users";console.log("in global/all_end_users call",t);let o=await fetch("".concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eF=async(e,t)=>{try{let o=s?"".concat(s,"/user/filter/ui"):"/user/filter/ui";t.get("user_email")&&(o+="?user_email=".concat(t.get("user_email"))),t.get("user_id")&&(o+="?user_id=".concat(t.get("user_id")));let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create key:",e),e}},eP=async(e,t,o,a,r,n)=>{try{console.log("user role in spend logs call: ".concat(o));let t=s?"".concat(s,"/spend/logs"):"/spend/logs";t="App Owner"==o?"".concat(t,"?user_id=").concat(a,"&start_date=").concat(r,"&end_date=").concat(n):"".concat(t,"?start_date=").concat(r,"&end_date=").concat(n);let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to create key:",e),e}},eO=async(e,t,o,a,r,n,l,c,i,d,u,p,h)=>{try{let g=s?"".concat(s,"/spend/logs/ui"):"/spend/logs/ui",w=new URLSearchParams;t&&w.append("api_key",t),o&&w.append("team_id",o),a&&w.append("request_id",a),r&&w.append("start_date",r),n&&w.append("end_date",n),l&&w.append("page",l.toString()),c&&w.append("page_size",c.toString()),i&&w.append("user_id",i),d&&w.append("end_user",d),u&&w.append("status_filter",u),p&&w.append("model",p),h&&w.append("key_alias",h);let y=w.toString();y&&(g+="?".concat(y));let j=await fetch(g,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!j.ok){let e=await j.json(),t=ov(e);throw m(t),Error(t)}let _=await j.json();return console.log("Spend Logs Response:",_),_}catch(e){throw console.error("Failed to fetch spend logs:",e),e}},eB=async e=>{try{let t=s?"".concat(s,"/global/spend/logs"):"/global/spend/logs",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},eN=async e=>{try{let t=s?"".concat(s,"/global/spend/keys?limit=5"):"/global/spend/keys?limit=5",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},ex=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/end_users"):"/global/spend/end_users",n="";n=t?JSON.stringify({api_key:t,startTime:o,endTime:a}):JSON.stringify({startTime:o,endTime:a});let l={method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:n},c=await fetch(r,l);if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}let i=await c.json();return console.log(i),i}catch(e){throw console.error("Failed to create key:",e),e}},eG=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/spend/provider"):"/global/spend/provider";o&&a&&(r+="?start_date=".concat(o,"&end_date=").concat(a)),t&&(r+="&api_key=".concat(t));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eJ=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity"):"/global/activity";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eA=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity/cache_hits"):"/global/activity/cache_hits";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eU=async(e,t,o)=>{try{let a=s?"".concat(s,"/global/activity/model"):"/global/activity/model";t&&o&&(a+="?start_date=".concat(t,"&end_date=").concat(o));let r={method:"GET",headers:{[f]:"Bearer ".concat(e)}},n=await fetch(a,r);if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eR=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/activity/exceptions"):"/global/activity/exceptions";t&&o&&(r+="?start_date=".concat(t,"&end_date=").concat(o)),a&&(r+="&model_group=".concat(a));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eI=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/global/activity/exceptions/deployment"):"/global/activity/exceptions/deployment";t&&o&&(r+="?start_date=".concat(t,"&end_date=").concat(o)),a&&(r+="&model_group=".concat(a));let n={method:"GET",headers:{[f]:"Bearer ".concat(e)}},l=await fetch(r,n);if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log(c),c}catch(e){throw console.error("Failed to fetch spend data:",e),e}},eM=async e=>{try{let t=s?"".concat(s,"/global/spend/models?limit=5"):"/global/spend/models?limit=5",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},ez=async(e,t)=>{try{let o=s?"".concat(s,"/v2/key/info"):"/v2/key/info",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:t})});if(!a.ok){let e=await a.text();if(e.includes("Invalid proxy server token passed"))throw Error("Invalid proxy server token passed");throw m(e),Error("Network response was not ok")}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},eL=async(e,t,o,a)=>{try{console.log("Sending model connection test request:",JSON.stringify(t));let n=s?"".concat(s,"/health/test_connection"):"/health/test_connection",l=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify({litellm_params:t,model_info:o,mode:a})}),c=l.headers.get("content-type");if(!c||!c.includes("application/json")){let e=await l.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(l.status,": ").concat(l.statusText,"). Check network tab for details."))}let i=await l.json();if(!l.ok||"error"===i.status){if("error"===i.status);else{var r;return{status:"error",message:(null===(r=i.error)||void 0===r?void 0:r.message)||"Connection test failed: ".concat(l.status," ").concat(l.statusText)}}}return i}catch(e){throw console.error("Model connection test error:",e),e}},eD=async(e,t)=>{try{console.log("entering keyInfoV1Call");let o=s?"".concat(s,"/key/info"):"/key/info";o="".concat(o,"?key=").concat(t);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(console.log("response",a),!a.ok){let e=await a.text();m(e),n.Z.fromBackend("Failed to fetch key info - "+e)}let r=await a.json();return console.log("data",r),r}catch(e){throw console.error("Failed to fetch key info:",e),e}},eV=async function(e,t,o,a,r,n,l,c){let i=arguments.length>8&&void 0!==arguments[8]?arguments[8]:null,d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:null;try{let u=s?"".concat(s,"/key/list"):"/key/list";console.log("in keyListCall");let p=new URLSearchParams;o&&p.append("team_id",o.toString()),t&&p.append("organization_id",t.toString()),a&&p.append("key_alias",a),n&&p.append("key_hash",n),r&&p.append("user_id",r.toString()),l&&p.append("page",l.toString()),c&&p.append("size",c.toString()),i&&p.append("sort_by",i),d&&p.append("sort_order",d),p.append("return_full_object","true"),p.append("include_team_keys","true"),p.append("include_created_by_keys","true");let h=p.toString();h&&(u+="?".concat(h));let g=await fetch(u,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!g.ok){let e=await g.json(),t=ov(e);throw m(t),Error(t)}let w=await g.json();return console.log("/team/list API Response:",w),w}catch(e){throw console.error("Failed to create key:",e),e}},eZ=async(e,t)=>{try{let o=s?"".concat(s,"/spend/users"):"/spend/users";console.log("in spendUsersCall:",o);let a=await fetch("".concat(o,"?user_id=").concat(t),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to get spend for user",e),e}},eq=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/user/request_model"):"/user/request_model",n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({models:[t],user_id:o,justification:a})});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},eH=async e=>{try{let t=s?"".concat(s,"/user/get_requests"):"/user/get_requests";console.log("in userGetRequesedtModelsCall:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log(a),a}catch(e){throw console.error("Failed to get requested models:",e),e}},eW=async(e,t,o)=>{try{let a=s?"".concat(s,"/user/daily/activity/aggregated"):"/user/daily/activity/aggregated",r=new URLSearchParams,n=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};r.append("start_date",n(t)),r.append("end_date",n(o));let l=r.toString();l&&(a+="?".concat(l));let c=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch aggregated user daily activity:",e),e}},eY=async(e,t)=>{try{let o=s?"".concat(s,"/user/get_users?role=").concat(t):"/user/get_users?role=".concat(t);console.log("in userGetAllUsersCall:",o);let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to get requested models:",e),e}},eK=async e=>{try{let t=s?"".concat(s,"/user/available_roles"):"/user/available_roles",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("response from user/available_role",a),a}catch(e){throw e}},e$=async(e,t)=>{try{if(console.log("Form Values in teamCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/team/new"):"/team/new",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},eQ=async(e,t)=>{try{if(console.log("Form Values in credentialCreateCall:",t),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let o=s?"".concat(s,"/credentials"):"/credentials",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},eX=async e=>{try{let t=s?"".concat(s,"/credentials"):"/credentials";console.log("in credentialListCall");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("/credentials API Response:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},e0=async(e,t,o)=>{try{let a=s?"".concat(s,"/credentials"):"/credentials";t?a+="/by_name/".concat(t):o&&(a+="/by_model/".concat(o)),console.log("in credentialListCall");let r=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("/credentials API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},e1=async(e,t)=>{try{let o=s?"".concat(s,"/credentials/").concat(t):"/credentials/".concat(t);console.log("in credentialDeleteCall:",t);let a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to delete key:",e),e}},e2=async(e,t,o)=>{try{if(console.log("Form Values in credentialUpdateCall:",o),o.metadata){console.log("formValues.metadata:",o.metadata);try{o.metadata=JSON.parse(o.metadata)}catch(e){throw Error("Failed to parse metadata: "+e)}}let a=s?"".concat(s,"/credentials/").concat(t):"/credentials/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},e4=async(e,t)=>{try{if(console.log("Form Values in keyUpdateCall:",t),t.model_tpm_limit){console.log("formValues.model_tpm_limit:",t.model_tpm_limit);try{t.model_tpm_limit=JSON.parse(t.model_tpm_limit)}catch(e){throw Error("Failed to parse model_tpm_limit: "+e)}}if(t.model_rpm_limit){console.log("formValues.model_rpm_limit:",t.model_rpm_limit);try{t.model_rpm_limit=JSON.parse(t.model_rpm_limit)}catch(e){throw Error("Failed to parse model_rpm_limit: "+e)}}let o=s?"".concat(s,"/key/update"):"/key/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let r=await a.json();return console.log("Update key Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},e3=async(e,t)=>{try{console.log("Form Values in teamUpateCall:",t);let o=s?"".concat(s,"/team/update"):"/team/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error response from the server:",e),n.Z.fromBackend("Failed to update team settings: "+e),Error(e)}let r=await a.json();return console.log("Update Team Response:",r),r}catch(e){throw console.error("Failed to update team:",e),e}},e5=async(e,t,o)=>{try{console.log("Form Values in modelUpateCall:",t);let a=s?"".concat(s,"/model/").concat(o,"/update"):"/model/".concat(o,"/update"),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error update from the server:",e),Error("Network response was not ok")}let n=await r.json();return console.log("Update model Response:",n),n}catch(e){throw console.error("Failed to update model:",e),e}},e6=async(e,t)=>{try{console.log("Form Values in modelUpateCall:",t);let o=s?"".concat(s,"/model/update"):"/model/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.text();throw m(e),console.error("Error update from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("Update model Response:",r),r}catch(e){throw console.error("Failed to update model:",e),e}},e9=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let r=s?"".concat(s,"/team/member_add"):"/team/member_add",n=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,member:o})});if(!n.ok){var a;let e=await n.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(a=t.detail)||void 0===a?void 0:a.error)||"Failed to add team member",r=Error(o);throw r.raw=t,r}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},e7=async(e,t,o,a,r)=>{try{console.log("Bulk add team members:",{teamId:t,members:o,maxBudgetInTeam:a});let l=s?"".concat(s,"/team/bulk_member_add"):"/team/bulk_member_add",c={team_id:t};r?c.all_users=!0:c.members=o,null!=a&&(c.max_budget_in_team=a);let i=await fetch(l,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(c)});if(!i.ok){var n;let e=await i.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(n=t.detail)||void 0===n?void 0:n.error)||"Failed to bulk add team members",a=Error(o);throw a.raw=t,a}let d=await i.json();return console.log("Bulk team member add API Response:",d),d}catch(e){throw console.error("Failed to bulk add team members:",e),e}},e8=async(e,t,o)=>{try{console.log("Form Values in teamMemberUpdateCall:",o),console.log("Budget value:",o.max_budget_in_team),console.log("TPM limit:",o.tpm_limit),console.log("RPM limit:",o.rpm_limit);let r=s?"".concat(s,"/team/member_update"):"/team/member_update",n={team_id:t,role:o.role,user_id:o.user_id};void 0!==o.user_email&&(n.user_email=o.user_email),void 0!==o.max_budget_in_team&&null!==o.max_budget_in_team&&(n.max_budget_in_team=o.max_budget_in_team),void 0!==o.tpm_limit&&null!==o.tpm_limit&&(n.tpm_limit=o.tpm_limit),void 0!==o.rpm_limit&&null!==o.rpm_limit&&(n.rpm_limit=o.rpm_limit),console.log("Final request body:",n);let l=await fetch(r,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){var a;let e=await l.text(),t={};try{t=JSON.parse(e)}catch(t){console.warn("Failed to parse error body as JSON:",e)}let o=(null==t?void 0:null===(a=t.detail)||void 0===a?void 0:a.error)||"Failed to add team member",r=Error(o);throw r.raw=t,r}let c=await l.json();return console.log("API Response:",c),c}catch(e){throw console.error("Failed to update team member:",e),e}},te=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let a=s?"".concat(s,"/team/member_delete"):"/team/member_delete",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,...void 0!==o.user_email&&{user_email:o.user_email},...void 0!==o.user_id&&{user_id:o.user_id}})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},tt=async(e,t,o)=>{try{console.log("Form Values in teamMemberAddCall:",o);let a=s?"".concat(s,"/organization/member_add"):"/organization/member_add",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,member:o})});if(!r.ok){let e=await r.text();throw m(e),console.error("Error response from the server:",e),Error(e)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create organization member:",e),e}},to=async(e,t,o)=>{try{console.log("Form Values in organizationMemberDeleteCall:",o);let a=s?"".concat(s,"/organization/member_delete"):"/organization/member_delete",r=await fetch(a,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,user_id:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to delete organization member:",e),e}},ta=async(e,t,o)=>{try{console.log("Form Values in organizationMemberUpdateCall:",o);let a=s?"".concat(s,"/organization/member_update"):"/organization/member_update",r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({organization_id:t,...o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to update organization member:",e),e}},tr=async(e,t,o)=>{try{console.log("Form Values in userUpdateUserCall:",t);let a=s?"".concat(s,"/user/update"):"/user/update",r={...t};null!==o&&(r.user_role=o),r=JSON.stringify(r);let n=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:r});if(!n.ok){let e=await n.json(),t=ov(e);throw m(t),Error(t)}let l=await n.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},tn=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];try{let r;console.log("Form Values in userUpdateUserCall:",t);let n=s?"".concat(s,"/user/bulk_update"):"/user/bulk_update";if(a)r=JSON.stringify({all_users:!0,user_updates:t});else if(o&&o.length>0){let e=[];for(let a of o)e.push({user_id:a,...t});r=JSON.stringify({users:e})}else throw Error("Must provide either userIds or set allUsers=true");let l=await fetch(n,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:r});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}let c=await l.json();return console.log("API Response:",c),c}catch(e){throw console.error("Failed to create key:",e),e}},tl=async(e,t)=>{try{let o=s?"".concat(s,"/global/predict/spend/logs"):"/global/predict/spend/logs",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},tc=async e=>{try{let t=s?"".concat(s,"/health/services?service=slack_budget_alerts"):"/health/services?service=slack_budget_alerts";console.log("Checking Slack Budget Alerts service health");let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}let a=await o.json();return n.Z.success("Test Slack Alert worked - check your Slack!"),console.log("Service Health Response:",a),a}catch(e){throw console.error("Failed to perform health check:",e),e}},ti=async(e,t)=>{try{let o=s?"".concat(s,"/health/services?service=").concat(t):"/health/services?service=".concat(t);console.log("Checking Slack Budget Alerts service health");let a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error(e)}return await a.json()}catch(e){throw console.error("Failed to perform health check:",e),e}},ts=async e=>{try{let t=s?"".concat(s,"/budget/list"):"/budget/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},td=async e=>{try{let t=s?"".concat(s,"/budget/settings"):"/budget/settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tu=async(e,t,o)=>{try{let t=s?"".concat(s,"/get/config/callbacks"):"/get/config/callbacks",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tp=async e=>{try{let t=s?"".concat(s,"/config/list?config_type=general_settings"):"/config/list?config_type=general_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},th=async e=>{try{let t=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tg=async(e,t)=>{try{let o=s?"".concat(s,"/config/field/info?field_name=").concat(t):"/config/field/info?field_name=".concat(t),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tm=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,field_value:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Successfully updated value!"),l}catch(e){throw console.error("Failed to set callbacks:",e),e}},tf=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint"):"/config/pass_through_endpoint",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tw=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/field/update"):"/config/field/update",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,field_value:o,config_type:"general_settings"})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Successfully updated value!"),l}catch(e){throw console.error("Failed to set callbacks:",e),e}},ty=async(e,t)=>{try{let o=s?"".concat(s,"/config/field/delete"):"/config/field/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({field_name:t,config_type:"general_settings"})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return n.Z.success("Field reset on proxy"),r}catch(e){throw console.error("Failed to get callbacks:",e),e}},tj=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint?endpoint_id=").concat(t):"/config/pass_through_endpoint?endpoint_id=".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},t_=async(e,t)=>{try{let o=s?"".concat(s,"/config/update"):"/config/update",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},tC=async e=>{try{let t=s?"".concat(s,"/health"):"/health",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to call /health:",e),e}},tk=async(e,t)=>{try{let o=s?"".concat(s,"/health?model=").concat(encodeURIComponent(t)):"/health?model=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to call /health for model ".concat(t,":"),e),e}},tv=async e=>{try{let t=s?"".concat(s,"/cache/ping"):"/cache/ping",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}return await o.json()}catch(e){throw console.error("Failed to call /cache/ping:",e),e}},tT=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:100,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;try{let n=s?"".concat(s,"/health/history"):"/health/history",l=new URLSearchParams;t&&l.append("model",t),o&&l.append("status_filter",o),l.append("limit",a.toString()),l.append("offset",r.toString()),l.toString()&&(n+="?".concat(l.toString()));let c=await fetch(n,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.text();throw m(e),Error(e)}return await c.json()}catch(e){throw console.error("Failed to call /health/history:",e),e}},tE=async e=>{try{let t=s?"".concat(s,"/health/latest"):"/health/latest",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error(e)}return await o.json()}catch(e){throw console.error("Failed to call /health/latest:",e),e}},tS=async e=>{try{console.log("Getting proxy UI settings"),console.log("proxyBaseUrl in getProxyUISettings:",s);let t=s?"".concat(s,"/sso/get/ui_settings"):"/sso/get/ui_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},tb=async e=>{try{let t=s?"".concat(s,"/v2/guardrails/list"):"/v2/guardrails/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get guardrails list:",e),e}},tF=async e=>{try{let t=s?"".concat(s,"/prompts/list"):"/prompts/list",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to get prompts list:",e),e}},tP=async(e,t)=>{try{let o=s?"".concat(s,"/prompts/").concat(t,"/info"):"/prompts/".concat(t,"/info"),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to get prompt info:",e),e}},tO=async(e,t)=>{try{let o=s?"".concat(s,"/prompts"):"/prompts",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to create prompt:",e),e}},tB=async(e,t,o)=>{try{let a=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),r=await fetch(a,{method:"PUT",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to update prompt:",e),e}},tN=async(e,t)=>{try{let o=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to delete prompt:",e),e}},tx=async(e,t)=>{try{let o=new FormData;o.append("file",t);let a=s?"".concat(s,"/utils/dotprompt_json_converter"):"/utils/dotprompt_json_converter",r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e)},body:o});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to convert prompt file:",e),e}},tG=async(e,t,o)=>{try{let a=s?"".concat(s,"/prompts/").concat(t):"/prompts/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}return await r.json()}catch(e){throw console.error("Failed to patch prompt:",e),e}},tJ=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails"):"/guardrails",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({guardrail:t})});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Create guardrail response:",r),r}catch(e){throw console.error("Failed to create guardrail:",e),e}},tA=async(e,t,o)=>{try{let a=s?"".concat(s,"/spend/logs/ui/").concat(t,"?start_date=").concat(encodeURIComponent(o)):"/spend/logs/ui/".concat(t,"?start_date=").concat(encodeURIComponent(o));console.log("Fetching log details from:",a);let r=await fetch(a,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Fetched log details:",n),n}catch(e){throw console.error("Failed to fetch log details:",e),e}},tU=async e=>{try{let t=s?"".concat(s,"/get/internal_user_settings"):"/get/internal_user_settings";console.log("Fetching SSO settings from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched SSO settings:",a),a}catch(e){throw console.error("Failed to fetch SSO settings:",e),e}},tR=async(e,t)=>{try{let o=s?"".concat(s,"/update/internal_user_settings"):"/update/internal_user_settings";console.log("Updating internal user settings:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Updated internal user settings:",r),n.Z.success("Internal user settings updated successfully"),r}catch(e){throw console.error("Failed to update internal user settings:",e),e}},tI=async e=>{try{let t=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server";console.log("Fetching MCP servers from:",t);let o=await fetch(t,{method:p.GET,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched MCP servers:",a),a}catch(e){throw console.error("Failed to fetch MCP servers:",e),e}},tM=async e=>{try{let t=s?"".concat(s,"/v1/mcp/access_groups"):"/v1/mcp/access_groups";console.log("Fetching MCP access groups from:",t);let o=await fetch(t,{method:p.GET,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched MCP access groups:",a),a.access_groups||[]}catch(e){throw console.error("Failed to fetch MCP access groups:",e),e}},tz=async(e,t)=>{try{console.log("Form Values in createMCPServer:",t);let o=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},tL=async(e,t)=>{try{let o=s?"".concat(s,"/v1/mcp/server"):"/v1/mcp/server",a=await fetch(o,{method:"PUT",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to update MCP server:",e),e}},tD=async(e,t)=>{try{let o=(s?"".concat(s):"")+"/v1/mcp/server/".concat(t);console.log("in deleteMCPServer:",t);let a=await fetch(o,{method:p.DELETE,headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}}catch(e){throw console.error("Failed to delete key:",e),e}},tV=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/mcp-rest/tools/list?server_id=").concat(t):"/mcp-rest/tools/list?server_id=".concat(t);console.log("Fetching MCP tools from:",r);let n={[f]:"Bearer ".concat(e),"Content-Type":"application/json"};a&&o?n["x-mcp-".concat(a,"-authorization")]=o:o&&(n[w]=o);let l=await fetch(r,{method:"GET",headers:n}),c=await l.json();if(console.log("Fetched MCP tools response:",c),!l.ok){if(c.error&&c.message)throw Error(c.message);throw Error("Failed to fetch MCP tools")}return c}catch(e){return console.error("Failed to fetch MCP tools:",e),{tools:[],error:"network_error",message:e instanceof Error?e.message:"Failed to fetch MCP tools"}}},tZ=async(e,t,o,a,r)=>{try{let n=s?"".concat(s,"/mcp-rest/tools/call"):"/mcp-rest/tools/call";console.log("Calling MCP tool:",t,"with arguments:",o);let l={[f]:"Bearer ".concat(e),"Content-Type":"application/json"};r?l["x-mcp-".concat(r,"-authorization")]=a:l[w]=a;let c=await fetch(n,{method:"POST",headers:l,body:JSON.stringify({name:t,arguments:o})});if(!c.ok){let e="Network response was not ok",t=null,o=await c.text();try{let a=JSON.parse(o);a.detail?"string"==typeof a.detail?e=a.detail:"object"==typeof a.detail&&(e=a.detail.message||a.detail.error||"An error occurred",t=a.detail):e=a.message||a.error||e}catch(t){console.error("Failed to parse JSON error response:",t),o&&(e=o)}let a=Error(e);throw a.status=c.status,a.statusText=c.statusText,a.details=t,m(e),a}let i=await c.json();return console.log("MCP tool call response:",i),i}catch(e){throw console.error("Failed to call MCP tool:",e),console.error("Error type:",typeof e),e instanceof Error&&(console.error("Error message:",e.message),console.error("Error stack:",e.stack)),e}},tq=async(e,t)=>{try{let o=s?"".concat(s,"/tag/new"):"/tag/new",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error creating tag:",e),e}},tH=async(e,t)=>{try{let o=s?"".concat(s,"/tag/update"):"/tag/update",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error updating tag:",e),e}},tW=async(e,t)=>{try{let o=s?"".concat(s,"/tag/info"):"/tag/info",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({names:t})});if(!a.ok){let e=await a.text();return await m(e),{}}return await a.json()}catch(e){throw console.error("Error getting tag info:",e),e}},tY=async e=>{try{let t=s?"".concat(s,"/tag/list"):"/tag/list",o=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e)}});if(!o.ok){let e=await o.text();return await m(e),{}}return await o.json()}catch(e){throw console.error("Error listing tags:",e),e}},tK=async(e,t)=>{try{let o=s?"".concat(s,"/tag/delete"):"/tag/delete",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({name:t})});if(!a.ok){let e=await a.text();await m(e);return}return await a.json()}catch(e){throw console.error("Error deleting tag:",e),e}},t$=async e=>{try{let t=s?"".concat(s,"/get/default_team_settings"):"/get/default_team_settings";console.log("Fetching default team settings from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched default team settings:",a),a}catch(e){throw console.error("Failed to fetch default team settings:",e),e}},tQ=async(e,t)=>{try{let o=s?"".concat(s,"/update/default_team_settings"):"/update/default_team_settings";console.log("Updating default team settings:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Updated default team settings:",r),n.Z.success("Default team settings updated successfully"),r}catch(e){throw console.error("Failed to update default team settings:",e),e}},tX=async(e,t)=>{try{let o=s?"".concat(s,"/team/permissions_list?team_id=").concat(t):"/team/permissions_list?team_id=".concat(t),a=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Team permissions response:",r),r}catch(e){throw console.error("Failed to get team permissions:",e),e}},t0=async(e,t,o)=>{try{let a=s?"".concat(s,"/team/permissions_update"):"/team/permissions_update",r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({team_id:t,team_member_permissions:o})});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let n=await r.json();return console.log("Team permissions response:",n),n}catch(e){throw console.error("Failed to update team permissions:",e),e}},t1=async(e,t)=>{try{let o=s?"".concat(s,"/spend/logs/session/ui?session_id=").concat(encodeURIComponent(t)):"/spend/logs/session/ui?session_id=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to fetch session logs:",e),e}},t2=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/new"):"/vector_store/new",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to create vector store")}return await a.json()}catch(e){throw console.error("Error creating vector store:",e),e}},t4=async function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1],arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{let t=s?"".concat(s,"/vector_store/list"):"/vector_store/list",o=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});if(!o.ok){let e=await o.json();throw Error(e.detail||"Failed to list vector stores")}return await o.json()}catch(e){throw console.error("Error listing vector stores:",e),e}},t3=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/delete"):"/vector_store/delete",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({vector_store_id:t})});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to delete vector store")}return await a.json()}catch(e){throw console.error("Error deleting vector store:",e),e}},t5=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/info"):"/vector_store/info",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({vector_store_id:t})});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to get vector store info")}return await a.json()}catch(e){throw console.error("Error getting vector store info:",e),e}},t6=async(e,t)=>{try{let o=s?"".concat(s,"/vector_store/update"):"/vector_store/update",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)});if(!a.ok){let e=await a.json();throw Error(e.detail||"Failed to update vector store")}return await a.json()}catch(e){throw console.error("Error updating vector store:",e),e}},t9=async e=>{try{let t=s?"".concat(s,"/email/event_settings"):"/email/event_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get email event settings")}let a=await o.json();return console.log("Email event settings response:",a),a}catch(e){throw console.error("Failed to get email event settings:",e),e}},t7=async(e,t)=>{try{let o=s?"".concat(s,"/email/event_settings"):"/email/event_settings",a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.text();throw m(e),Error("Failed to update email event settings")}let r=await a.json();return console.log("Update email event settings response:",r),r}catch(e){throw console.error("Failed to update email event settings:",e),e}},t8=async e=>{try{let t=s?"".concat(s,"/email/event_settings/reset"):"/email/event_settings/reset",o=await fetch(t,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to reset email event settings")}let a=await o.json();return console.log("Reset email event settings response:",a),a}catch(e){throw console.error("Failed to reset email event settings:",e),e}},oe=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails/").concat(t):"/guardrails/".concat(t),a=await fetch(o,{method:"DELETE",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error(e)}let r=await a.json();return console.log("Delete guardrail response:",r),r}catch(e){throw console.error("Failed to delete guardrail:",e),e}},ot=async e=>{try{let t=s?"".concat(s,"/guardrails/ui/add_guardrail_settings"):"/guardrails/ui/add_guardrail_settings",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get guardrail UI settings")}let a=await o.json();return console.log("Guardrail UI settings response:",a),a}catch(e){throw console.error("Failed to get guardrail UI settings:",e),e}},oo=async e=>{try{let t=s?"".concat(s,"/guardrails/ui/provider_specific_params"):"/guardrails/ui/provider_specific_params",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw m(e),Error("Failed to get guardrail provider specific parameters")}let a=await o.json();return console.log("Guardrail provider specific params response:",a),a}catch(e){throw console.error("Failed to get guardrail provider specific parameters:",e),e}},oa=async(e,t)=>{try{let o=s?"".concat(s,"/guardrails/").concat(t,"/info"):"/guardrails/".concat(t,"/info"),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw m(e),Error("Failed to get guardrail info")}let r=await a.json();return console.log("Guardrail info response:",r),r}catch(e){throw console.error("Failed to get guardrail info:",e),e}},or=async(e,t,o)=>{try{let a=s?"".concat(s,"/guardrails/").concat(t):"/guardrails/".concat(t),r=await fetch(a,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.text();throw m(e),Error("Failed to update guardrail")}let n=await r.json();return console.log("Update guardrail response:",n),n}catch(e){throw console.error("Failed to update guardrail:",e),e}},on=async e=>{try{let t=s?"".concat(s,"/get/sso_settings"):"/get/sso_settings";console.log("Fetching SSO configuration from:",t);let o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}let a=await o.json();return console.log("Fetched SSO configuration:",a),a}catch(e){throw console.error("Failed to fetch SSO configuration:",e),e}},ol=async(e,t)=>{try{let o=s?"".concat(s,"/update/sso_settings"):"/update/sso_settings";console.log("Updating SSO configuration:",t);let a=await fetch(o,{method:"PATCH",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=await a.json();return console.log("Updated SSO configuration:",r),r}catch(e){throw console.error("Failed to update SSO configuration:",e),e}},oc=async(e,t,o,a,r)=>{try{let t=s?"".concat(s,"/audit"):"/audit",o=new URLSearchParams;a&&o.append("page",a.toString()),r&&o.append("page_size",r.toString());let n=o.toString();n&&(t+="?".concat(n));let l=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.json(),t=ov(e);throw m(t),Error(t)}return await l.json()}catch(e){throw console.error("Failed to fetch audit logs:",e),e}},oi=async e=>{try{let t=s?"".concat(s,"/user/available_users"):"/user/available_users",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e)}});if(!o.ok){if(404===o.status)return null;let e=await o.text();throw m(e),Error("Network response was not ok")}return await o.json()}catch(e){throw console.error("Failed to fetch remaining users:",e),e}},os=async(e,t,o)=>{try{let a=s?"".concat(s,"/config/pass_through_endpoint/").concat(encodeURIComponent(t)):"/config/pass_through_endpoint/".concat(encodeURIComponent(t)),r=await fetch(a,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok){let e=await r.json(),t=ov(e);throw m(t),Error(t)}let l=await r.json();return n.Z.success("Pass through endpoint updated successfully"),l}catch(e){throw console.error("Failed to update pass through endpoint:",e),e}},od=async(e,t)=>{try{let o=s?"".concat(s,"/config/pass_through_endpoint?endpoint_id=").concat(encodeURIComponent(t)):"/config/pass_through_endpoint?endpoint_id=".concat(encodeURIComponent(t)),a=await fetch(o,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}let r=(await a.json()).endpoints;if(!r||0===r.length)throw Error("Pass through endpoint not found");return r[0]}catch(e){throw console.error("Failed to get pass through endpoint info:",e),e}},ou=async(e,t)=>{try{let o=s?"".concat(s,"/config/callback/delete"):"/config/callback/delete",a=await fetch(o,{method:"POST",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({callback_name:t})});if(!a.ok){let e=await a.json(),t=ov(e);throw m(t),Error(t)}return await a.json()}catch(e){throw console.error("Failed to delete specific callback:",e),e}},op=async e=>{let t=u(),o=await fetch("".concat(t,"/v1/mcp/tools"),{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok)throw Error("HTTP error! status: ".concat(o.status));return await o.json()},oh=async(e,t)=>{try{console.log("Testing MCP connection with config:",JSON.stringify(t));let a=s?"".concat(s,"/mcp-rest/test/connection"):"/mcp-rest/test/connection",r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify(t)}),n=r.headers.get("content-type");if(!n||!n.includes("application/json")){let e=await r.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(r.status,": ").concat(r.statusText,"). Check network tab for details."))}let l=await r.json();if(!r.ok||"error"===l.status){if("error"===l.status);else{var o;return{status:"error",message:(null===(o=l.error)||void 0===o?void 0:o.message)||"MCP connection test failed: ".concat(r.status," ").concat(r.statusText)}}}return l}catch(e){throw console.error("MCP connection test error:",e),e}},og=async(e,t)=>{try{console.log("Testing MCP tools list with config:",JSON.stringify(t));let o=s?"".concat(s,"/mcp-rest/test/tools/list"):"/mcp-rest/test/tools/list",a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",[f]:"Bearer ".concat(e)},body:JSON.stringify(t)}),r=a.headers.get("content-type");if(!r||!r.includes("application/json")){let e=await a.text();throw console.error("Received non-JSON response:",e),Error("Received non-JSON response (".concat(a.status,": ").concat(a.statusText,"). Check network tab for details."))}let n=await a.json();if((!a.ok||n.error)&&!n.error)return{tools:[],error:"request_failed",message:n.message||"MCP tools list failed: ".concat(a.status," ").concat(a.statusText)};return n}catch(e){throw console.error("MCP tools list test error:",e),e}},om=async(e,t,o)=>{try{let a="".concat(u(),"/v1/vector_stores/").concat(t,"/search"),r=await fetch(a,{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({query:o})});if(!r.ok){let e=await r.text();return await m(e),null}return await r.json()}catch(e){throw console.error("Error testing vector store search:",e),e}},of=async function(e,t,o){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:50,n=arguments.length>5?arguments[5]:void 0;try{let l=s?"".concat(s,"/tag/user-agent/analytics"):"/tag/user-agent/analytics",c=new URLSearchParams,i=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};c.append("start_date",i(t)),c.append("end_date",i(o)),c.append("page",a.toString()),c.append("page_size",r.toString()),n&&c.append("user_agent_filter",n);let d=c.toString();d&&(l+="?".concat(d));let u=await fetch(l,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!u.ok){let e=await u.json(),t=ov(e);throw m(t),Error(t)}return await u.json()}catch(e){throw console.error("Failed to fetch user agent analytics:",e),e}},ow=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/dau"):"/tag/dau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch DAU:",e),e}},oy=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/wau"):"/tag/wau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch WAU:",e),e}},oj=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/mau"):"/tag/mau",n=new URLSearchParams;n.append("end_date",(e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)})(t)),a&&a.length>0?a.forEach(e=>{n.append("tag_filters",e)}):o&&n.append("tag_filter",o);let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch MAU:",e),e}},o_=async e=>{try{let t=s?"".concat(s,"/tag/distinct"):"/tag/distinct",o=await fetch(t,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.json(),t=ov(e);throw m(t),Error(t)}return await o.json()}catch(e){throw console.error("Failed to fetch distinct tags:",e),e}},oC=async(e,t,o,a)=>{try{let r=s?"".concat(s,"/tag/summary"):"/tag/summary",n=new URLSearchParams,l=e=>{let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(o,"-").concat(a)};n.append("start_date",l(t)),n.append("end_date",l(o)),a&&a.length>0&&a.forEach(e=>{n.append("tag_filters",e)});let c=n.toString();c&&(r+="?".concat(c));let i=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!i.ok){let e=await i.json(),t=ov(e);throw m(t),Error(t)}return await i.json()}catch(e){throw console.error("Failed to fetch user agent summary:",e),e}},ok=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:50,a=arguments.length>3?arguments[3]:void 0;try{let r=s?"".concat(s,"/tag/user-agent/per-user-analytics"):"/tag/user-agent/per-user-analytics",n=new URLSearchParams;n.append("page",t.toString()),n.append("page_size",o.toString()),a&&a.length>0&&a.forEach(e=>{n.append("tag_filters",e)});let l=n.toString();l&&(r+="?".concat(l));let c=await fetch(r,{method:"GET",headers:{[f]:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!c.ok){let e=await c.json(),t=ov(e);throw m(t),Error(t)}return await c.json()}catch(e){throw console.error("Failed to fetch per-user analytics:",e),e}},ov=e=>(null==e?void 0:e.error)&&(e.error.message||e.error)||(null==e?void 0:e.message)||(null==e?void 0:e.detail)||(null==e?void 0:e.error)||JSON.stringify(e)},85968:function(e,t,o){o.d(t,{O:function(){return a}});let a=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let t=JSON.parse(e.message);if(t.error&&t.error.message)return t.error.message;return"string"==typeof t?t:JSON.stringify(t,null,2)}catch(t){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)}},3914:function(e,t,o){function a(){let e=window.location.hostname,t=["Lax","Strict","None"];["/","/ui"].forEach(o=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; domain=").concat(e,";"),t.forEach(t=>{let a="None"===t?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; SameSite=").concat(t,";").concat(a),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(o,"; domain=").concat(e,"; SameSite=").concat(t,";").concat(a)})}),console.log("After clearing cookies:",document.cookie)}function r(e){let t=document.cookie.split("; ").find(t=>t.startsWith(e+"="));return t?t.split("=")[1]:null}o.d(t,{b:function(){return a},e:function(){return r}})}}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/layout-21dfaab0131d6703.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/layout-df4939b4f2ec37d7.js similarity index 59% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/layout-21dfaab0131d6703.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/layout-df4939b4f2ec37d7.js index 91430e42f4..a6801cb335 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/layout-21dfaab0131d6703.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/layout-df4939b4f2ec37d7.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[185],{96443:function(n,e,t){Promise.resolve().then(t.t.bind(t,39974,23)),Promise.resolve().then(t.t.bind(t,2778,23))},2778:function(){},39974:function(n){n.exports={style:{fontFamily:"'__Inter_1c856b', '__Inter_Fallback_1c856b'",fontStyle:"normal"},className:"__className_1c856b"}}},function(n){n.O(0,[919,986,971,117,744],function(){return n(n.s=96443)}),_N_E=n.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[185],{85210:function(n,e,t){Promise.resolve().then(t.t.bind(t,39974,23)),Promise.resolve().then(t.t.bind(t,2778,23))},2778:function(){},39974:function(n){n.exports={style:{fontFamily:"'__Inter_1c856b', '__Inter_Fallback_1c856b'",fontStyle:"normal"},className:"__className_1c856b"}}},function(n){n.O(0,[919,986,971,117,744],function(){return n(n.s=85210)}),_N_E=n.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-0dbadf20167b786c.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-13b00ef4a072d920.js similarity index 63% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-0dbadf20167b786c.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-13b00ef4a072d920.js index 6f2cf4f69e..9c30a52d27 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-0dbadf20167b786c.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-13b00ef4a072d920.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[418],{21024:function(e,n,t){Promise.resolve().then(t.bind(t,52829))},52829:function(e,n,t){"use strict";t.r(n),t.d(n,{default:function(){return f}});var u=t(57437),s=t(2265),c=t(99376),r=t(72162);function f(){let e=(0,c.useSearchParams)().get("key"),[n,t]=(0,s.useState)(null);return(0,s.useEffect)(()=>{e&&t(e)},[e]),(0,u.jsx)(r.Z,{accessToken:n})}}},function(e){e.O(0,[50,521,154,162,971,117,744],function(){return e(e.s=21024)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[418],{67355:function(e,n,t){Promise.resolve().then(t.bind(t,52829))},52829:function(e,n,t){"use strict";t.r(n),t.d(n,{default:function(){return f}});var u=t(57437),s=t(2265),c=t(99376),r=t(72162);function f(){let e=(0,c.useSearchParams)().get("key"),[n,t]=(0,s.useState)(null);return(0,s.useEffect)(()=>{e&&t(e)},[e]),(0,u.jsx)(r.Z,{accessToken:n})}}},function(e){e.O(0,[50,521,154,162,971,117,744],function(){return e(e.s=67355)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-f469bae327299fbb.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-304b7041a3fa39f7.js similarity index 69% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-f469bae327299fbb.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-304b7041a3fa39f7.js index 6ac3e8b900..f4e07dce6a 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-f469bae327299fbb.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub_table/page-304b7041a3fa39f7.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[25],{64563:function(e,n,u){Promise.resolve().then(u.bind(u,22775))},22775:function(e,n,u){"use strict";u.r(n),u.d(n,{default:function(){return f}});var t=u(57437),s=u(2265),r=u(99376),c=u(36172);function f(){let e=(0,r.useSearchParams)().get("key"),[n,u]=(0,s.useState)(null);return(0,s.useEffect)(()=>{e&&u(e)},[e]),(0,t.jsx)(c.Z,{accessToken:n,publicPage:!0,premiumUser:!1,userRole:null})}}},function(e){e.O(0,[50,521,866,154,162,172,971,117,744],function(){return e(e.s=64563)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[25],{38520:function(e,n,u){Promise.resolve().then(u.bind(u,22775))},22775:function(e,n,u){"use strict";u.r(n),u.d(n,{default:function(){return f}});var t=u(57437),s=u(2265),r=u(99376),c=u(36172);function f(){let e=(0,r.useSearchParams)().get("key"),[n,u]=(0,s.useState)(null);return(0,s.useEffect)(()=>{e&&u(e)},[e]),(0,t.jsx)(c.Z,{accessToken:n,publicPage:!0,premiumUser:!1,userRole:null})}}},function(e){e.O(0,[50,521,866,154,162,172,971,117,744],function(){return e(e.s=38520)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-7828c2c64e97362a.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-d0d85032bb87ba51.js similarity index 98% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-7828c2c64e97362a.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-d0d85032bb87ba51.js index f948427618..dad5d7aaa6 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-7828c2c64e97362a.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-d0d85032bb87ba51.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{8672:function(e,s,r){Promise.resolve().then(r.bind(r,12011))},49804:function(e,s,r){"use strict";r.d(s,{Z:function(){return i}});var l=r(5853),o=r(97324),n=r(1153),t=r(2265),a=r(9496);let c=(0,n.fn)("Col"),i=t.forwardRef((e,s)=>{let{numColSpan:r=1,numColSpanSm:n,numColSpanMd:i,numColSpanLg:d,children:m,className:u}=e,g=(0,l._T)(e,["numColSpan","numColSpanSm","numColSpanMd","numColSpanLg","children","className"]),p=(e,s)=>e&&Object.keys(s).includes(String(e))?s[e]:"";return t.createElement("div",Object.assign({ref:s,className:(0,o.q)(c("root"),(()=>{let e=p(r,a.PT),s=p(n,a.SP),l=p(i,a.VS),t=p(d,a._w);return(0,o.q)(e,s,l,t)})(),u)},g),m)});i.displayName="Col"},67101:function(e,s,r){"use strict";r.d(s,{Z:function(){return d}});var l=r(5853),o=r(97324),n=r(1153),t=r(2265),a=r(9496);let c=(0,n.fn)("Grid"),i=(e,s)=>e&&Object.keys(s).includes(String(e))?s[e]:"",d=t.forwardRef((e,s)=>{let{numItems:r=1,numItemsSm:n,numItemsMd:d,numItemsLg:m,children:u,className:g}=e,p=(0,l._T)(e,["numItems","numItemsSm","numItemsMd","numItemsLg","children","className"]),f=i(r,a._m),h=i(n,a.LH),b=i(d,a.l5),w=i(m,a.N4),x=(0,o.q)(f,h,b,w);return t.createElement("div",Object.assign({ref:s,className:(0,o.q)(c("root"),"grid",x,g)},p),u)});d.displayName="Grid"},9496:function(e,s,r){"use strict";r.d(s,{LH:function(){return o},N4:function(){return t},PT:function(){return a},SP:function(){return c},VS:function(){return i},_m:function(){return l},_w:function(){return d},l5:function(){return n}});let l={0:"grid-cols-none",1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6",7:"grid-cols-7",8:"grid-cols-8",9:"grid-cols-9",10:"grid-cols-10",11:"grid-cols-11",12:"grid-cols-12"},o={0:"sm:grid-cols-none",1:"sm:grid-cols-1",2:"sm:grid-cols-2",3:"sm:grid-cols-3",4:"sm:grid-cols-4",5:"sm:grid-cols-5",6:"sm:grid-cols-6",7:"sm:grid-cols-7",8:"sm:grid-cols-8",9:"sm:grid-cols-9",10:"sm:grid-cols-10",11:"sm:grid-cols-11",12:"sm:grid-cols-12"},n={0:"md:grid-cols-none",1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3",4:"md:grid-cols-4",5:"md:grid-cols-5",6:"md:grid-cols-6",7:"md:grid-cols-7",8:"md:grid-cols-8",9:"md:grid-cols-9",10:"md:grid-cols-10",11:"md:grid-cols-11",12:"md:grid-cols-12"},t={0:"lg:grid-cols-none",1:"lg:grid-cols-1",2:"lg:grid-cols-2",3:"lg:grid-cols-3",4:"lg:grid-cols-4",5:"lg:grid-cols-5",6:"lg:grid-cols-6",7:"lg:grid-cols-7",8:"lg:grid-cols-8",9:"lg:grid-cols-9",10:"lg:grid-cols-10",11:"lg:grid-cols-11",12:"lg:grid-cols-12"},a={1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4",5:"col-span-5",6:"col-span-6",7:"col-span-7",8:"col-span-8",9:"col-span-9",10:"col-span-10",11:"col-span-11",12:"col-span-12",13:"col-span-13"},c={1:"sm:col-span-1",2:"sm:col-span-2",3:"sm:col-span-3",4:"sm:col-span-4",5:"sm:col-span-5",6:"sm:col-span-6",7:"sm:col-span-7",8:"sm:col-span-8",9:"sm:col-span-9",10:"sm:col-span-10",11:"sm:col-span-11",12:"sm:col-span-12",13:"sm:col-span-13"},i={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3",4:"md:col-span-4",5:"md:col-span-5",6:"md:col-span-6",7:"md:col-span-7",8:"md:col-span-8",9:"md:col-span-9",10:"md:col-span-10",11:"md:col-span-11",12:"md:col-span-12",13:"md:col-span-13"},d={1:"lg:col-span-1",2:"lg:col-span-2",3:"lg:col-span-3",4:"lg:col-span-4",5:"lg:col-span-5",6:"lg:col-span-6",7:"lg:col-span-7",8:"lg:col-span-8",9:"lg:col-span-9",10:"lg:col-span-10",11:"lg:col-span-11",12:"lg:col-span-12",13:"lg:col-span-13"}},94789:function(e,s,r){"use strict";r.d(s,{Z:function(){return i}});var l=r(5853),o=r(2265),n=r(26898),t=r(97324),a=r(1153);let c=(0,a.fn)("Callout"),i=o.forwardRef((e,s)=>{let{title:r,icon:i,color:d,className:m,children:u}=e,g=(0,l._T)(e,["title","icon","color","className","children"]);return o.createElement("div",Object.assign({ref:s,className:(0,t.q)(c("root"),"flex flex-col overflow-hidden rounded-tremor-default text-tremor-default border-l-4 py-3 pr-3 pl-4",d?(0,t.q)((0,a.bM)(d,n.K.background).bgColor,(0,a.bM)(d,n.K.darkBorder).borderColor,(0,a.bM)(d,n.K.darkText).textColor,"dark:bg-opacity-10 bg-opacity-10"):(0,t.q)("bg-tremor-brand-faint border-tremor-brand-emphasis text-tremor-brand-emphasis","dark:bg-dark-tremor-brand-muted/70 dark:border-dark-tremor-brand-emphasis dark:text-dark-tremor-brand-emphasis"),m)},g),o.createElement("div",{className:(0,t.q)(c("header"),"flex items-start")},i?o.createElement(i,{className:(0,t.q)(c("icon"),"flex-none h-5 w-5 mr-1.5")}):null,o.createElement("h4",{className:(0,t.q)(c("title"),"font-semibold")},r)),o.createElement("p",{className:(0,t.q)(c("body"),"overflow-y-auto",u?"mt-2":"")},u))});i.displayName="Callout"},12011:function(e,s,r){"use strict";r.r(s),r.d(s,{default:function(){return k}});var l=r(57437),o=r(2265),n=r(99376),t=r(20831),a=r(94789),c=r(12514),i=r(49804),d=r(67101),m=r(84264),u=r(49566),g=r(96761),p=r(84566),f=r(19250),h=r(14474),b=r(13634),w=r(73002),x=r(3914);function k(){let[e]=b.Z.useForm(),s=(0,n.useSearchParams)();(0,x.e)("token");let r=s.get("invitation_id"),k=s.get("action"),[S,N]=(0,o.useState)(null),[y,_]=(0,o.useState)(""),[j,v]=(0,o.useState)(""),[C,Z]=(0,o.useState)(null),[E,I]=(0,o.useState)(""),[q,O]=(0,o.useState)(""),[P,T]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{(0,f.getUiConfig)().then(e=>{console.log("ui config in onboarding.tsx:",e),T(!1)})},[]),(0,o.useEffect)(()=>{r&&!P&&(0,f.getOnboardingCredentials)(r).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let r=e.token,l=(0,h.o)(r);O(r),console.log("decoded:",l),N(l.key),console.log("decoded user email:",l.user_email),v(l.user_email),Z(l.user_id)})},[r,P]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(c.Z,{children:[(0,l.jsx)(g.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(g.Z,{className:"text-xl",children:"reset_password"===k?"Reset Password":"Sign up"}),(0,l.jsx)(m.Z,{children:"reset_password"===k?"Reset your password to access Admin UI.":"Claim your user account to login to Admin UI."}),"reset_password"!==k&&(0,l.jsx)(a.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,l.jsxs)(d.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(i.Z,{children:"SSO is under the Enterprise Tier."}),(0,l.jsx)(i.Z,{children:(0,l.jsx)(t.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)(b.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",S,"token:",q,"formValues:",e),S&&q&&(e.user_email=j,C&&r&&(0,f.claimOnboardingToken)(S,r,C,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+q,console.log("redirecting to:",s);let r=(0,f.getProxyBaseUrl)();console.log("proxyBaseUrl:",r),r?window.location.href=r+s:window.location.href=s}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(b.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(u.Z,{type:"email",disabled:!0,value:j,defaultValue:j,className:"max-w-md"})}),(0,l.jsx)(b.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"reset_password"===k?"Enter your new password":"Create a password for your account",children:(0,l.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(w.ZP,{htmlType:"submit",children:"reset_password"===k?"Reset Password":"Sign Up"})})]})]})})}},14474:function(e,s,r){"use strict";r.d(s,{o:function(){return o}});class l extends Error{}function o(e,s){let r;if("string"!=typeof e)throw new l("Invalid token specified: must be a string");s||(s={});let o=!0===s.header?0:1,n=e.split(".")[o];if("string"!=typeof n)throw new l(`Invalid token specified: missing part #${o+1}`);try{r=function(e){let s=e.replace(/-/g,"+").replace(/_/g,"/");switch(s.length%4){case 0:break;case 2:s+="==";break;case 3:s+="=";break;default:throw Error("base64 string is not of the correct length")}try{var r;return r=s,decodeURIComponent(atob(r).replace(/(.)/g,(e,s)=>{let r=s.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}catch(e){return atob(s)}}(n)}catch(e){throw new l(`Invalid token specified: invalid base64 for part #${o+1} (${e.message})`)}try{return JSON.parse(r)}catch(e){throw new l(`Invalid token specified: invalid json for part #${o+1} (${e.message})`)}}l.prototype.name="InvalidTokenError"}},function(e){e.O(0,[665,50,154,971,117,744],function(){return e(e.s=8672)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[461],{2532:function(e,s,r){Promise.resolve().then(r.bind(r,12011))},49804:function(e,s,r){"use strict";r.d(s,{Z:function(){return i}});var l=r(5853),o=r(97324),n=r(1153),t=r(2265),a=r(9496);let c=(0,n.fn)("Col"),i=t.forwardRef((e,s)=>{let{numColSpan:r=1,numColSpanSm:n,numColSpanMd:i,numColSpanLg:d,children:m,className:u}=e,g=(0,l._T)(e,["numColSpan","numColSpanSm","numColSpanMd","numColSpanLg","children","className"]),p=(e,s)=>e&&Object.keys(s).includes(String(e))?s[e]:"";return t.createElement("div",Object.assign({ref:s,className:(0,o.q)(c("root"),(()=>{let e=p(r,a.PT),s=p(n,a.SP),l=p(i,a.VS),t=p(d,a._w);return(0,o.q)(e,s,l,t)})(),u)},g),m)});i.displayName="Col"},67101:function(e,s,r){"use strict";r.d(s,{Z:function(){return d}});var l=r(5853),o=r(97324),n=r(1153),t=r(2265),a=r(9496);let c=(0,n.fn)("Grid"),i=(e,s)=>e&&Object.keys(s).includes(String(e))?s[e]:"",d=t.forwardRef((e,s)=>{let{numItems:r=1,numItemsSm:n,numItemsMd:d,numItemsLg:m,children:u,className:g}=e,p=(0,l._T)(e,["numItems","numItemsSm","numItemsMd","numItemsLg","children","className"]),f=i(r,a._m),h=i(n,a.LH),b=i(d,a.l5),w=i(m,a.N4),x=(0,o.q)(f,h,b,w);return t.createElement("div",Object.assign({ref:s,className:(0,o.q)(c("root"),"grid",x,g)},p),u)});d.displayName="Grid"},9496:function(e,s,r){"use strict";r.d(s,{LH:function(){return o},N4:function(){return t},PT:function(){return a},SP:function(){return c},VS:function(){return i},_m:function(){return l},_w:function(){return d},l5:function(){return n}});let l={0:"grid-cols-none",1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6",7:"grid-cols-7",8:"grid-cols-8",9:"grid-cols-9",10:"grid-cols-10",11:"grid-cols-11",12:"grid-cols-12"},o={0:"sm:grid-cols-none",1:"sm:grid-cols-1",2:"sm:grid-cols-2",3:"sm:grid-cols-3",4:"sm:grid-cols-4",5:"sm:grid-cols-5",6:"sm:grid-cols-6",7:"sm:grid-cols-7",8:"sm:grid-cols-8",9:"sm:grid-cols-9",10:"sm:grid-cols-10",11:"sm:grid-cols-11",12:"sm:grid-cols-12"},n={0:"md:grid-cols-none",1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3",4:"md:grid-cols-4",5:"md:grid-cols-5",6:"md:grid-cols-6",7:"md:grid-cols-7",8:"md:grid-cols-8",9:"md:grid-cols-9",10:"md:grid-cols-10",11:"md:grid-cols-11",12:"md:grid-cols-12"},t={0:"lg:grid-cols-none",1:"lg:grid-cols-1",2:"lg:grid-cols-2",3:"lg:grid-cols-3",4:"lg:grid-cols-4",5:"lg:grid-cols-5",6:"lg:grid-cols-6",7:"lg:grid-cols-7",8:"lg:grid-cols-8",9:"lg:grid-cols-9",10:"lg:grid-cols-10",11:"lg:grid-cols-11",12:"lg:grid-cols-12"},a={1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4",5:"col-span-5",6:"col-span-6",7:"col-span-7",8:"col-span-8",9:"col-span-9",10:"col-span-10",11:"col-span-11",12:"col-span-12",13:"col-span-13"},c={1:"sm:col-span-1",2:"sm:col-span-2",3:"sm:col-span-3",4:"sm:col-span-4",5:"sm:col-span-5",6:"sm:col-span-6",7:"sm:col-span-7",8:"sm:col-span-8",9:"sm:col-span-9",10:"sm:col-span-10",11:"sm:col-span-11",12:"sm:col-span-12",13:"sm:col-span-13"},i={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3",4:"md:col-span-4",5:"md:col-span-5",6:"md:col-span-6",7:"md:col-span-7",8:"md:col-span-8",9:"md:col-span-9",10:"md:col-span-10",11:"md:col-span-11",12:"md:col-span-12",13:"md:col-span-13"},d={1:"lg:col-span-1",2:"lg:col-span-2",3:"lg:col-span-3",4:"lg:col-span-4",5:"lg:col-span-5",6:"lg:col-span-6",7:"lg:col-span-7",8:"lg:col-span-8",9:"lg:col-span-9",10:"lg:col-span-10",11:"lg:col-span-11",12:"lg:col-span-12",13:"lg:col-span-13"}},94789:function(e,s,r){"use strict";r.d(s,{Z:function(){return i}});var l=r(5853),o=r(2265),n=r(26898),t=r(97324),a=r(1153);let c=(0,a.fn)("Callout"),i=o.forwardRef((e,s)=>{let{title:r,icon:i,color:d,className:m,children:u}=e,g=(0,l._T)(e,["title","icon","color","className","children"]);return o.createElement("div",Object.assign({ref:s,className:(0,t.q)(c("root"),"flex flex-col overflow-hidden rounded-tremor-default text-tremor-default border-l-4 py-3 pr-3 pl-4",d?(0,t.q)((0,a.bM)(d,n.K.background).bgColor,(0,a.bM)(d,n.K.darkBorder).borderColor,(0,a.bM)(d,n.K.darkText).textColor,"dark:bg-opacity-10 bg-opacity-10"):(0,t.q)("bg-tremor-brand-faint border-tremor-brand-emphasis text-tremor-brand-emphasis","dark:bg-dark-tremor-brand-muted/70 dark:border-dark-tremor-brand-emphasis dark:text-dark-tremor-brand-emphasis"),m)},g),o.createElement("div",{className:(0,t.q)(c("header"),"flex items-start")},i?o.createElement(i,{className:(0,t.q)(c("icon"),"flex-none h-5 w-5 mr-1.5")}):null,o.createElement("h4",{className:(0,t.q)(c("title"),"font-semibold")},r)),o.createElement("p",{className:(0,t.q)(c("body"),"overflow-y-auto",u?"mt-2":"")},u))});i.displayName="Callout"},12011:function(e,s,r){"use strict";r.r(s),r.d(s,{default:function(){return k}});var l=r(57437),o=r(2265),n=r(99376),t=r(20831),a=r(94789),c=r(12514),i=r(49804),d=r(67101),m=r(84264),u=r(49566),g=r(96761),p=r(84566),f=r(19250),h=r(14474),b=r(13634),w=r(73002),x=r(3914);function k(){let[e]=b.Z.useForm(),s=(0,n.useSearchParams)();(0,x.e)("token");let r=s.get("invitation_id"),k=s.get("action"),[S,N]=(0,o.useState)(null),[y,_]=(0,o.useState)(""),[j,v]=(0,o.useState)(""),[C,Z]=(0,o.useState)(null),[E,I]=(0,o.useState)(""),[q,O]=(0,o.useState)(""),[P,T]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{(0,f.getUiConfig)().then(e=>{console.log("ui config in onboarding.tsx:",e),T(!1)})},[]),(0,o.useEffect)(()=>{r&&!P&&(0,f.getOnboardingCredentials)(r).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let r=e.token,l=(0,h.o)(r);O(r),console.log("decoded:",l),N(l.key),console.log("decoded user email:",l.user_email),v(l.user_email),Z(l.user_id)})},[r,P]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(c.Z,{children:[(0,l.jsx)(g.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(g.Z,{className:"text-xl",children:"reset_password"===k?"Reset Password":"Sign up"}),(0,l.jsx)(m.Z,{children:"reset_password"===k?"Reset your password to access Admin UI.":"Claim your user account to login to Admin UI."}),"reset_password"!==k&&(0,l.jsx)(a.Z,{className:"mt-4",title:"SSO",icon:p.GH$,color:"sky",children:(0,l.jsxs)(d.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(i.Z,{children:"SSO is under the Enterprise Tier."}),(0,l.jsx)(i.Z,{children:(0,l.jsx)(t.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)(b.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",S,"token:",q,"formValues:",e),S&&q&&(e.user_email=j,C&&r&&(0,f.claimOnboardingToken)(S,r,C,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+q,console.log("redirecting to:",s);let r=(0,f.getProxyBaseUrl)();console.log("proxyBaseUrl:",r),r?window.location.href=r+s:window.location.href=s}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(b.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(u.Z,{type:"email",disabled:!0,value:j,defaultValue:j,className:"max-w-md"})}),(0,l.jsx)(b.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"reset_password"===k?"Enter your new password":"Create a password for your account",children:(0,l.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(w.ZP,{htmlType:"submit",children:"reset_password"===k?"Reset Password":"Sign Up"})})]})]})})}},14474:function(e,s,r){"use strict";r.d(s,{o:function(){return o}});class l extends Error{}function o(e,s){let r;if("string"!=typeof e)throw new l("Invalid token specified: must be a string");s||(s={});let o=!0===s.header?0:1,n=e.split(".")[o];if("string"!=typeof n)throw new l(`Invalid token specified: missing part #${o+1}`);try{r=function(e){let s=e.replace(/-/g,"+").replace(/_/g,"/");switch(s.length%4){case 0:break;case 2:s+="==";break;case 3:s+="=";break;default:throw Error("base64 string is not of the correct length")}try{var r;return r=s,decodeURIComponent(atob(r).replace(/(.)/g,(e,s)=>{let r=s.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}catch(e){return atob(s)}}(n)}catch(e){throw new l(`Invalid token specified: invalid base64 for part #${o+1} (${e.message})`)}try{return JSON.parse(r)}catch(e){throw new l(`Invalid token specified: invalid json for part #${o+1} (${e.message})`)}}l.prototype.name="InvalidTokenError"}},function(e){e.O(0,[665,50,154,971,117,744],function(){return e(e.s=2532)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-73b19c9fbf8cc64f.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-73b19c9fbf8cc64f.js new file mode 100644 index 0000000000..cea368e341 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-73b19c9fbf8cc64f.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{31283:function(e,s,t){Promise.resolve().then(t.bind(t,85617))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return y}});var l=t(57437),a=t(2265),r=t(99376),i=t(20831),n=t(94789),o=t(12514),c=t(49804),d=t(67101),m=t(84264),u=t(49566),x=t(96761),h=t(84566),p=t(19250),g=t(14474),j=t(13634),f=t(73002),v=t(3914);function y(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,v.e)("token");let t=s.get("invitation_id"),y=s.get("action"),[b,_]=(0,a.useState)(null),[N,Z]=(0,a.useState)(""),[w,k]=(0,a.useState)(""),[S,C]=(0,a.useState)(null),[I,A]=(0,a.useState)(""),[L,T]=(0,a.useState)(""),[P,E]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{(0,p.getUiConfig)().then(e=>{console.log("ui config in onboarding.tsx:",e),E(!1)})},[]),(0,a.useEffect)(()=>{t&&!P&&(0,p.getOnboardingCredentials)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),A(s);let t=e.token,l=(0,g.o)(t);T(t),console.log("decoded:",l),_(l.key),console.log("decoded user email:",l.user_email),k(l.user_email),C(l.user_id)})},[t,P]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(x.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(x.Z,{className:"text-xl",children:"reset_password"===y?"Reset Password":"Sign up"}),(0,l.jsx)(m.Z,{children:"reset_password"===y?"Reset your password to access Admin UI.":"Claim your user account to login to Admin UI."}),"reset_password"!==y&&(0,l.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:h.GH$,color:"sky",children:(0,l.jsxs)(d.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tier."}),(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:",b,"token:",L,"formValues:",e),b&&L&&(e.user_email=w,S&&t&&(0,p.claimOnboardingToken)(b,t,S,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+L,console.log("redirecting to:",s);let t=(0,p.getProxyBaseUrl)();console.log("proxyBaseUrl:",t),t?window.location.href=t+s:window.location.href=s}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(u.Z,{type:"email",disabled:!0,value:w,defaultValue:w,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"reset_password"===y?"Enter your new password":"Create a password for your account",children:(0,l.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(f.ZP,{htmlType:"submit",children:"reset_password"===y?"Reset Password":"Sign Up"})})]})]})})}},85617:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return oZ}});var l,a,r,i,n,o,c=t(57437),d=t(2265),m=t(99376),u=t(14474),x=t(21623),h=t(29827),p=t(65373),g=t(69734),j=t(19250);let f=async(e,s,t,l,a)=>{let r;r="Admin"!=t&&"Admin Viewer"!=t?await (0,j.teamListCall)(e,(null==l?void 0:l.organization_id)||null,s):await (0,j.teamListCall)(e,(null==l?void 0:l.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var v=t(49804),y=t(67101),b=t(20831),_=t(49566),N=t(87452),Z=t(88829),w=t(72208),k=t(84264),S=t(96761),C=t(29233),I=t(52787),A=t(13634),L=t(82680),T=t(29967),P=t(73002),E=t(64482),M=t(30150),O=e=>{let{step:s=.01,style:t={width:"100%"},placeholder:l="Enter a numerical value",min:a,max:r,onChange:i,...n}=e;return(0,c.jsx)(M.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:t,placeholder:l,min:a,max:r,onChange:i,...n})};let D=async(e,s,t)=>{try{if(null===e||null===s)return;if(null!==t){let l=(await (0,j.modelAvailableCall)(t,e,s,!0,null,!0)).data.map(e=>e.id),a=[],r=[];return l.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},F=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},R=(e,s)=>{let t=[],l=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));l.push(...r),t.push(e)}else l.push(e)}),[...t,...l].filter((e,s,t)=>t.indexOf(e)===s)};var z=t(63610),U=e=>{let{onChange:s,value:t,className:l,accessToken:a,placeholder:r="Select vector stores",disabled:i=!1}=e,[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a){u(!0);try{let e=await (0,j.vectorStoreListCall)(a);e.data&&o(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{u(!1)}}})()},[a]),(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:r,onChange:s,value:t,loading:m,className:l,options:n.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"},disabled:i})})},q=e=>{let{teams:s,value:t,onChange:l,disabled:a}=e;return console.log("disabled",a),(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:t,onChange:l,disabled:a,filterOption:(e,t)=>{if(!t)return!1;let l=null==s?void 0:s.find(e=>e.team_id===t.key);if(!l)return!1;let a=e.toLowerCase().trim(),r=(l.team_alias||"").toLowerCase(),i=(l.team_id||"").toLowerCase();return r.includes(a)||i.includes(a)},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,c.jsxs)(I.default.Option,{value:e.team_id,children:[(0,c.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,c.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},B=t(15424),V=t(89970),K=t(23496),G=t(12514),H=t(91777),J=t(82182),Y=t(22452),W=t(74998);(l=i||(i={})).Braintrust="Braintrust",l.CustomCallbackAPI="Custom Callback API",l.Datadog="Datadog",l.Langfuse="Langfuse",l.LangfuseOtel="LangfuseOtel",l.LangSmith="LangSmith",l.Lago="Lago",l.OpenMeter="OpenMeter",l.OTel="Open Telemetry",l.S3="S3",l.Arize="Arize";let $={Braintrust:"braintrust",CustomCallbackAPI:"custom_callback_api",Datadog:"datadog",Langfuse:"langfuse",LangfuseOtel:"langfuse_otel",LangSmith:"langsmith",Lago:"lago",OpenMeter:"openmeter",OTel:"otel",S3:"s3",Arize:"arize"},Q=Object.fromEntries(Object.entries($).map(e=>{let[s,t]=e;return[t,s]})),X=e=>e.map(e=>Q[e]||e),ee=e=>e.map(e=>$[e]||e),es="/ui/assets/logos/",et={Langfuse:{logo:"".concat(es,"langfuse.png"),supports_key_team_logging:!0,dynamic_params:{langfuse_public_key:"text",langfuse_secret_key:"password",langfuse_host:"text"},description:"Langfuse v2 Logging Integration"},LangfuseOtel:{logo:"".concat(es,"langfuse.png"),supports_key_team_logging:!0,dynamic_params:{langfuse_public_key:"text",langfuse_secret_key:"password",langfuse_host:"text"},description:"Langfuse v3 OTEL Logging Integration"},Arize:{logo:"".concat(es,"arize.png"),supports_key_team_logging:!0,dynamic_params:{arize_api_key:"password",arize_space_id:"text"},description:"Arize Logging Integration"},LangSmith:{logo:"".concat(es,"langsmith.png"),supports_key_team_logging:!0,dynamic_params:{langsmith_api_key:"password",langsmith_project:"text",langsmith_base_url:"text",langsmith_sampling_rate:"number"},description:"Langsmith Logging Integration"},Braintrust:{logo:"".concat(es,"braintrust.png"),supports_key_team_logging:!1,dynamic_params:{},description:"Braintrust Logging Integration"},"Custom Callback API":{logo:"".concat(es,"custom.svg"),supports_key_team_logging:!0,dynamic_params:{},description:"Custom Callback API Logging Integration"},Datadog:{logo:"".concat(es,"datadog.png"),supports_key_team_logging:!1,dynamic_params:{},description:"Datadog Logging Integration"},Lago:{logo:"".concat(es,"lago.svg"),supports_key_team_logging:!1,dynamic_params:{},description:"Lago Billing Logging Integration"},OpenMeter:{logo:"".concat(es,"openmeter.png"),supports_key_team_logging:!1,dynamic_params:{},description:"OpenMeter Logging Integration"},"Open Telemetry":{logo:"".concat(es,"otel.png"),supports_key_team_logging:!1,dynamic_params:{},description:"OpenTelemetry Logging Integration"},S3:{logo:"".concat(es,"aws.svg"),supports_key_team_logging:!1,dynamic_params:{},description:"S3 Bucket (AWS) Logging Integration"}},{Option:el}=I.default;var ea=e=>{let{value:s=[],onChange:t,disabledCallbacks:l=[],onDisabledCallbacksChange:a}=e,r=Object.entries(et).filter(e=>{let[s,t]=e;return t.supports_key_team_logging}).map(e=>{let[s,t]=e;return s}),i=Object.keys(et),n=e=>{null==t||t(e)},o=e=>{n(s.filter((s,t)=>t!==e))},d=(e,t,l)=>{let a=[...s];if("callback_name"===t){let s=$[l]||l;a[e]={...a[e],[t]:s,callback_vars:{}}}else a[e]={...a[e],[t]:l};n(a)},m=(e,t,l)=>{let a=[...s];a[e]={...a[e],callback_vars:{...a[e].callback_vars,[t]:l}},n(a)},u=(e,s)=>{var t,l;if(!e.callback_name)return null;let a=null===(t=Object.entries($).find(s=>{let[t,l]=s;return l===e.callback_name}))||void 0===t?void 0:t[0];if(!a)return null;let r=(null===(l=et[a])||void 0===l?void 0:l.dynamic_params)||{};return 0===Object.keys(r).length?null:(0,c.jsxs)("div",{className:"mt-6 pt-4 border-t border-gray-100",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-4",children:[(0,c.jsx)("div",{className:"w-3 h-3 bg-blue-100 rounded-full flex items-center justify-center",children:(0,c.jsx)("div",{className:"w-1.5 h-1.5 bg-blue-500 rounded-full"})}),(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Integration Parameters"})]}),(0,c.jsx)("div",{className:"grid grid-cols-1 gap-4",children:Object.entries(r).map(t=>{let[l,a]=t;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("label",{className:"text-sm font-medium text-gray-700 capitalize flex items-center space-x-1",children:[(0,c.jsx)("span",{children:l.replace(/_/g," ")}),(0,c.jsx)(V.Z,{title:"Environment variable reference recommended: os.environ/".concat(l.toUpperCase()),children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help text-xs"})}),"password"===a&&(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:"Sensitive"}),"number"===a&&(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:"Number"})]}),"number"===a&&(0,c.jsx)("span",{className:"text-xs text-gray-500",children:"Value must be between 0 and 1"}),"number"===a?(0,c.jsx)(O,{step:.01,width:400,placeholder:"os.environ/".concat(l.toUpperCase()),value:e.callback_vars[l]||"",onChange:e=>m(s,l,e.target.value)}):(0,c.jsx)(_.Z,{type:"password"===a?"password":"text",placeholder:"os.environ/".concat(l.toUpperCase()),value:e.callback_vars[l]||"",onChange:e=>m(s,l,e.target.value)})]},l)})})]})};return(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(H.Z,{className:"w-5 h-5 text-red-500"}),(0,c.jsx)("span",{className:"text-base font-semibold text-gray-800",children:"Disabled Callbacks"}),(0,c.jsx)(V.Z,{title:"Select callbacks to disable for this key. Disabled callbacks will not receive any logging data.",children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help"})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Disabled Callbacks"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select callbacks to disable",value:l,onChange:e=>{let s=ee(e);null==a||a(s)},style:{width:"100%"},optionLabelProp:"label",children:i.map(e=>{var s,t;let l=null===(s=et[e])||void 0===s?void 0:s.logo,a=null===(t=et[e])||void 0===t?void 0:t.description;return(0,c.jsx)(el,{value:e,label:e,children:(0,c.jsx)(V.Z,{title:a,placement:"right",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,c.jsx)("img",{src:l,alt:e,className:"w-4 h-4 object-contain",onError:s=>{let t=s.target,l=t.parentElement;if(l){let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=e.charAt(0),l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e})]})})},e)})}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"Select callbacks that should be disabled for this key. These callbacks will not receive any logging data."})]})]}),(0,c.jsx)(K.Z,{}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(J.Z,{className:"w-5 h-5 text-blue-500"}),(0,c.jsx)("span",{className:"text-base font-semibold text-gray-800",children:"Logging Integrations"}),(0,c.jsx)(V.Z,{title:"Configure callback logging integrations for this team.",children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help"})})]}),(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{n([...s,{callback_name:"",callback_type:"success",callback_vars:{}}])},icon:Y.Z,size:"sm",className:"hover:border-blue-400 hover:text-blue-500",type:"button",children:"Add Integration"})]}),(0,c.jsx)("div",{className:"space-y-4",children:s.map((e,s)=>{var t,l;let a=e.callback_name?null===(t=Object.entries($).find(s=>{let[t,l]=s;return l===e.callback_name}))||void 0===t?void 0:t[0]:void 0,i=a?null===(l=et[a])||void 0===l?void 0:l.logo:null;return(0,c.jsxs)(G.Z,{className:"border border-gray-200 shadow-sm hover:shadow-md transition-shadow duration-200",decoration:"top",decorationColor:"blue",children:[(0,c.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[i&&(0,c.jsx)("img",{src:i,alt:a,className:"w-5 h-5 object-contain"}),(0,c.jsxs)("span",{className:"text-sm font-medium",children:[a||"New Integration"," Configuration"]})]}),(0,c.jsx)(b.Z,{variant:"light",onClick:()=>o(s),icon:W.Z,size:"xs",color:"red",className:"hover:bg-red-50",type:"button",children:"Remove"})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Integration Type"}),(0,c.jsx)(I.default,{value:a,placeholder:"Select integration",onChange:e=>d(s,"callback_name",e),className:"w-full",optionLabelProp:"label",children:r.map(e=>{var s,t;let l=null===(s=et[e])||void 0===s?void 0:s.logo,a=null===(t=et[e])||void 0===t?void 0:t.description;return(0,c.jsx)(el,{value:e,label:e,children:(0,c.jsx)(V.Z,{title:a,placement:"right",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,c.jsx)("img",{src:l,alt:e,className:"w-4 h-4 object-contain",onError:s=>{let t=s.target,l=t.parentElement;if(l){let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=e.charAt(0),l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e})]})})},e)})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Event Type"}),(0,c.jsxs)(I.default,{value:e.callback_type,onChange:e=>d(s,"callback_type",e),className:"w-full",children:[(0,c.jsx)(el,{value:"success",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{children:"Success Only"})]})}),(0,c.jsx)(el,{value:"failure",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-red-500 rounded-full"}),(0,c.jsx)("span",{children:"Failure Only"})]})}),(0,c.jsx)(el,{value:"success_and_failure",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{children:"Success & Failure"})]})})]})]})]}),u(e,s)]})]},s)})}),0===s.length&&(0,c.jsxs)("div",{className:"text-center py-12 text-gray-500 border-2 border-dashed border-gray-200 rounded-lg bg-gray-50/50",children:[(0,c.jsx)(J.Z,{className:"w-12 h-12 text-gray-300 mb-3 mx-auto"}),(0,c.jsx)("div",{className:"text-base font-medium mb-1",children:"No logging integrations configured"}),(0,c.jsx)("div",{className:"text-sm text-gray-400",children:'Click "Add Integration" to configure logging for this team'})]})]})},er=function(e){let{value:s,onChange:t,premiumUser:l=!1,disabledCallbacks:a=[],onDisabledCallbacksChange:r}=e;return l?(0,c.jsx)(ea,{value:s,onChange:t,disabledCallbacks:a,onDisabledCallbacksChange:r}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex flex-wrap gap-2 mb-3",children:[(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium opacity-50",children:"✨ langfuse-logging"}),(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium opacity-50",children:"✨ datadog-logging"})]}),(0,c.jsx)("div",{className:"p-3 bg-yellow-50 border border-yellow-200 rounded-lg",children:(0,c.jsxs)(k.Z,{className:"text-sm text-yellow-800",children:["Setting Key/Team logging settings is a LiteLLM Enterprise feature. Global Logging Settings are available for all free users. Get a trial key ",(0,c.jsx)("a",{href:"https://www.litellm.ai/#pricing",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"here"}),"."]})})]})},ei=t(57365),en=t(93192),eo=t(9114);function ec(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:t,baseUrl:l,invitationLinkData:a,modalType:r="invitation"}=e,{Title:i,Paragraph:n}=en.default,o=()=>{if(!l)return"";let e=new URL(l).pathname,s=e&&"/"!==e?"".concat(e,"/ui"):"ui";if(null==a?void 0:a.has_user_setup_sso)return new URL(s,l).toString();let t="".concat(s,"?invitation_id=").concat(null==a?void 0:a.id);return"resetPassword"===r&&(t+="&action=reset_password"),new URL(t,l).toString()};return(0,c.jsxs)(L.Z,{title:"invitation"===r?"Invitation Link":"Reset Password Link",visible:s,width:800,footer:null,onOk:()=>{t(!1)},onCancel:()=>{t(!1)},children:[(0,c.jsx)(n,{children:"invitation"===r?"Copy and send the generated link to onboard this user to the proxy.":"Copy and send the generated link to the user to reset their password."}),(0,c.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,c.jsx)(k.Z,{className:"text-base",children:"User ID"}),(0,c.jsx)(k.Z,{children:null==a?void 0:a.user_id})]}),(0,c.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,c.jsx)(k.Z,{children:"invitation"===r?"Invitation Link":"Reset Password Link"}),(0,c.jsx)(k.Z,{children:(0,c.jsx)(k.Z,{children:o()})})]}),(0,c.jsx)("div",{className:"flex justify-end mt-5",children:(0,c.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>eo.Z.success("Copied!"),children:(0,c.jsx)(b.Z,{variant:"primary",children:"invitation"===r?"Copy invitation link":"Copy password reset link"})})})]})}var ed=t(65319),em=t(72188),eu=t(73879),ex=t(34310),eh=t(38434),ep=t(26349),eg=t(35291),ej=t(3632),ef=t(15452),ev=t.n(ef),ey=t(71157),eb=t(44643),e_=t(88532),eN=e=>{let{accessToken:s,teams:t,possibleUIRoles:l,onUsersCreated:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(null),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(null),[w,S]=(0,d.useState)("http://localhost:4000");(0,d.useEffect)(()=>{(async()=>{try{let e=await (0,j.getProxyUISettings)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),S(new URL("/",window.location.href).toString())},[s]);let I=async()=>{u(!0);let e=n.map(e=>({...e,status:"pending"}));o(e);let t=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),n.models&&"string"==typeof n.models&&""!==n.models.trim()&&(e.models=n.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),n.max_budget&&""!==n.max_budget.toString().trim()){let s=parseFloat(n.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}n.budget_duration&&""!==n.budget_duration.trim()&&(e.budget_duration=n.budget_duration.trim()),n.metadata&&"string"==typeof n.metadata&&""!==n.metadata.trim()&&(e.metadata=n.metadata.trim()),console.log("Sending user data:",e);let r=await (0,j.userCreateCall)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){t=!0,console.log("Success case triggered");let e=(null===(l=r.data)||void 0===l?void 0:l.user_id)||r.user_id;try{if(null==N?void 0:N.SSO_ENABLED){let e=new URL("/ui",w).toString();o(s=>s.map((s,t)=>t===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let t=await (0,j.invitationCreateCall)(s,e),l=new URL("/ui?invitation_id=".concat(t.id),w).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:l}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===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),o(s=>s.map((s,t)=>t===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(i=s.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,t)=>t===a?{...s,status:"failed",error:e}:s))}}u(!1),t&&a&&a()};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(b.Z,{className:"mb-0",onClick:()=>i(!0),children:"+ Bulk Invite Users"}),(0,c.jsx)(L.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>i(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,c.jsx)("div",{className:"flex flex-col",children:0===n.length?(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,c.jsxs)("div",{className:"ml-11 mb-6",children:[(0,c.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,c.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,c.jsx)("li",{children:"Download our CSV template"}),(0,c.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,c.jsx)("li",{children:"Save the file and upload it here"}),(0,c.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,c.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"user_email"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"user_role"}),(0,c.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,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"teams"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"models"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,c.jsxs)(b.Z,{onClick:()=>{let e=new Blob([ev().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"}),s=window.URL.createObjectURL(e),t=document.createElement("a");t.href=s,t.download="bulk_users_template.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,c.jsx)(eu.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,c.jsxs)("div",{className:"ml-11",children:[y?(0,c.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(f?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[f?(0,c.jsx)(ex.Z,{className:"text-red-500 text-xl mr-3"}):(0,c.jsx)(eh.Z,{className:"text-blue-500 text-xl mr-3"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(en.default.Text,{strong:!0,className:f?"text-red-800":"text-blue-800",children:y.name}),(0,c.jsxs)(en.default.Text,{className:"block text-xs ".concat(f?"text-red-600":"text-blue-600"),children:[(y.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,c.jsxs)(b.Z,{size:"xs",variant:"secondary",onClick:()=>{_(null),o([]),h(null),g(null),v(null)},className:"flex items-center",children:[(0,c.jsx)(ep.Z,{className:"mr-1"})," Remove"]})]}),f?(0,c.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,c.jsx)(eg.Z,{className:"mr-2 mt-0.5"}),(0,c.jsx)("span",{children:f})]}):!p&&(0,c.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,c.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,c.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,c.jsx)(ed.default,{beforeUpload:e=>((h(null),g(null),v(null),_(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?v("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ev().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let l=["user_email","user_role"].filter(e=>!s.includes(e));if(l.length>0){g("Your CSV is missing these required columns: ".concat(l.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let l=e.data.slice(1).map((e,l)=>{var a,r,i,n,o,c;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(d.max_budget.toString())&&m.push("Max budget must be greater than 0")),d.budget_duration&&!d.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(d.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),d.teams&&"string"==typeof d.teams&&t&&t.length>0){let e=t.map(e=>e.team_id),s=d.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(d.isValid=!1,d.error=m.join(", ")),d}).filter(Boolean),a=l.filter(e=>e.isValid);o(l),0===l.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?h("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{h("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(v("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),eo.Z.fromBackend("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,c.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,c.jsx)(ej.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,c.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,c.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,c.jsx)(b.Z,{size:"sm",children:"Browse files"}),(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,c.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(e_.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(en.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,c.jsx)(en.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,c.jsx)(en.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:n.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),x&&(0,c.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(eg.Z,{className:"text-red-500 mr-2 mt-1"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-red-600 font-medium",children:x}),n.some(e=>!e.isValid)&&(0,c.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,c.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,c.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,c.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,c.jsxs)("div",{className:"ml-11",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,c.jsx)("div",{className:"flex items-center",children:n.some(e=>"success"===e.status||"failed"===e.status)?(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,c.jsxs)(k.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[n.filter(e=>"success"===e.status).length," Successful"]}),n.some(e=>"failed"===e.status)&&(0,c.jsxs)(k.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[n.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,c.jsxs)(k.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[n.filter(e=>e.isValid).length," of ",n.length," users valid"]})]})}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex space-x-3",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",children:"Back"}),(0,c.jsx)(b.Z,{onClick:I,disabled:0===n.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]})]}),n.some(e=>"success"===e.status)&&(0,c.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"mr-3 mt-1",children:(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-blue-500"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,c.jsxs)(k.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,c.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,c.jsx)(em.Z,{dataSource:n,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,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,c.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,c.jsx)("div",{className:"mt-1",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,c.jsx)(C.CopyToClipboard,{text:s.invitation_link,onCopy:()=>eo.Z.success("Invitation link copied!"),children:(0,c.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,c.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,c.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,c.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,c.jsx)(b.Z,{onClick:I,disabled:0===n.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]}),n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,c.jsxs)(b.Z,{onClick:()=>{let e=n.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||""})),s=new Blob([ev().unparse(e)],{type:"text/csv"}),t=window.URL.createObjectURL(s),l=document.createElement("a");l.href=t,l.download="bulk_users_results.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(t)},variant:"primary",className:"flex items-center",children:[(0,c.jsx)(eu.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:eZ}=I.default,ew=()=>"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let s=16*Math.random()|0;return("x"==e?s:3&s|8).toString(16)});var ek=e=>{let{userID:s,accessToken:t,teams:l,possibleUIRoles:a,onUserCreated:r,isEmbedded:i=!1}=e,n=(0,h.NL)(),[o,m]=(0,d.useState)(null),[u]=A.Z.useForm(),[x,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),[C,T]=(0,d.useState)(!1),[M,O]=(0,d.useState)(null),[D,R]=(0,d.useState)(null);(0,d.useEffect)(()=>{let e=async()=>{try{let e=await (0,j.modelAvailableCall)(t,s,"any"),l=[];for(let s=0;s{var l,a,c;try{eo.Z.info("Making API Call"),i||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.userCreateCall)(t,null,e);await n.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let c=(null===(l=a.data)||void 0===l?void 0:l.user_id)||a.user_id;if(r&&i){r(c),u.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:ew(),user_id:c,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};O(e),T(!0)}else(0,j.invitationCreateCall)(t,c).then(e=>{e.has_user_setup_sso=!1,O(e),T(!0)});eo.Z.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(c=s.response)||void 0===c?void 0:null===(a=c.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";eo.Z.fromBackend(e),console.error("Error creating the user:",s)}};return i?(0,c.jsxs)(A.Z,{form:u,onFinish:z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,c.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,c.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:l?l.map(e=>(0,c.jsx)(eZ,{value:e.team_id,children:e.team_alias},e.team_id)):(0,c.jsx)(eZ,{value:null,children:"Default Team"},"default")})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{className:"mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,c.jsx)(eN,{accessToken:t,teams:l,possibleUIRoles:a}),(0,c.jsxs)(L.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),u.resetFields()},onCancel:()=>{p(!1),f(!1),u.resetFields()},children:[(0,c.jsx)(k.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,c.jsxs)(A.Z,{form:u,onFinish:z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Global Proxy Role"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{})})]}),name:"user_role",children:(0,c.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.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,c.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:l?l.map(e=>(0,c.jsx)(eZ,{value:e.team_id,children:e.team_alias},e.team_id)):(0,c.jsx)(eZ,{value:null,children:"Default Team"},"default")})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsxs)(N.Z,{children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)(A.Z.Item,{className:"gap-2",label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.Z,{title:"Models user has access to, outside of team scope.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),v.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})})})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create User"})})]})]}),g&&(0,c.jsx)(ec,{isInvitationLinkModalVisible:C,setIsInvitationLinkModalVisible:T,baseUrl:D||"",invitationLinkData:M})]})},eS=t(7310),eC=t.n(eS),eI=t(20347);let{Option:eA}=I.default,eL=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var eT=e=>{let{value:s,onChange:t,className:l="",style:a={}}=e;return(0,c.jsxs)(I.default,{style:{width:"100%",...a},value:s||void 0,onChange:t,className:l,placeholder:"n/a",children:[(0,c.jsx)(eA,{value:"24h",children:"daily"}),(0,c.jsx)(eA,{value:"7d",children:"weekly"}),(0,c.jsx)(eA,{value:"30d",children:"monthly"})]})};function eP(e,s){let t=structuredClone(e);for(let[e,l]of Object.entries(s))e in t&&(t[e]=l);return t}let eE=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return null==e?"-":e.toLocaleString("en-US",{minimumFractionDigits:s,maximumFractionDigits:s})},eM=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Copied to clipboard";if(!e)return!1;try{return await navigator.clipboard.writeText(e),eo.Z.success(s),!0}catch(e){return eo.Z.fromBackend("Failed to copy to clipboard"),console.error("Failed to copy: ",e),!1}};var eO=e=>{let{onChange:s,value:t,className:l,accessToken:a,placeholder:r="Select MCP servers",disabled:i=!1}=e,[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(a){h(!0);try{let[e,s]=await Promise.all([(0,j.fetchMCPServers)(a),(0,j.fetchMCPAccessGroups)(a)]),t=Array.isArray(e)?e:e.data||[],l=Array.isArray(s)?s:s.data||[];o(t),u(l)}catch(e){console.error("Error fetching MCP servers or access groups:",e)}finally{h(!1)}}})()},[a]);let p=[...m.map(e=>({label:e,value:e,isAccessGroup:!0,searchText:"".concat(e," Access Group")})),...n.map(e=>({label:"".concat(e.server_name||e.server_id," (").concat(e.server_id,")"),value:e.server_id,isAccessGroup:!1,searchText:"".concat(e.server_name||e.server_id," ").concat(e.server_id," MCP Server")}))],g=[...(null==t?void 0:t.servers)||[],...(null==t?void 0:t.accessGroups)||[]];return(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:r,onChange:e=>{s({servers:e.filter(e=>!m.includes(e)),accessGroups:e.filter(e=>m.includes(e))})},value:g,loading:x,className:l,showSearch:!0,style:{width:"100%"},disabled:i,filterOption:(e,s)=>{var t;return((null===(t=p.find(e=>e.value===(null==s?void 0:s.value)))||void 0===t?void 0:t.searchText)||"").toLowerCase().includes(e.toLowerCase())},children:p.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,label:e.label,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,c.jsx)("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:e.isAccessGroup?"#52c41a":"#1890ff",flexShrink:0}}),(0,c.jsx)("span",{style:{flex:1},children:e.label}),(0,c.jsx)("span",{style:{color:e.isAccessGroup?"#52c41a":"#1890ff",fontSize:"12px",fontWeight:500,opacity:.8},children:e.isAccessGroup?"Access Group":"MCP Server"})]})},e.value))})})},eD=t(77355),eF=t(93416),eR=t(95704),ez=t(69993);let eU=async e=>{try{let s=await (0,j.modelHubCall)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};var eq=e=>{let{accessToken:s,value:t,placeholder:l="Select a Model",onChange:a,disabled:r=!1,style:i,className:n,showLabel:o=!0,labelText:m="Select Model"}=e,[u,x]=(0,d.useState)(t),[h,p]=(0,d.useState)(!1),[g,j]=(0,d.useState)([]),f=(0,d.useRef)(null);return(0,d.useEffect)(()=>{x(t)},[t]),(0,d.useEffect)(()=>{s&&(async()=>{try{let e=await eU(s);console.log("Fetched models for selector:",e),e.length>0&&j(e)}catch(e){console.error("Error fetching model info:",e)}})()},[s]),(0,c.jsxs)("div",{children:[o&&(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(ez.Z,{className:"mr-2"})," ",m]}),(0,c.jsx)(I.default,{value:u,placeholder:l,onChange:e=>{"custom"===e?(p(!0),x(void 0)):(p(!1),x(e),a&&a(e))},options:[...Array.from(new Set(g.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%",...i},showSearch:!0,className:"rounded-md ".concat(n||""),disabled:r}),h&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{x(e),a&&a(e)},500)},disabled:r})]})},eB=e=>{let{accessToken:s,initialModelAliases:t={},onAliasUpdate:l,showExampleConfig:a=!0}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)({aliasName:"",targetModel:""}),[m,u]=(0,d.useState)(null);(0,d.useEffect)(()=>{i(Object.entries(t).map((e,s)=>{let[t,l]=e;return{id:"".concat(s,"-").concat(t),aliasName:t,targetModel:l}}))},[t]);let x=e=>{u({...e})},h=()=>{if(!m)return;if(!m.aliasName||!m.targetModel){eo.Z.fromBackend("Please provide both alias name and target model");return}if(r.some(e=>e.id!==m.id&&e.aliasName===m.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=r.map(e=>e.id===m.id?m:e);i(e),u(null);let s={};e.forEach(e=>{s[e.aliasName]=e.targetModel}),l&&l(s),eo.Z.success("Alias updated successfully")},p=()=>{u(null)},g=e=>{let s=r.filter(s=>s.id!==e);i(s);let t={};s.forEach(e=>{t[e.aliasName]=e.targetModel}),l&&l(t),eo.Z.success("Alias deleted successfully")},j=r.reduce((e,s)=>(e[s.aliasName]=s.targetModel,e),{});return(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Add New Alias"}),(0,c.jsxs)("div",{className:"grid grid-cols-3 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Alias Name"}),(0,c.jsx)("input",{type:"text",value:n.aliasName,onChange:e=>o({...n,aliasName:e.target.value}),placeholder:"e.g., gpt-4o",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Target Model"}),(0,c.jsx)(eq,{accessToken:s,value:n.targetModel,placeholder:"Select target model",onChange:e=>o({...n,targetModel:e}),showLabel:!1})]}),(0,c.jsx)("div",{className:"flex items-end",children:(0,c.jsxs)("button",{onClick:()=>{if(!n.aliasName||!n.targetModel){eo.Z.fromBackend("Please provide both alias name and target model");return}if(r.some(e=>e.aliasName===n.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=[...r,{id:"".concat(Date.now(),"-").concat(n.aliasName),aliasName:n.aliasName,targetModel:n.targetModel}];i(e),o({aliasName:"",targetModel:""});let s={};e.forEach(e=>{s[e.aliasName]=e.targetModel}),l&&l(s),eo.Z.success("Alias added successfully")},disabled:!n.aliasName||!n.targetModel,className:"flex items-center px-4 py-2 rounded-md text-sm ".concat(n.aliasName&&n.targetModel?"bg-green-600 text-white hover:bg-green-700":"bg-gray-300 text-gray-500 cursor-not-allowed"),children:[(0,c.jsx)(eD.Z,{className:"w-4 h-4 mr-1"}),"Add Alias"]})})]})]}),(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Manage Existing Aliases"}),(0,c.jsx)("div",{className:"rounded-lg custom-border relative mb-6",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(eR.iA,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(eR.ss,{children:(0,c.jsxs)(eR.SC,{children:[(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Alias Name"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Target Model"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Actions"})]})}),(0,c.jsxs)(eR.RM,{children:[r.map(e=>(0,c.jsx)(eR.SC,{className:"h-8",children:m&&m.id===e.id?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:m.aliasName,onChange:e=>u({...m,aliasName:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)(eq,{accessToken:s,value:m.targetModel,onChange:e=>u({...m,targetModel:e}),showLabel:!1,style:{height:"32px"}})}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:h,className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:"Save"}),(0,c.jsx)("button",{onClick:p,className:"text-xs bg-gray-50 text-gray-600 px-2 py-1 rounded hover:bg-gray-100",children:"Cancel"})]})})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-900",children:e.aliasName}),(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-500",children:e.targetModel}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>x(e),className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:(0,c.jsx)(eF.Z,{className:"w-3 h-3"})}),(0,c.jsx)("button",{onClick:()=>g(e.id),className:"text-xs bg-red-50 text-red-600 px-2 py-1 rounded hover:bg-red-100",children:(0,c.jsx)(W.Z,{className:"w-3 h-3"})})]})})]})},e.id)),0===r.length&&(0,c.jsx)(eR.SC,{children:(0,c.jsx)(eR.pj,{colSpan:3,className:"py-0.5 text-sm text-gray-500 text-center",children:"No aliases added yet. Add a new alias above."})})]})]})})}),a&&(0,c.jsxs)(eR.Zb,{children:[(0,c.jsx)(eR.Dx,{className:"mb-4",children:"Configuration Example"}),(0,c.jsx)(eR.xv,{className:"text-gray-600 mb-4",children:"Here's how your current aliases would look in the config:"}),(0,c.jsx)("div",{className:"bg-gray-100 rounded-lg p-4 font-mono text-sm",children:(0,c.jsxs)("div",{className:"text-gray-700",children:["model_aliases:",0===Object.keys(j).length?(0,c.jsxs)("span",{className:"text-gray-500",children:[(0,c.jsx)("br",{}),"\xa0\xa0# No aliases configured yet"]}):Object.entries(j).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[(0,c.jsx)("br",{}),'\xa0\xa0"',s,'": "',t,'"']},s)})]})})]})]})};let{Option:eV}=I.default,eK=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let t of e)t.metadata&&t.metadata.tags&&s.push(...t.metadata.tags);let t=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",t),t},eG=async(e,s,t,l)=>{try{if(null===e||null===s)return[];if(null!==t){let a=(await (0,j.modelAvailableCall)(t,e,s,!0,l,!0)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eH=async(e,s,t,l)=>{try{if(null===e||null===s)return;if(null!==t){let a=(await (0,j.modelAvailableCall)(t,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),l(a)}}catch(e){console.error("Error fetching user models:",e)}};var eJ=e=>{let{userID:s,team:t,teams:l,userRole:a,accessToken:r,data:i,addKey:n,premiumUser:o=!1}=e,[m]=A.Z.useForm(),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(null),[M,D]=(0,d.useState)([]),[R,K]=(0,d.useState)([]),[G,H]=(0,d.useState)("you"),[J,Y]=(0,d.useState)(eK(i)),[W,$]=(0,d.useState)([]),[Q,X]=(0,d.useState)([]),[es,et]=(0,d.useState)([]),[el,ea]=(0,d.useState)(t),[ei,en]=(0,d.useState)(!1),[ec,ed]=(0,d.useState)(null),[em,eu]=(0,d.useState)({}),[ex,eh]=(0,d.useState)([]),[ep,eg]=(0,d.useState)(!1),[ej,ef]=(0,d.useState)([]),[ev,ey]=(0,d.useState)(!1),[eb,e_]=(0,d.useState)([]),[eN,eZ]=(0,d.useState)("default"),[ew,eS]=(0,d.useState)({}),eA=()=>{x(!1),m.resetFields(),et([]),e_([]),eZ("default"),eS({})},eL=()=>{x(!1),p(null),ea(null),m.resetFields(),et([]),e_([]),eZ("default"),eS({})};(0,d.useEffect)(()=>{s&&a&&r&&eH(s,a,r,D)},[r,s,a]);let eP=async()=>{try{if(null==r)return;let e=await (0,j.fetchMCPAccessGroups)(r);ef(e)}catch(e){console.error("Failed to fetch MCP access groups:",e)}};(0,d.useEffect)(()=>{eP()},[r]),(0,d.useEffect)(()=>{let e=async()=>{try{let e=await (0,j.getPromptsList)(r);X(e.prompts.map(e=>e.prompt_id))}catch(e){console.error("Failed to fetch prompts:",e)}};(async()=>{try{let e=(await (0,j.getGuardrailsList)(r)).guardrails.map(e=>e.guardrail_name);$(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})(),e()},[r]),(0,d.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)eu(JSON.parse(e));else{let e=await (0,j.getPossibleUserRoles)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),eu(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let eM=R.includes("no-default-models")&&!el,eD=async e=>{try{var t,l,a,o,c;let d;let u=null!==(a=null==e?void 0:e.key_alias)&&void 0!==a?a:"",h=null!==(o=null==e?void 0:e.team_id)&&void 0!==o?o:null;if((null!==(c=null==i?void 0:i.filter(e=>e.team_id===h).map(e=>e.key_alias))&&void 0!==c?c:[]).includes(u))throw Error("Key alias ".concat(u," already exists for team with ID ").concat(h,", please provide another key alias"));eo.Z.info("Making API Call"),x(!0),"you"===G&&(e.user_id=s);let g={};try{g=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}if("service_account"===G&&(g.service_account_id=e.key_alias),es.length>0&&(g={...g,logging:es.filter(e=>e.callback_name)}),eb.length>0){let e=ee(eb);g={...g,litellm_disabled_callbacks:e}}if(e.metadata=JSON.stringify(g),e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission={vector_stores:e.allowed_vector_store_ids},delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups&&((null===(t=e.allowed_mcp_servers_and_groups.servers)||void 0===t?void 0:t.length)>0||(null===(l=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===l?void 0:l.length)>0)){e.object_permission||(e.object_permission={});let{servers:s,accessGroups:t}=e.allowed_mcp_servers_and_groups;s&&s.length>0&&(e.object_permission.mcp_servers=s),t&&t.length>0&&(e.object_permission.mcp_access_groups=t),delete e.allowed_mcp_servers_and_groups}e.allowed_mcp_access_groups&&e.allowed_mcp_access_groups.length>0&&(e.object_permission||(e.object_permission={}),e.object_permission.mcp_access_groups=e.allowed_mcp_access_groups,delete e.allowed_mcp_access_groups),Object.keys(ew).length>0&&(e.aliases=JSON.stringify(ew)),d="service_account"===G?await (0,j.keyCreateServiceAccountCall)(r,e):await (0,j.keyCreateCall)(r,s,e),console.log("key create Response:",d),n(d),p(d.key),f(d.soft_budget),eo.Z.success("API Key Created"),m.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};(0,d.useEffect)(()=>{if(s&&a&&r){var e;eG(s,a,r,null!==(e=null==el?void 0:el.team_id)&&void 0!==e?e:null).then(e=>{var s;K(Array.from(new Set([...null!==(s=null==el?void 0:el.models)&&void 0!==s?s:[],...e])))})}m.setFieldValue("models",[])},[el,r,s,a]);let eF=async e=>{if(!e){eh([]);return}eg(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let t=(await (0,j.userFilterUICall)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eh(t)}catch(e){console.error("Error fetching users:",e),eo.Z.fromBackend("Failed to search for users")}finally{eg(!1)}},eR=(0,d.useCallback)(eC()(e=>eF(e),300),[r]),ez=(e,s)=>{let t=s.user;m.setFieldsValue({user_id:t.user_id})};return(0,c.jsxs)("div",{children:[a&&eI.LQ.includes(a)&&(0,c.jsx)(b.Z,{className:"mx-auto",onClick:()=>x(!0),children:"+ Create New Key"}),(0,c.jsx)(L.Z,{visible:u,width:1e3,footer:null,onOk:eA,onCancel:eL,children:(0,c.jsxs)(A.Z,{form:m,onFinish:eD,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Owned By"," ",(0,c.jsx)(V.Z,{title:"Select who will own this API key",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,c.jsxs)(T.ZP.Group,{onChange:e=>H(e.target.value),value:G,children:[(0,c.jsx)(T.ZP,{value:"you",children:"You"}),(0,c.jsx)(T.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,c.jsx)(T.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===G&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["User ID"," ",(0,c.jsx)(V.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===G,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eR(e)},onSelect:(e,s)=>ez(e,s),options:ex,loading:ep,allowClear:!0,style:{width:"100%"},notFoundContent:ep?"Searching...":"No users found"}),(0,c.jsx)(P.ZP,{onClick:()=>en(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Team"," ",(0,c.jsx)(V.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:t?t.team_id:null,className:"mt-4",rules:[{required:"service_account"===G,message:"Please select a team for the service account"}],help:"service_account"===G?"required":"",children:(0,c.jsx)(q,{teams:l,onChange:e=>{ea((null==l?void 0:l.find(s=>s.team_id===e))||null)}})})]}),eM&&(0,c.jsx)("div",{className:"mb-8 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-blue-800 text-sm",children:"Please select a team to continue configuring your API key. If you do not see any teams, please contact your Proxy Admin to either provide you with access to models or to add you to a team."})}),!eM&&(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["you"===G||"another_user"===G?"Key Name":"Service Account ID"," ",(0,c.jsx)(V.Z,{title:"you"===G||"another_user"===G?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===G?"key name":"service account ID")}],help:"required",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:"management"===eN||"read_only"===eN?[]:[{required:!0,message:"Please select a model"}],help:"management"===eN||"read_only"===eN?"Models field is disabled for this key type":"required",className:"mt-4",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:"management"===eN||"read_only"===eN,onChange:e=>{e.includes("all-team-models")&&m.setFieldsValue({models:["all-team-models"]})},children:[(0,c.jsx)(eV,{value:"all-team-models",children:"All Team Models"},"all-team-models"),R.map(e=>(0,c.jsx)(eV,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Key Type"," ",(0,c.jsx)(V.Z,{title:"Select the type of key to determine what routes and operations this key can access",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"key_type",initialValue:"default",className:"mt-4",children:(0,c.jsxs)(I.default,{defaultValue:"default",placeholder:"Select key type",style:{width:"100%"},optionLabelProp:"label",onChange:e=>{eZ(e),("management"===e||"read_only"===e)&&m.setFieldsValue({models:[]})},children:[(0,c.jsx)(eV,{value:"default",label:"Default",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"Default"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call LLM API + Management routes"})]})}),(0,c.jsx)(eV,{value:"llm_api",label:"LLM API",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"LLM API"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call only LLM API routes (chat/completions, embeddings, etc.)"})]})}),(0,c.jsx)(eV,{value:"management",label:"Management",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"Management"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call only management routes (user/team/key management)"})]})})]})})]}),!eM&&(0,c.jsx)("div",{className:"mb-8",children:(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",onClick:()=>{ev||(eP(),ey(!0))},children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Max Budget (USD)"," ",(0,c.jsx)(V.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.max_budget&&s>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(eE(t.max_budget,4)))}}],children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Reset Budget"," ",(0,c.jsx)(V.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,c.jsx)(eT,{onChange:e=>m.setFieldValue("budget_duration",e)})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,c.jsx)(V.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.tpm_limit&&s>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,c.jsx)(V.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.rpm_limit&&s>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Expire Key"," ",(0,c.jsx)(V.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:o?"Select existing guardrails or enter new ones":"Premium feature - Upgrade to set guardrails by key",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!o,placeholder:o?"Select or enter guardrails":"Premium feature - Upgrade to set guardrails by key",options:W.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Prompts"," ",(0,c.jsx)(V.Z,{title:"Allow this key to use specific prompt templates",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/prompt_management",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"prompts",className:"mt-4",help:o?"Select existing prompts or enter new ones":"Premium feature - Upgrade to set prompts by key",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!o,placeholder:o?"Select or enter prompts":"Premium feature - Upgrade to set prompts by key",options:Q.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this key can access. If none selected, the key will have access to all available vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-4",help:"Select vector stores this key can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>m.setFieldValue("allowed_vector_store_ids",e),value:m.getFieldValue("allowed_vector_store_ids"),accessToken:r,placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers or access groups this key can access. ",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-4",help:"Select MCP servers or access groups this key can access. ",children:(0,c.jsx)(eO,{onChange:e=>m.setFieldValue("allowed_mcp_servers_and_groups",e),value:m.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:r,placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Tags"," ",(0,c.jsx)(V.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),o?(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:es,onChange:et,premiumUser:!0,disabledCallbacks:eb,onDisabledCallbacksChange:e_})})})]}):(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Key-level logging settings is an enterprise feature, get in touch -",(0,c.jsx)("a",{href:"https://www.litellm.ai/enterprise",target:"_blank",children:"https://www.litellm.ai/enterprise"})]}),placement:"top",children:(0,c.jsxs)("div",{style:{position:"relative"},children:[(0,c.jsx)("div",{style:{opacity:.5},children:(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:es,onChange:et,premiumUser:!1,disabledCallbacks:eb,onDisabledCallbacksChange:e_})})})]})}),(0,c.jsx)("div",{style:{position:"absolute",inset:0,cursor:"not-allowed"}})]})}),(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Model Aliases"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600 mb-4",children:"Create custom aliases for models that can be used in API calls. This allows you to create shortcuts for specific models."}),(0,c.jsx)(eB,{accessToken:r,initialModelAliases:ew,onAliasUpdate:eS,showExampleConfig:!1})]})})]}),(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("b",{children:"Advanced Settings"}),(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,c.jsx)("a",{href:j.proxyBaseUrl?"".concat(j.proxyBaseUrl,"/#/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,c.jsx)(B.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)(z.Z,{schemaComponent:"GenerateKeyRequest",form:m,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",disabled:eM,style:{opacity:eM?.5:1},children:"Create Key"})})]})}),ei&&(0,c.jsx)(L.Z,{title:"Create New User",visible:ei,onCancel:()=>en(!1),footer:null,width:800,children:(0,c.jsx)(ek,{userID:s,accessToken:r,teams:l,possibleUIRoles:em,onUserCreated:e=>{ed(e),m.setFieldsValue({user_id:e}),en(!1)},isEmbedded:!0})}),h&&(0,c.jsx)(L.Z,{visible:u,onOk:eA,onCancel:eL,footer:null,children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Save your Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,c.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,c.jsx)(v.Z,{numColSpan:1,children:null!=h?(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"API Key:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,c.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{eo.Z.success("API Key copied to clipboard")},children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,c.jsx)(k.Z,{children:"Key being created, this might take 30s"})})]})})]})},eY=t(7366),eW=t(20577),e$=e=>{let{selectedTeam:s,currentOrg:t,selectedKeyAlias:l,accessToken:a,createClicked:r}=e,[i,n]=(0,d.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,c]=(0,d.useState)(!0),[m,u]=(0,d.useState)(null),x=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}c(!0);let s="number"==typeof e.page?e.page:1,t="number"==typeof e.pageSize?e.pageSize:100,l=await (0,j.keyListCall)(a,null,null,null,null,null,s,t);console.log("data",l),n(l),u(null)}catch(e){u(e instanceof Error?e:Error("An error occurred"))}finally{c(!1)}};return(0,d.useEffect)(()=>{x(),console.log("selectedTeam",s,"currentOrg",t,"accessToken",a,"selectedKeyAlias",l)},[s,t,a,l,r]),{keys:i.keys,isLoading:o,error:m,pagination:{currentPage:i.current_page,totalPages:i.total_pages,totalCount:i.total_count},refresh:x,setKeys:e=>{n(s=>{let t="function"==typeof e?e(s.keys):e;return{...s,keys:t}})}}},eQ=t(27281),eX=t(41649),e0=t(12485),e1=t(18135),e2=t(35242),e4=t(29706),e5=t(77991),e6=t(10900),e3=t(23628),e8=e=>{let{value:s,onChange:t,disabledCallbacks:l=[],onDisabledCallbacksChange:a}=e;return(0,c.jsx)(ea,{value:s,onChange:t,disabledCallbacks:l,onDisabledCallbacksChange:a})};let e7=["logging"],e9=e=>e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(e=>{let[s]=e;return!e7.includes(s)})):{},se=e=>e&&"object"==typeof e&&Array.isArray(e.logging)?e.logging:[],ss=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return JSON.stringify(e9(e),null,s)};var st=e=>{let{onChange:s,value:t,className:l,accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,j.getGuardrailsList)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),i(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:t,loading:n,className:l,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};function sl(e){var s,t,l,a,r,i,n,o;let{keyData:m,onCancel:u,onSubmit:x,teams:h,accessToken:p,userID:g,userRole:f,premiumUser:v=!1}=e,[y]=A.Z.useForm(),[N,Z]=(0,d.useState)([]),[w,k]=(0,d.useState)([]),S=null==h?void 0:h.find(e=>e.team_id===m.team_id),[C,L]=(0,d.useState)([]),[T,M]=(0,d.useState)([]),[D,F]=(0,d.useState)(!1),[R,z]=(0,d.useState)(Array.isArray(null===(s=m.metadata)||void 0===s?void 0:s.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]);(0,d.useEffect)(()=>{let e=async()=>{if(g&&f&&p)try{if(null===m.team_id){let e=(await (0,j.modelAvailableCall)(p,g,f)).data.map(e=>e.id);L(e)}else if(null==S?void 0:S.team_id){let e=await eG(g,f,p,S.team_id);L(Array.from(new Set([...S.models,...e])))}}catch(e){console.error("Error fetching models:",e)}};(async()=>{if(p)try{let e=await (0,j.getPromptsList)(p);k(e.prompts.map(e=>e.prompt_id))}catch(e){console.error("Failed to fetch prompts:",e)}})(),e()},[g,f,p,S,m.team_id]),(0,d.useEffect)(()=>{y.setFieldValue("disabled_callbacks",R)},[y,R]);let q=e=>e&&({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||null,B={...m,token:m.token||m.token_id,budget_duration:q(m.budget_duration),metadata:ss(m.metadata),guardrails:(null===(t=m.metadata)||void 0===t?void 0:t.guardrails)||[],prompts:(null===(l=m.metadata)||void 0===l?void 0:l.prompts)||[],vector_stores:(null===(a=m.object_permission)||void 0===a?void 0:a.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(r=m.object_permission)||void 0===r?void 0:r.mcp_servers)||[],accessGroups:(null===(i=m.object_permission)||void 0===i?void 0:i.mcp_access_groups)||[]},logging_settings:se(m.metadata),disabled_callbacks:Array.isArray(null===(n=m.metadata)||void 0===n?void 0:n.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]};return(0,d.useEffect)(()=>{var e,s,t,l,a,r;y.setFieldsValue({...m,token:m.token||m.token_id,budget_duration:q(m.budget_duration),metadata:ss(m.metadata),guardrails:(null===(e=m.metadata)||void 0===e?void 0:e.guardrails)||[],prompts:(null===(s=m.metadata)||void 0===s?void 0:s.prompts)||[],vector_stores:(null===(t=m.object_permission)||void 0===t?void 0:t.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(l=m.object_permission)||void 0===l?void 0:l.mcp_servers)||[],accessGroups:(null===(a=m.object_permission)||void 0===a?void 0:a.mcp_access_groups)||[]},logging_settings:se(m.metadata),disabled_callbacks:Array.isArray(null===(r=m.metadata)||void 0===r?void 0:r.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]})},[m,y]),console.log("premiumUser:",v),(0,c.jsxs)(A.Z,{form:y,onFinish:x,initialValues:B,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[C.length>0&&(0,c.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),C.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,c.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,c.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,c.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,c.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:p&&(0,c.jsx)(st,{onChange:e=>{y.setFieldValue("guardrails",e)},accessToken:p})}),(0,c.jsx)(A.Z.Item,{label:"Prompts",name:"prompts",children:(0,c.jsx)(V.Z,{title:v?"":"Setting prompts by key is a premium feature",placement:"top",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!v,placeholder:v?Array.isArray(null===(o=m.metadata)||void 0===o?void 0:o.prompts)&&m.metadata.prompts.length>0?"Current: ".concat(m.metadata.prompts.join(", ")):"Select or enter prompts":"Premium feature - Upgrade to set prompts by key",options:w.map(e=>({value:e,label:e}))})})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>y.setFieldValue("vector_stores",e),value:y.getFieldValue("vector_stores"),accessToken:p||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers / Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>y.setFieldValue("mcp_servers_and_groups",e),value:y.getFieldValue("mcp_servers_and_groups"),accessToken:p||"",placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,c.jsx)(I.default,{placeholder:"Select team",style:{width:"100%"},children:null==h?void 0:h.map(e=>(0,c.jsx)(I.default.Option,{value:e.team_id,children:"".concat(e.team_alias," (").concat(e.team_id,")")},e.team_id))})}),(0,c.jsx)(A.Z.Item,{label:"Logging Settings",name:"logging_settings",children:(0,c.jsx)(e8,{value:y.getFieldValue("logging_settings"),onChange:e=>y.setFieldValue("logging_settings",e),disabledCallbacks:R,onDisabledCallbacksChange:e=>{z(X(e)),y.setFieldValue("disabled_callbacks",e)}})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:10})}),(0,c.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{name:"disabled_callbacks",hidden:!0,children:(0,c.jsx)(E.default,{})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{onClick:u,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]})}function sa(e){let{selectedToken:s,visible:t,onClose:l,accessToken:a,premiumUser:r,setAccessToken:i,onKeyUpdate:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,N]=(0,d.useState)(!1),[Z,w]=(0,d.useState)(!1),[I,T]=(0,d.useState)(null);(0,d.useEffect)(()=>{t&&s&&a&&(o.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""}),T(a),w(s.key_name===a))},[t,s,o,a]),(0,d.useEffect)(()=>{t||(u(null),N(!1),w(!1),T(null),o.resetFields())},[t,o]);let P=e=>{if(!e)return null;try{let s;let t=new Date;if(e.endsWith("s"))s=(0,eY.Z)(t,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eY.Z)(t,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eY.Z)(t,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}};(0,d.useEffect)(()=>{(null==x?void 0:x.duration)?g(P(x.duration)):g(null)},[null==x?void 0:x.duration]);let E=async()=>{if(s&&I){N(!0);try{let e=await o.validateFields(),t=await (0,j.regenerateKeyCall)(I,s.token||s.token_id,e);u(t.key),eo.Z.success("API Key regenerated successfully"),console.log("Full regenerate response:",t);let l={token:t.token||t.key_id||s.token,key_name:t.key,max_budget:e.max_budget,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,expires:e.duration?P(e.duration):s.expires,...t};console.log("Updated key data with new token:",l),Z&&(T(t.key),i&&i(t.key)),n&&n(l),N(!1)}catch(e){console.error("Error regenerating key:",e),eo.Z.fromBackend(e),N(!1)}}},M=()=>{u(null),N(!1),w(!1),T(null),o.resetFields(),l()};return(0,c.jsx)(L.Z,{title:"Regenerate API Key",open:t,onCancel:M,footer:m?[(0,c.jsx)(b.Z,{onClick:M,children:"Close"},"close")]:[(0,c.jsx)(b.Z,{onClick:M,className:"mr-2",children:"Cancel"},"cancel"),(0,c.jsx)(b.Z,{onClick:E,disabled:f,children:f?"Regenerating...":"Regenerate"},"regenerate")],children:m?(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Regenerated Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons,"," ",(0,c.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,c.jsxs)(v.Z,{numColSpan:1,children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"Key Alias:"}),(0,c.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,c.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,c.jsx)(k.Z,{className:"mt-3",children:"New API Key:"}),(0,c.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,c.jsx)("pre",{className:"break-words whitespace-normal",children:m})}),(0,c.jsx)(C.CopyToClipboard,{text:m,onCopy:()=>eo.Z.success("API Key copied to clipboard"),children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,c.jsxs)(A.Z,{form:o,layout:"vertical",onValuesChange:e=>{"duration"in e&&h(s=>({...s,duration:e.duration}))},children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,c.jsx)(_.Z,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),p&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",p]})]})})}var sr=t(79814),si=function(e){let{vectorStores:s,accessToken:t}=e,[l,a]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(t&&0!==s.length)try{let e=await (0,j.vectorStoreListCall)(t);e.data&&a(e.data.map(e=>({vector_store_id:e.vector_store_id,vector_store_name:e.vector_store_name})))}catch(e){console.error("Error fetching vector stores:",e)}})()},[t,s.length]);let r=e=>{let s=l.find(s=>s.vector_store_id===e);return s?"".concat(s.vector_store_name||s.vector_store_id," (").concat(s.vector_store_id,")"):e};return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sr.Z,{className:"h-4 w-4 text-blue-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Vector Stores"}),(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:s.length})]}),s.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map((e,s)=>(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-blue-50 border border-blue-200 text-blue-800 text-sm font-medium",children:r(e)},s))}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(sr.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No vector stores configured"})]})]})},sn=t(25327),so=function(e){let{mcpServers:s,mcpAccessGroups:l=[],accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(a&&s.length>0)try{let e=await (0,j.fetchMCPServers)(a);e&&Array.isArray(e)?i(e):e.data&&Array.isArray(e.data)&&i(e.data)}catch(e){console.error("Error fetching MCP servers:",e)}})()},[a,s.length]),(0,d.useEffect)(()=>{(async()=>{if(a&&l.length>0)try{let e=await Promise.resolve().then(t.bind(t,19250)).then(e=>e.fetchMCPAccessGroups(a));o(Array.isArray(e)?e:e.data||[])}catch(e){console.error("Error fetching MCP access groups:",e)}})()},[a,l.length]);let m=e=>{let s=r.find(s=>s.server_id===e);if(s){let t=e.length>7?"".concat(e.slice(0,3),"...").concat(e.slice(-4)):e;return"".concat(s.alias," (").concat(t,")")}return e},u=e=>e,x=[...s.map(e=>({type:"server",value:e})),...l.map(e=>({type:"accessGroup",value:e}))],h=x.length;return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sn.Z,{className:"h-4 w-4 text-gray-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"MCP Servers"}),(0,c.jsx)(eX.Z,{color:"gray",size:"xs",children:h})]}),h>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:x.map((e,s)=>"server"===e.type?(0,c.jsx)(V.Z,{title:"Full ID: ".concat(e.value),placement:"top",children:(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-blue-50 border border-blue-200 text-blue-800 text-sm font-medium cursor-help",children:m(e.value)})},s):(0,c.jsxs)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium",children:[(0,c.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full mr-2"}),u(e.value)," ",(0,c.jsx)("span",{className:"ml-1 text-xs text-green-500",children:"(Access Group)"})]},s))}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(sn.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No MCP servers or access groups configured"})]})]})},sc=function(e){let{objectPermission:s,variant:t="card",className:l="",accessToken:a}=e,r=(null==s?void 0:s.vector_stores)||[],i=(null==s?void 0:s.mcp_servers)||[],n=(null==s?void 0:s.mcp_access_groups)||[],o=(0,c.jsxs)("div",{className:"card"===t?"grid grid-cols-1 md:grid-cols-2 gap-6":"space-y-4",children:[(0,c.jsx)(si,{vectorStores:r,accessToken:a}),(0,c.jsx)(so,{mcpServers:i,mcpAccessGroups:n,accessToken:a})]});return"card"===t?(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6 ".concat(l),children:[(0,c.jsx)("div",{className:"flex items-center gap-2 mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Object Permissions"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500",children:"Access control for Vector Stores and MCP Servers"})]})}),o]}):(0,c.jsxs)("div",{className:"".concat(l),children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900 mb-3",children:"Object Permissions"}),o]})},sd=function(e){let{loggingConfigs:s=[],disabledCallbacks:t=[],variant:l="card",className:a=""}=e,r=e=>{var s;return(null===(s=Object.entries($).find(s=>{let[t,l]=s;return l===e}))||void 0===s?void 0:s[0])||e},i=e=>{switch(e){case"success":return"green";case"failure":return"red";case"success_and_failure":return"blue";default:return"gray"}},n=e=>{switch(e){case"success":return"Success Only";case"failure":return"Failure Only";case"success_and_failure":return"Success & Failure";default:return e}},o=(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(J.Z,{className:"h-4 w-4 text-blue-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Logging Integrations"}),(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:s.length})]}),s.length>0?(0,c.jsx)("div",{className:"space-y-3",children:s.map((e,s)=>{var t;let l=r(e.callback_name),a=null===(t=et[l])||void 0===t?void 0:t.logo;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg bg-blue-50 border border-blue-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[a?(0,c.jsx)("img",{src:a,alt:l,className:"w-5 h-5 object-contain"}):(0,c.jsx)(J.Z,{className:"h-5 w-5 text-gray-400"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-blue-800",children:l}),(0,c.jsxs)(k.Z,{className:"text-xs text-blue-600",children:[Object.keys(e.callback_vars).length," parameters configured"]})]})]}),(0,c.jsx)(eX.Z,{color:i(e.callback_type),size:"sm",children:n(e.callback_type)})]},s)})}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(J.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No logging integrations configured"})]})]}),(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(H.Z,{className:"h-4 w-4 text-red-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Disabled Callbacks"}),(0,c.jsx)(eX.Z,{color:"red",size:"xs",children:t.length})]}),t.length>0?(0,c.jsx)("div",{className:"space-y-3",children:t.map((e,s)=>{var t;let l=Q[e]||e,a=null===(t=et[l])||void 0===t?void 0:t.logo;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg bg-red-50 border border-red-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[a?(0,c.jsx)("img",{src:a,alt:l,className:"w-5 h-5 object-contain"}):(0,c.jsx)(H.Z,{className:"h-5 w-5 text-gray-400"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-red-800",children:l}),(0,c.jsx)(k.Z,{className:"text-xs text-red-600",children:"Disabled for this key"})]})]}),(0,c.jsx)(eX.Z,{color:"red",size:"sm",children:"Disabled"})]},s)})}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(H.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No callbacks disabled"})]})]})]});return"card"===l?(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6 ".concat(a),children:[(0,c.jsx)("div",{className:"flex items-center gap-2 mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Logging Settings"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500",children:"Active logging integrations and disabled callbacks for this key"})]})}),o]}):(0,c.jsxs)("div",{className:"".concat(a),children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900 mb-3",children:"Logging Settings"}),o]})},sm=t(30401),su=t(78867),sx=t(85968);function sh(e){var s,t,l,a,r;let{keyId:i,onClose:n,keyData:o,accessToken:m,userID:u,userRole:x,teams:h,onKeyDataUpdate:p,onDelete:g,premiumUser:f,setAccessToken:v,backButtonText:_="Back to Keys"}=e,[N,Z]=(0,d.useState)(!1),[w]=A.Z.useForm(),[C,I]=(0,d.useState)(!1),[L,T]=(0,d.useState)(""),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)({}),[F,R]=(0,d.useState)(o),[z,U]=(0,d.useState)(null),[q,B]=(0,d.useState)(!1);if((0,d.useEffect)(()=>{o&&R(o)},[o]),(0,d.useEffect)(()=>{if(q){let e=setTimeout(()=>{B(!1)},5e3);return()=>clearTimeout(e)}},[q]),!F)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:n,className:"mb-4",children:_}),(0,c.jsx)(k.Z,{children:"Key not found"})]});let K=async e=>{try{var s,t,l,a;if(!m)return;let r=e.token;if(e.key=r,void 0!==e.vector_stores&&(e.object_permission={...F.object_permission,vector_stores:e.vector_stores||[]},delete e.vector_stores),void 0!==e.mcp_servers_and_groups){let{servers:s,accessGroups:t}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};e.object_permission={...F.object_permission,mcp_servers:s||[],mcp_access_groups:t||[]},delete e.mcp_servers_and_groups}if(e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{},...e.logging_settings?{logging:e.logging_settings}:{},...(null===(t=e.disabled_callbacks)||void 0===t?void 0:t.length)>0?{litellm_disabled_callbacks:ee(e.disabled_callbacks)}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),eo.Z.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{},...e.logging_settings?{logging:e.logging_settings}:{},...(null===(a=e.disabled_callbacks)||void 0===a?void 0:a.length)>0?{litellm_disabled_callbacks:ee(e.disabled_callbacks)}:{}};delete e.logging_settings,e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let i=await (0,j.keyUpdateCall)(m,e);R(e=>e?{...e,...i}:void 0),p&&p(i),eo.Z.success("Key updated successfully"),Z(!1)}catch(e){eo.Z.fromBackend((0,sx.O)(e)),console.error("Error updating key:",e)}},H=async()=>{try{if(!m)return;await (0,j.keyDeleteCall)(m,F.token||F.token_id),eo.Z.success("Key deleted successfully"),g&&g(),n()}catch(e){console.error("Error deleting the key:",e),eo.Z.fromBackend(e)}T("")},J=async(e,s)=>{await eM(e)&&(D(e=>({...e,[s]:!0})),setTimeout(()=>{D(e=>({...e,[s]:!1}))},2e3))},Y=e=>{let s=new Date(e),t=s.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),l=s.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return"".concat(t," at ").concat(l)};return(0,c.jsxs)("div",{className:"w-full h-screen p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:n,className:"mb-4",children:_}),(0,c.jsx)(S.Z,{children:F.key_alias||"API Key"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer mb-2 space-y-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-xs text-gray-400 uppercase tracking-wide mt-2",children:"Key ID"}),(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono text-sm",children:F.token_id||F.token})]}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:O["key-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>J(F.token_id||F.token,"key-id"),className:"ml-2 transition-all duration-200".concat(O["key-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]}),(0,c.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-500",children:F.updated_at&&F.updated_at!==F.created_at?"Updated: ".concat(Y(F.updated_at)):"Created: ".concat(Y(F.created_at))}),q&&(0,c.jsx)(eX.Z,{color:"green",size:"xs",className:"animate-pulse",children:"Recently Regenerated"}),z&&(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:"Regenerated"})]})]}),x&&eI.LQ.includes(x)&&(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(V.Z,{title:f?"":"This is a LiteLLM Enterprise feature, and requires a valid key to use.",children:(0,c.jsx)("span",{className:"inline-block",children:(0,c.jsx)(b.Z,{icon:e3.Z,variant:"secondary",onClick:()=>M(!0),className:"flex items-center",disabled:!f,children:"Regenerate Key"})})}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>I(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,c.jsx)(sa,{selectedToken:F,visible:E,onClose:()=>M(!1),accessToken:m,premiumUser:f,setAccessToken:v,onKeyUpdate:e=>{R(s=>{if(s)return{...s,...e,created_at:new Date().toLocaleString()}}),U(new Date),B(!0),p&&p({...e,created_at:new Date().toLocaleString()})}}),C&&(()=>{let e=(null==F?void 0:F.key_alias)||(null==F?void 0:F.token_id)||"API Key",s=L===e;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Key"}),(0,c.jsx)("button",{onClick:()=>{I(!1),T("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.082 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"Warning: You are about to delete this API key."}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"This action is irreversible and will immediately revoke access for any applications using this key."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to delete this API key?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:e})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:L,onChange:e=>T(e.target.value),placeholder:"Enter key name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{I(!1),T("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:H,disabled:!s,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(s?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Delete Key"})]})]})})})(),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Spend"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(F.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null!==F.max_budget?"$".concat(eE(F.max_budget)):"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",null!==F.tpm_limit?F.tpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",null!==F.rpm_limit?F.rpm_limit:"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:F.models&&F.models.length>0?F.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s)):(0,c.jsx)(k.Z,{children:"No models specified"})})]}),(0,c.jsx)(G.Z,{children:(0,c.jsx)(sc,{objectPermission:F.object_permission,variant:"inline",accessToken:m})}),(0,c.jsx)(sd,{loggingConfigs:se(F.metadata),disabledCallbacks:Array.isArray(null===(s=F.metadata)||void 0===s?void 0:s.litellm_disabled_callbacks)?X(F.metadata.litellm_disabled_callbacks):[],variant:"card"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Key Settings"}),!N&&x&&eI.LQ.includes(x)&&(0,c.jsx)(b.Z,{variant:"light",onClick:()=>Z(!0),children:"Edit Settings"})]}),N?(0,c.jsx)(sl,{keyData:F,onCancel:()=>Z(!1),onSubmit:K,teams:h,accessToken:m,userID:u,userRole:x,premiumUser:f}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Key ID"}),(0,c.jsx)(k.Z,{className:"font-mono",children:F.token_id||F.token})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Key Alias"}),(0,c.jsx)(k.Z,{children:F.key_alias||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Secret Key"}),(0,c.jsx)(k.Z,{className:"font-mono",children:F.key_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)(k.Z,{children:F.team_id||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization"}),(0,c.jsx)(k.Z,{children:F.organization_id||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:Y(F.created_at)})]}),z&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Regenerated"}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(k.Z,{children:Y(z)}),(0,c.jsx)(eX.Z,{color:"green",size:"xs",children:"Recent"})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Expires"}),(0,c.jsx)(k.Z,{children:F.expires?Y(F.expires):"Never"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Spend"}),(0,c.jsxs)(k.Z,{children:["$",eE(F.spend,4)," USD"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget"}),(0,c.jsx)(k.Z,{children:null!==F.max_budget?"$".concat(eE(F.max_budget,2)):"Unlimited"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompts"}),(0,c.jsx)(k.Z,{children:Array.isArray(null===(t=F.metadata)||void 0===t?void 0:t.prompts)&&F.metadata.prompts.length>0?F.metadata.prompts.map((e,s)=>(0,c.jsx)("span",{className:"px-2 mr-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"No prompts specified"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:F.models&&F.models.length>0?F.models.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,c.jsx)(k.Z,{children:"No models specified"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)(k.Z,{children:["TPM: ",null!==F.tpm_limit?F.tpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",null!==F.rpm_limit?F.rpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Max Parallel Requests:"," ",null!==F.max_parallel_requests?F.max_parallel_requests:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Model TPM Limits:"," ",(null===(l=F.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(F.metadata.model_tpm_limit):"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Model RPM Limits:"," ",(null===(a=F.metadata)||void 0===a?void 0:a.model_rpm_limit)?JSON.stringify(F.metadata.model_rpm_limit):"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:ss(F.metadata)})]}),(0,c.jsx)(sc,{objectPermission:F.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:m}),(0,c.jsx)(sd,{loggingConfigs:se(F.metadata),disabledCallbacks:Array.isArray(null===(r=F.metadata)||void 0===r?void 0:r.litellm_disabled_callbacks)?X(F.metadata.litellm_disabled_callbacks):[],variant:"inline",className:"pt-4 border-t border-gray-200"})]})]})})]})]})]})}var sp=t(2356),sg=e=>{let{options:s,onApplyFilters:t,onResetFilters:l,initialValues:a={},buttonLabel:r="Filters"}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(a),[u,x]=(0,d.useState)({}),[h,p]=(0,d.useState)({}),[g,j]=(0,d.useState)({}),[f,v]=(0,d.useState)({}),y=(0,d.useCallback)(eC()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let t=await s.searchFn(e);x(e=>({...e,[s.name]:t}))}catch(e){console.error("Error searching:",e),x(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),b=(0,d.useCallback)(async e=>{if(e.isSearchable&&e.searchFn&&!f[e.name]){p(s=>({...s,[e.name]:!0})),v(s=>({...s,[e.name]:!0}));try{let s=await e.searchFn("");x(t=>({...t,[e.name]:s}))}catch(s){console.error("Error loading initial options:",s),x(s=>({...s,[e.name]:[]}))}finally{p(s=>({...s,[e.name]:!1}))}}},[f]);(0,d.useEffect)(()=>{i&&s.forEach(e=>{e.isSearchable&&!f[e.name]&&b(e)})},[i,s,b,f]);let _=(e,s)=>{let l={...o,[e]:s};m(l),t(l)},N=(e,s)=>{e&&s.isSearchable&&!f[s.name]&&b(s)};return(0,c.jsxs)("div",{className:"w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(sp.Z,{className:"h-4 w-4"}),onClick:()=>n(!i),className:"flex items-center gap-2",children:r}),(0,c.jsx)(P.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),m(e),l()},children:"Reset Filters"})]}),i&&(0,c.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","End User","Key Hash","Model"].map(e=>{let t=s.find(s=>s.label===e||s.name===e);return t?(0,c.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,c.jsx)("label",{className:"text-sm text-gray-600",children:t.label||t.name}),t.isSearchable?(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(t.label||t.name,"..."),value:o[t.name]||void 0,onChange:e=>_(t.name,e),onDropdownVisibleChange:e=>N(e,t),onSearch:e=>{j(s=>({...s,[t.name]:e})),t.searchFn&&y(e,t)},filterOption:!1,loading:h[t.name],options:u[t.name]||[],allowClear:!0,notFoundContent:h[t.name]?"Loading...":"No results found"}):t.options?(0,c.jsx)(I.default,{className:"w-full",placeholder:"Select ".concat(t.label||t.name,"..."),value:o[t.name]||void 0,onChange:e=>_(t.name,e),allowClear:!0,children:t.options.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))}):(0,c.jsx)(E.default,{className:"w-full",placeholder:"Enter ".concat(t.label||t.name,"..."),value:o[t.name]||"",onChange:e=>_(t.name,e.target.value),allowClear:!0})]},t.name):null})})]})},sj=t(16593);let sf=async e=>{if(!e)return[];try{let s=[],t=1,l=!0;for(;l;){let a=await (0,j.keyListCall)(e,null,"",null,null,null,t,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],t{if(!e)return[];try{let t=[],l=1,a=!0;for(;a;){let r=await (0,j.teamListCall)(e,s||null,null);t=[...t,...r],l{if(!e)return[];try{let s=[],t=1,l=!0;for(;l;){let a=await (0,j.organizationListCall)(e);s=[...s,...a],t{let[e,s]=(0,d.useState)("http://localhost:4000");return(0,d.useEffect)(()=>{{let{protocol:e,host:t}=window.location;s("".concat(e,"//").concat(t))}},[]),e};var s_=t(71594),sN=t(24525),sZ=t(47323),sw=t(21626),sk=t(97214),sS=t(28241),sC=t(58834),sI=t(69552),sA=t(71876),sL=t(86462),sT=t(47686),sP=t(44633),sE=t(49084);function sM(e){let{keys:s,setKeys:t,isLoading:l=!1,pagination:a,onPageChange:r,pageSize:i=50,teams:n,selectedTeam:o,setSelectedTeam:m,selectedKeyAlias:u,setSelectedKeyAlias:x,accessToken:h,userID:p,userRole:g,organizations:f,setCurrentOrg:v,refresh:y,onSortChange:_,currentSort:N,premiumUser:Z,setAccessToken:w}=e,[S,C]=(0,d.useState)(null),[I,A]=(0,d.useState)([]),[L,T]=d.useState(()=>N?[{id:N.sortBy,desc:"desc"===N.sortOrder}]:[{id:"created_at",desc:!0}]),[P,E]=(0,d.useState)({}),{filters:M,filteredKeys:O,allKeyAliases:D,allTeams:R,allOrganizations:z,handleFilterChange:U,handleFilterReset:q}=function(e){let{keys:s,teams:t,organizations:l,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[i,n]=(0,d.useState)(r),[o,c]=(0,d.useState)(t||[]),[m,u]=(0,d.useState)(l||[]),[x,h]=(0,d.useState)(s),p=(0,d.useRef)(0),g=(0,d.useCallback)(eC()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let t=await (0,j.keyListCall)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&t&&(h(t.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(t)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,d.useEffect)(()=>{if(!s){h([]);return}let e=[...s];i["Team ID"]&&(e=e.filter(e=>e.team_id===i["Team ID"])),i["Organization ID"]&&(e=e.filter(e=>e.organization_id===i["Organization ID"])),h(e)},[s,i]),(0,d.useEffect)(()=>{let e=async()=>{let e=await sv(a);e.length>0&&c(e);let s=await sy(a);s.length>0&&u(s)};a&&e()},[a]);let f=(0,sj.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await sf(a)},enabled:!!a}).data||[];return(0,d.useEffect)(()=>{t&&t.length>0&&c(e=>e.length{l&&l.length>0&&u(e=>e.length{n({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...i,...e})},handleFilterReset:()=>{n(r),g(r)}}}({keys:s,teams:n,organizations:f,accessToken:h});(0,d.useEffect)(()=>{if(h){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{A((await (0,j.userListCall)(h,e,1,100)).users)})()}},[h,s]),(0,d.useEffect)(()=>{if(y){let e=()=>{y()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[y]);let B=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,c.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.getValue(),children:(0,c.jsx)(b.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:()=>C(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,c.jsx)(V.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,c.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:t}=e,l=t(),a=null==n?void 0:n.find(e=>e.team_id===l);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,c.jsx)(V.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),t=I.find(e=>e.user_id===s);return(null==t?void 0:t.user_email)?(0,c.jsx)(V.Z,{title:null==t?void 0:t.user_email,children:(0,c.jsxs)("span",{children:[null==t?void 0:t.user_email.slice(0,20),"..."]})}):"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s&&s.length>15?(0,c.jsx)(V.Z,{title:s,children:(0,c.jsxs)("span",{children:[s.slice(0,7),"..."]})}):s||"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>{let s=e.getValue();return s&&s.length>15?(0,c.jsx)(V.Z,{title:s,children:(0,c.jsxs)("span",{children:[s.slice(0,7),"..."]})}):s}},{id:"updated_at",accessorKey:"updated_at",header:"Updated At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>eE(e.getValue(),4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>{let s=e.getValue();return null===s?"Unlimited":"$".concat(eE(s))}},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,c.jsx)("div",{className:"flex flex-col py-2",children:Array.isArray(s)?(0,c.jsx)("div",{className:"flex flex-col",children:0===s.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[s.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:P[e.row.id]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{E(s=>({...s,[e.row.id]:!s[e.row.id]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[s.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),s.length>3&&!P[e.row.id]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",s.length-3," ",s.length-3==1?"more model":"more models"]})}),P[e.row.id]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:s.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:["TPM: ",null!==t.tpm_limit?t.tpm_limit:"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",null!==t.rpm_limit?t.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let K=(0,s_.b7)({data:O,columns:B.filter(e=>"expander"!==e.id),state:{sorting:L},onSortingChange:e=>{let s="function"==typeof e?e(L):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),T(s),s&&s.length>0){let e=s[0],t=e.id,l=e.desc?"desc":"asc";console.log("sortBy: ".concat(t,", sortOrder: ").concat(l)),U({...M,"Sort By":t,"Sort Order":l}),null==_||_(t,l)}},getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0,manualSorting:!1});return d.useEffect(()=>{N&&T([{id:N.sortBy,desc:"desc"===N.sortOrder}])},[N]),(0,c.jsx)("div",{className:"w-full h-full overflow-hidden",children:S?(0,c.jsx)(sh,{keyId:S,onClose:()=>C(null),keyData:O.find(e=>e.token===S),onKeyDataUpdate:e=>{t(s=>s.map(s=>s.token===e.token?eP(s,e):s)),y&&y()},onDelete:()=>{t(e=>e.filter(e=>e.token!==S)),y&&y()},accessToken:h,userID:p,userRole:g,teams:R,premiumUser:Z,setAccessToken:w}):(0,c.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,c.jsx)("div",{className:"w-full mb-6",children:(0,c.jsx)(sg,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>R&&0!==R.length?R.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>z&&0!==z.length?z.filter(s=>{var t,l;return null!==(l=null===(t=s.organization_id)||void 0===t?void 0:t.toLowerCase().includes(e.toLowerCase()))&&void 0!==l&&l}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>D.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:U,initialValues:M,onResetFilters:q})}),(0,c.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,c.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing"," ",l?"...":"".concat((a.currentPage-1)*i+1," - ").concat(Math.min(a.currentPage*i,a.totalCount))," ","of ",l?"...":a.totalCount," results"]}),(0,c.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",l?"...":a.currentPage," of ",l?"...":a.totalPages]}),(0,c.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:l||1===a.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,c.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:l||a.currentPage===a.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,c.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:K.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:l?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:B.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):O.length>0?K.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("models"===e.column.id&&e.getValue().length>3?"px-0":""),children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:B.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}var sO=e=>{let{userID:s,userRole:t,accessToken:l,selectedTeam:a,setSelectedTeam:r,data:i,setData:n,teams:o,premiumUser:m,currentOrg:u,organizations:x,setCurrentOrg:h,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:f,setAccessToken:N}=e,[Z,w]=(0,d.useState)(!1),[I,T]=(0,d.useState)(!1),[P,E]=(0,d.useState)(null),[M,O]=(0,d.useState)(""),[F,R]=(0,d.useState)(null),[z,U]=(0,d.useState)(null),[q,B]=(0,d.useState)((null==a?void 0:a.team_id)||"");(0,d.useEffect)(()=>{B((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:K,error:G,pagination:H,refresh:J,setKeys:Y}=e$({selectedTeam:a||void 0,currentOrg:u,selectedKeyAlias:p,accessToken:l||"",createClicked:f}),[W,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(!1),[ee,es]=(0,d.useState)(null),[et,el]=(0,d.useState)([]),ea=new Set,[er,ei]=(0,d.useState)(!1),[en,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(null),[eu,ex]=(0,d.useState)(null),[eh]=A.Z.useForm(),[ep,eg]=(0,d.useState)(null),[ej,ef]=(0,d.useState)(ea),[ev,ey]=(0,d.useState)([]);(0,d.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",ee),(null==eu?void 0:eu.duration)?eg((e=>{if(!e)return null;try{let s;let t=new Date;if(e.endsWith("s"))s=(0,eY.Z)(t,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eY.Z)(t,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eY.Z)(t,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eu.duration)):eg(null),console.log("calculateNewExpiryTime:",ep)},[ee,null==eu?void 0:eu.duration]),(0,d.useEffect)(()=>{(async()=>{try{if(null===s||null===t||null===l)return;let e=await D(s,t,l);e&&el(e)}catch(e){eo.Z.error({description:"Error fetching user models"})}})()},[l,s,t]),(0,d.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,t)=>{let l=s.team_id;e.add(l)}),ef(e)}},[o]);let eb=async()=>{if(null!=P&&null!=V){try{if(!l)return;await (0,j.keyDeleteCall)(l,P);let e=V.filter(e=>e.token!==P);Y(e)}catch(e){eo.Z.error({description:"Error deleting the key"})}T(!1),E(null),O("")}},e_=()=>{T(!1),E(null),O("")},eN=(e,s)=>{ex(t=>({...t,[e]:s}))},eZ=async()=>{if(!m){eo.Z.warning({description:"Regenerate API Key is an Enterprise feature. Please upgrade to use this feature."});return}if(null!=ee)try{let e=await eh.validateFields();if(!l)return;let s=await (0,j.regenerateKeyCall)(l,ee.token||ee.token_id,e);if(em(s.key),i){let t=i.map(t=>t.token===(null==ee?void 0:ee.token)?{...t,key_name:s.key_name,...e}:t);n(t)}ec(!1),eh.resetFields(),eo.Z.success({description:"API Key regenerated successfully"})}catch(e){console.error("Error regenerating key:",e),eo.Z.error({description:"Failed to regenerate API Key"})}};return(0,c.jsxs)("div",{children:[(0,c.jsx)(sM,{keys:V,setKeys:Y,isLoading:K,pagination:H,onPageChange:e=>{J({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:l,userID:s,userRole:t,organizations:x,setCurrentOrg:h,refresh:J,selectedKeyAlias:p,setSelectedKeyAlias:g,premiumUser:m,setAccessToken:N}),I&&(()=>{let e=null==V?void 0:V.find(e=>e.token===P),s=(null==e?void 0:e.key_alias)||(null==e?void 0:e.token_id)||P,t=M===s;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Key"}),(0,c.jsx)("button",{onClick:()=>{e_(),O("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.082 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"Warning: You are about to delete this API key."}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"This action is irreversible and will immediately revoke access for any applications using this key."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to delete this API key?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:s})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:M,onChange:e=>O(e.target.value),placeholder:"Enter key name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{e_(),O("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:eb,disabled:!t,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(t?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Delete Key"})]})]})})})(),(0,c.jsx)(L.Z,{title:"Regenerate API Key",visible:en,onCancel:()=>{ec(!1),eh.resetFields()},footer:[(0,c.jsx)(b.Z,{onClick:()=>{ec(!1),eh.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,c.jsx)(b.Z,{onClick:eZ,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,c.jsxs)(A.Z,{form:eh,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&eN("duration",e.duration)},children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,c.jsx)(_.Z,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==ee?void 0:ee.expires)!=null?new Date(ee.expires).toLocaleString():"Never"]}),ep&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",ep]})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,c.jsx)(b.Z,{variant:"primary",className:"mb-2",children:(0,c.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ed&&(0,c.jsx)(L.Z,{visible:!!ed,onCancel:()=>em(null),footer:[(0,c.jsx)(b.Z,{onClick:()=>em(null),children:"Close"},"close")],children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Regenerated Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons,"," ",(0,c.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,c.jsxs)(v.Z,{numColSpan:1,children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"Key Alias:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==ee?void 0:ee.key_alias)||"No alias set"})}),(0,c.jsx)(k.Z,{className:"mt-3",children:"New API Key:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ed})}),(0,c.jsx)(C.CopyToClipboard,{text:ed,onCopy:()=>eo.Z.success({description:"API Key copied to clipboard"}),children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sD=t(12011),sF=t(3914),sR=e=>{let{userID:s,userRole:t,teams:l,keys:a,setUserRole:r,userEmail:i,setUserEmail:n,setTeams:o,setKeys:x,premiumUser:h,organizations:p,addKey:g,createClicked:b}=e,[_,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(null),k=(0,m.useSearchParams)(),S=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),C=k.get("invitation_id"),[I,A]=(0,d.useState)(null),[L,T]=(0,d.useState)(null),[P,E]=(0,d.useState)([]),[M,O]=(0,d.useState)(null),[D,F]=(0,d.useState)(null),[R,z]=(0,d.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,d.useEffect)(()=>{if(S){let e=(0,u.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";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:",s),r(s)}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&I&&t&&!a&&!_){let e=sessionStorage.getItem("userModels"+s);e?E(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.getProxyUISettings)(I);O(e);let l=await (0,j.userInfoCall)(I,s,t,!1,null,null);N(l.user_info),console.log("userSpendData: ".concat(JSON.stringify(_))),(null==l?void 0:l.teams[0].keys)?x(l.keys.concat(l.teams.filter(e=>"Admin"===t||e.user_id===s).flatMap(e=>e.keys))):x(l.keys),sessionStorage.setItem("userData"+s,JSON.stringify(l.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(l.user_info));let a=(await (0,j.modelAvailableCall)(I,s,t)).data.map(e=>e.id);console.log("available_model_names:",a),E(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&U()}})(),f(I,s,t,Z,o))}},[s,S,I,a,t]),(0,d.useEffect)(()=>{I&&(async()=>{try{let e=await (0,j.keyInfoCall)(I,[I]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&U()}})()},[I]),(0,d.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(I,", userID: ").concat(s,", userRole: ").concat(t)),I&&(console.log("fetching teams"),f(I,s,t,Z,o))},[Z]),(0,d.useEffect)(()=>{if(null!==a&&null!=D&&null!==D.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))D.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===D.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),T(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;T(e)}},[D]),null!=C)return(0,c.jsx)(sD.default,{});function U(){(0,sF.b)();let e=(0,j.getProxyBaseUrl)();console.log("proxyBaseUrl:",e);let s=e?"".concat(e,"/sso/key/generate"):"/sso/key/generate";return console.log("Full URL:",s),window.location.href=s,null}if(null==S)return console.log("All cookies before redirect:",document.cookie),U(),null;try{let e=(0,u.o)(S);console.log("Decoded token:",e);let s=e.exp,t=Math.floor(Date.now()/1e3);if(s&&t>=s)return console.log("Token expired, redirecting to login"),U(),null}catch(e){return console.error("Error decoding token:",e),(0,sF.b)(),U(),null}if(null==I)return null;if(null==s)return(0,c.jsx)("h1",{children:"User ID is not set"});if(null==t&&r("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",D),console.log("All cookies after redirect:",document.cookie),(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,c.jsx)(eJ,{userID:s,team:D,teams:l,userRole:t,accessToken:I,data:a,addKey:g,premiumUser:h},D?D.team_id:null),(0,c.jsx)(sO,{userID:s,userRole:t,accessToken:I,selectedTeam:D||null,setSelectedTeam:F,selectedKeyAlias:R,setSelectedKeyAlias:z,data:a,setData:x,premiumUser:h,teams:l,currentOrg:Z,setCurrentOrg:w,organizations:p,createClicked:b,setAccessToken:A})]})})})},sz=t(97765),sU=t(42673);let sq=async(e,s,t)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let t=e.custom_llm_provider,l=sU.fK[t]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let t=[];for(let l of s){let s={},a={},r=l.public_name;for(let[t,r]of(s.model=l.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),s.model=l.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==t&&"pricing_model"!==t&&"cache_control"!==t){if("model_name"==t)s.model=r;else if("custom_llm_provider"==t){console.log("custom_llm_provider:",r);let e=sU.fK[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==t)continue;else if("base_model"===t)a[t]=r;else if("team_id"===t)a.team_id=r;else if("model_access_group"===t)a.access_groups=r;else if("mode"==t)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===t)s.model=r;else if("litellm_extra_params"==t){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw eo.Z.fromBackend("Failed to parse LiteLLM Extra Params: "+e),Error("Failed to parse litellm_extra_params: "+e)}for(let[t,l]of Object.entries(e))s[t]=l}}else if("model_info_params"==t){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw eo.Z.fromBackend("Failed to parse LiteLLM Extra Params: "+e),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,t]of Object.entries(e))a[s]=t}}else if("input_cost_per_token"===t||"output_cost_per_token"===t||"input_cost_per_second"===t){r&&(s[t]=Number(r));continue}else s[t]=r}t.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return t}catch(e){eo.Z.fromBackend("Failed to create model: "+e)}},sB=async(e,s,t,l)=>{try{let a=await sq(e,s,t);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:t,modelInfoObj:l,modelName:a}=e,r={model_name:a,litellm_params:t,model_info:l},i=await (0,j.modelCreateCall)(s,r);console.log("response for model create call: ".concat(i.data))}l&&l(),t.resetFields()}catch(e){eo.Z.fromBackend("Failed to add model: "+e)}};var sV=t(53410),sK=t(47451),sG=t(69410);let{Link:sH}=en.default,sJ={[sU.Cl.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[sU.Cl.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[sU.Cl.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[sU.Cl.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[sU.Cl.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Dashscope]:[{key:"api_key",label:"Dashscope API Key",type:"password",required:!0},{key:"api_base",label:"API Base",placeholder:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",defaultValue:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",required:!0,tooltip:"The base URL for your Dashscope server. Defaults to https://dashscope-intl.aliyuncs.com/compatible-mode/v1 if not specified."}],[sU.Cl.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[sU.Cl.SageMaker]:[{key:"aws_access_key_id",label:"AWS Access Key ID",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[sU.Cl.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[sU.Cl.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[sU.Cl.Deepgram]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.ElevenLabs]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[sU.Cl.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.AIML]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.GradientAI]:[{key:"api_base",label:"GradientAI Endpoint",placeholder:"https://...",required:!1},{key:"api_key",label:"GradientAI API Key",type:"password",required:!0}],[sU.Cl.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}],[sU.Cl.Hosted_Vllm]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Voyage]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.JinaAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.VolcEngine]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.DeepInfra]:[{key:"api_key",label:"API Key",type:"password",required:!0}]};var sY=e=>{let{selectedProvider:s,uploadProps:t}=e,l=sU.Cl[s],a=A.Z.useFormInstance(),r=d.useMemo(()=>sJ[l]||[],[l]),i={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,c.jsx)(c.Fragment,{children:r.map(e=>{var s;return(0,c.jsxs)(d.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,c.jsx)(I.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,c.jsx)(ed.default,{...i,onChange:s=>{(null==t?void 0:t.onChange)&&t.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(ej.Z,{}),children:"Click to Upload"})}):(0,c.jsx)(_.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,c.jsx)(sK.Z,{children:(0,c.jsx)(sG.Z,{children:(0,c.jsx)(k.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,c.jsx)(sH,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})},sW=t(49169);let{Title:s$,Link:sQ}=en.default;var sX=e=>{let{isVisible:s,onCancel:t,onAddCredential:l,onUpdateCredential:a,uploadProps:r,addOrEdit:i,existingCredential:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(sU.Cl.OpenAI),[x,h]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{n&&(o.setFieldsValue({credential_name:n.credential_name,custom_llm_provider:n.credential_info.custom_llm_provider,api_base:n.credential_values.api_base,api_version:n.credential_values.api_version,base_model:n.credential_values.base_model,api_key:n.credential_values.api_key}),u(n.credential_info.custom_llm_provider))},[n]),(0,c.jsx)(L.Z,{title:"add"===i?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{t(),o.resetFields()},footer:null,width:600,children:(0,c.jsxs)(A.Z,{form:o,onFinish:e=>{let s=Object.entries(e).reduce((e,s)=>{let[t,l]=s;return""!==l&&null!=l&&(e[t]=l),e},{});"add"===i?l(s):a(s),o.resetFields()},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==n?void 0:n.credential_name,children:(0,c.jsx)(sW.o,{placeholder:"Enter a friendly name for these credentials",disabled:null!=n&&!!n.credential_name})}),(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,c.jsx)(I.default,{showSearch:!0,onChange:e=>{u(e),o.setFieldValue("custom_llm_provider",e)},children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(sY,{selectedProvider:m,uploadProps:r}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(sQ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:()=>{t(),o.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"add"===i?"Add Credential":"Update Credential"})]})]})]})})},s0=e=>{let{isVisible:s,onCancel:t,onConfirm:l,credentialName:a}=e,[r,i]=(0,d.useState)(""),n=r===a,o=()=>{i(""),t()};return(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(e_.Z,{className:"h-6 w-6 text-red-600 mr-2"}),"Delete Credential"]}),open:s,footer:null,onCancel:o,closable:!0,destroyOnClose:!0,maskClosable:!1,children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)(e_.Z,{className:"h-5 w-5"})}),(0,c.jsx)("div",{children:(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"This action cannot be undone and may break existing integrations."})})]}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsxs)("span",{className:"underline italic",children:["'",a,"'"]})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:r,onChange:e=>i(e.target.value),placeholder:"Enter credential name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(b.Z,{onClick:o,variant:"secondary",className:"mr-2",children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>{n&&(i(""),l())},color:"red",className:"focus:ring-red-500",disabled:!n,children:"Delete Credential"})]})]})})},s1=e=>{let{accessToken:s,uploadProps:t,credentialList:l,fetchCredentials:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p]=A.Z.useForm(),g=["credential_name","custom_llm_provider"],f=async e=>{if(!s)return;let t=Object.entries(e).filter(e=>{let[s]=e;return!g.includes(s)}).reduce((e,s)=>{let[t,l]=s;return{...e,[t]:l}},{}),l={credential_name:e.credential_name,credential_values:t,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,j.credentialUpdateCall)(s,e.credential_name,l),eo.Z.success("Credential updated successfully"),o(!1),a(s)},v=async e=>{if(!s)return;let t=Object.entries(e).filter(e=>{let[s]=e;return!g.includes(s)}).reduce((e,s)=>{let[t,l]=s;return{...e,[t]:l}},{}),l={credential_name:e.credential_name,credential_values:t,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,j.credentialCreateCall)(s,l),eo.Z.success("Credential added successfully"),i(!1),a(s)};(0,d.useEffect)(()=>{s&&a(s)},[s]);let y=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},t=s[e.toLowerCase()]||s.default;return(0,c.jsx)(eX.Z,{color:t,size:"xs",children:e})},_=async e=>{s&&(await (0,j.credentialDeleteCall)(s,e),eo.Z.success("Credential deleted successfully"),h(null),a(s))},N=e=>{h(e)};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(k.Z,{children:"Configured credentials for different AI providers. Add and manage your API credentials."})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Credential Name"}),(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Description"})]})}),(0,c.jsx)(sk.Z,{children:l&&0!==l.length?l.map((e,s)=>{var t,l;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.credential_name}),(0,c.jsx)(sS.Z,{children:y((null===(t=e.credential_info)||void 0===t?void 0:t.custom_llm_provider)||"-")}),(0,c.jsx)(sS.Z,{children:(null===(l=e.credential_info)||void 0===l?void 0:l.description)||"-"}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(b.Z,{icon:sV.Z,variant:"light",size:"sm",onClick:()=>{u(e),o(!0)}}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"light",size:"sm",onClick:()=>N(e.credential_name)})]})]},s)}):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,c.jsx)(b.Z,{onClick:()=>i(!0),className:"mt-4",children:"Add Credential"}),r&&(0,c.jsx)(sX,{onAddCredential:v,isVisible:r,onCancel:()=>i(!1),uploadProps:t,addOrEdit:"add",onUpdateCredential:f,existingCredential:null}),n&&(0,c.jsx)(sX,{onAddCredential:v,isVisible:n,existingCredential:m,onUpdateCredential:f,uploadProps:t,onCancel:()=>o(!1),addOrEdit:"edit"}),x&&(0,c.jsx)(s0,{isVisible:!0,onCancel:()=>{h(null)},onConfirm:()=>_(x),credentialName:x})]})};let s2=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var s4=t(21487),s5=e=>{let{value:s,onValueChange:t,label:l="Select Time Range",className:a="",showTimeRange:r=!0}=e,[i,n]=(0,d.useState)(!1),o=(0,d.useRef)(null),m=(0,d.useCallback)(e=>{n(!0),setTimeout(()=>n(!1),1500),t(e),requestIdleCallback(()=>{if(e.from){let s;let l={...e},a=new Date(e.from);s=new Date(e.to?e.to:e.from),a.toDateString(),s.toDateString(),a.setHours(0,0,0,0),s.setHours(23,59,59,999),l.from=a,l.to=s,t(l)}},{timeout:100})},[t]),u=(0,d.useCallback)((e,s)=>{if(!e||!s)return"";let t=e=>e.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0,timeZoneName:"short"});if(e.toDateString()!==s.toDateString())return"".concat(t(e)," - ").concat(t(s));{let t=e.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),l=e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0}),a=s.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZoneName:"short"});return"".concat(t,": ").concat(l," - ").concat(a)}},[]);return(0,c.jsxs)("div",{className:a,children:[l&&(0,c.jsx)(k.Z,{className:"mb-2",children:l}),(0,c.jsxs)("div",{className:"relative w-fit",children:[(0,c.jsx)("div",{ref:o,children:(0,c.jsx)(s4.Z,{enableSelect:!0,value:s,onValueChange:m,placeholder:"Select date range",enableClear:!1,style:{zIndex:100}})}),i&&(0,c.jsx)("div",{className:"absolute top-1/2 animate-pulse",style:{left:"calc(100% + 8px)",transform:"translateY(-50%)",zIndex:110},children:(0,c.jsxs)("div",{className:"flex items-center gap-1 text-green-600 text-sm font-medium bg-white px-2 py-1 rounded-full border border-green-200 shadow-sm whitespace-nowrap",children:[(0,c.jsx)("div",{className:"w-3 h-3 bg-green-500 text-white rounded-full flex items-center justify-center text-xs",children:"✓"}),(0,c.jsx)("span",{className:"text-xs",children:"Selected"})]})})]}),r&&s.from&&s.to&&(0,c.jsx)(k.Z,{className:"mt-2 text-xs text-gray-500",children:u(s.from,s.to)})]})},s6=t(75105),s3=t(40278),s8=t(79326),s7=t(59664),s9=e=>{let{modelMetrics:s,modelMetricsCategories:t,customTooltip:l,premiumUser:a}=e;return(0,c.jsx)(s7.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:t,colors:["indigo","rose"],connectNulls:!0,customTooltip:l})},te=e=>{let{teamData:s,canEditTeam:t,handleMemberDelete:l,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:i}=e,n=e=>{if(null==e)return"0";if("number"==typeof e){let s=Number(e);return s===Math.floor(s)?s.toString():eE(s,8).replace(/\.?0+$/,"")}return"0"},o=e=>{if(!e)return 0;let t=s.team_memberships.find(s=>s.user_id===e);return(null==t?void 0:t.spend)||0},d=e=>{var t;if(!e)return null;let l=s.team_memberships.find(s=>s.user_id===e);console.log("membership=".concat(l));let a=null==l?void 0:null===(t=l.litellm_budget_table)||void 0===t?void 0:t.max_budget;return null==a?null:n(a)},m=e=>{var t,l;if(!e)return"No Limits";let a=s.team_memberships.find(s=>s.user_id===e),r=null==a?void 0:null===(t=a.litellm_budget_table)||void 0===t?void 0:t.rpm_limit,i=null==a?void 0:null===(l=a.litellm_budget_table)||void 0===l?void 0:l.tpm_limit,o=[r?"".concat(n(r)," RPM"):null,i?"".concat(n(i)," TPM"):null].filter(Boolean);return o.length>0?o.join(" / "):"No Limits"};return(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-auto max-h-[50vh]",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"min-w-full",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"User Email"}),(0,c.jsx)(sI.Z,{children:"Role"}),(0,c.jsxs)(sI.Z,{children:["Team Member Spend (USD)"," ",(0,c.jsx)(V.Z,{title:"This is the amount spent by a user in the team.",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(sI.Z,{children:"Team Member Budget (USD)"}),(0,c.jsxs)(sI.Z,{children:["Team Member Rate Limits"," ",(0,c.jsx)(V.Z,{title:"Rate limits for this member's usage within this team.",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(sI.Z,{className:"sticky right-0 bg-white z-10 border-l border-gray-200",children:"Actions"})]})}),(0,c.jsx)(sk.Z,{children:s.team_info.members_with_roles.map((e,i)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_email?e.user_email:"No Email"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.role})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{className:"font-mono",children:["$",eE(o(e.user_id),4)]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:d(e.user_id)?"$".concat(eE(Number(d(e.user_id)),4)):"No Limit"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:m(e.user_id)})}),(0,c.jsx)(sS.Z,{className:"sticky right-0 bg-white z-10 border-l border-gray-200",children:t&&(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{var t,l,i;let n=s.team_memberships.find(s=>s.user_id===e.user_id);a({...e,max_budget_in_team:(null==n?void 0:null===(t=n.litellm_budget_table)||void 0===t?void 0:t.max_budget)||null,tpm_limit:(null==n?void 0:null===(l=n.litellm_budget_table)||void 0===l?void 0:l.tpm_limit)||null,rpm_limit:(null==n?void 0:null===(i=n.litellm_budget_table)||void 0===i?void 0:i.rpm_limit)||null}),r(!0)},className:"cursor-pointer hover:text-blue-600"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(e),className:"cursor-pointer hover:text-red-600"})]})})]},i))})]})})}),(0,c.jsx)(b.Z,{onClick:()=>i(!0),children:"Add Member"})]})},ts=t(61994),tt=t(85180),tl=t(89245),ta=t(78355);let tr={"/key/generate":"Member can generate a virtual key for this team","/key/service-account/generate":"Member can generate a service account key (not belonging to any user) for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},ti=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",tn=e=>{let s=ti(e),t=tr[e];if(!t){for(let[s,l]of Object.entries(tr))if(e.includes(s)){t=l;break}}return t||(t="Access ".concat(e)),{method:s,endpoint:e,description:t,route:e}};var to=e=>{let{teamId:s,accessToken:t,canEditTeam:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)([]),[o,m]=(0,d.useState)(!0),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),g=async()=>{try{if(m(!0),!t)return;let e=await (0,j.getTeamPermissionsCall)(t,s),l=e.all_available_permissions||[];r(l);let a=e.team_member_permissions||[];n(a),p(!1)}catch(e){eo.Z.fromBackend("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{m(!1)}};(0,d.useEffect)(()=>{g()},[s,t]);let f=(e,s)=>{n(s?[...i,e]:i.filter(s=>s!==e)),p(!0)},v=async()=>{try{if(!t)return;x(!0),await (0,j.teamPermissionsUpdateCall)(t,s,i),eo.Z.success("Permissions updated successfully"),p(!1)}catch(e){eo.Z.fromBackend("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{x(!1)}};if(o)return(0,c.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let y=a.length>0;return(0,c.jsxs)(G.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,c.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,c.jsx)(S.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),l&&h&&(0,c.jsxs)("div",{className:"flex gap-3",children:[(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(tl.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,c.jsxs)(b.Z,{onClick:v,loading:u,className:"flex items-center gap-2",children:[(0,c.jsx)(ta.Z,{})," Save Changes"]})]})]}),(0,c.jsx)(k.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),y?(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:" min-w-full",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Method"}),(0,c.jsx)(sI.Z,{children:"Endpoint"}),(0,c.jsx)(sI.Z,{children:"Description"}),(0,c.jsx)(sI.Z,{className:"sticky right-0 bg-white shadow-[-4px_0_4px_-4px_rgba(0,0,0,0.1)] text-center",children:"Allow Access"})]})}),(0,c.jsx)(sk.Z,{children:a.map(e=>{let s=tn(e);return(0,c.jsxs)(sA.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,c.jsx)(sS.Z,{className:"text-gray-700",children:s.description}),(0,c.jsx)(sS.Z,{className:"sticky right-0 bg-white shadow-[-4px_0_4px_-4px_rgba(0,0,0,0.1)] text-center",children:(0,c.jsx)(ts.Z,{checked:i.includes(e),onChange:s=>f(e,s.target.checked),disabled:!l})})]},e)})})]})}):(0,c.jsx)("div",{className:"py-12",children:(0,c.jsx)(tt.Z,{description:"No permissions available"})})]})},tc=t(42264),td=e=>{var s,t,l;let{visible:a,onCancel:r,onSubmit:i,initialData:n,mode:o,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",n),(0,d.useEffect)(()=>{if(a){if("edit"===o&&n){let e={...n,role:n.role||m.defaultRole,max_budget_in_team:n.max_budget_in_team||null,tpm_limit:n.tpm_limit||null,rpm_limit:n.rpm_limit||null};console.log("Setting form values:",e),u.setFieldsValue(e)}else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,n,o,u,m.defaultRole,m.roleOptions]);let x=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[t,l]=s;if("string"==typeof l){let s=l.trim();return""===s&&("max_budget_in_team"===t||"tpm_limit"===t||"rpm_limit"===t)?{...e,[t]:null}:{...e,[t]:s}}return{...e,[t]:l}},{});console.log("Submitting form data:",s),i(s),u.resetFields()}catch(e){console.error("Form submission error:",e)}},h=e=>{switch(e.type){case"input":return(0,c.jsx)(_.Z,{placeholder:e.placeholder});case"numerical":return(0,c.jsx)(O,{step:e.step||1,min:e.min||0,style:{width:"100%"},placeholder:e.placeholder||"Enter a numerical value"});case"select":var s;return(0,c.jsx)(eQ.Z,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value))});default:return null}};return(0,c.jsx)(L.Z,{title:m.title||("add"===o?"Add Member":"Edit Member"),open:a,width:1e3,footer:null,onCancel:r,children:(0,c.jsxs)(A.Z,{form:u,onFinish:x,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,c.jsx)(_.Z,{placeholder:"user@example.com"})}),m.showEmail&&m.showUserId&&(0,c.jsx)("div",{className:"text-center mb-4",children:(0,c.jsx)(k.Z,{children:"OR"})}),m.showUserId&&(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,c.jsx)(_.Z,{placeholder:"user_123"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{children:"Role"}),"edit"===o&&n&&(0,c.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(t=n.role,(null===(l=m.roleOptions.find(e=>e.value===t))||void 0===l?void 0:l.label)||t),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,c.jsx)(eQ.Z,{children:"edit"===o&&n?[...m.roleOptions.filter(e=>e.value===n.role),...m.roleOptions.filter(e=>e.value!==n.role)].map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value))})}),null===(s=m.additionalFields)||void 0===s?void 0:s.map(e=>(0,c.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:h(e)},e.name)),(0,c.jsxs)("div",{className:"text-right mt-6",children:[(0,c.jsx)(P.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,c.jsx)(P.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},tm=e=>{let{isVisible:s,onCancel:t,onSubmit:l,accessToken:a,title:r="Add Team Member",roles:i=[{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:n="user"}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)("user_email"),f=async(e,s)=>{if(!e){u([]);return}h(!0);try{let t=new URLSearchParams;if(t.append(s,e),null==a)return;let l=(await (0,j.userFilterUICall)(a,t)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));u(l)}catch(e){console.error("Error fetching users:",e)}finally{h(!1)}},v=(0,d.useCallback)(eC()((e,s)=>f(e,s),300),[]),y=(e,s)=>{g(s),v(e,s)},b=(e,s)=>{let t=s.user;o.setFieldsValue({user_email:t.user_email,user_id:t.user_id,role:o.getFieldValue("role")})};return(0,c.jsx)(L.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),u([]),t()},footer:null,width:800,children:(0,c.jsxs)(A.Z,{form:o,onFinish:l,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:n},children:[(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>y(e,"user_email"),onSelect:(e,s)=>b(e,s),options:"user_email"===p?m:[],loading:x,allowClear:!0})}),(0,c.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>y(e,"user_id"),onSelect:(e,s)=>b(e,s),options:"user_id"===p?m:[],loading:x,allowClear:!0})}),(0,c.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,c.jsx)(I.default,{defaultValue:n,children:i.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,children:(0,c.jsxs)(V.Z,{title:e.description,children:[(0,c.jsx)("span",{className:"font-medium",children:e.label}),(0,c.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,c.jsx)("div",{className:"text-right mt-4",children:(0,c.jsx)(P.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},tu=e=>{var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f;let{teamId:v,onClose:N,accessToken:Z,is_team_admin:w,is_proxy_admin:C,userModels:L,editTeam:T,premiumUser:M=!1,onUpdate:D}=e,[R,z]=(0,d.useState)(null),[q,K]=(0,d.useState)(!0),[H,J]=(0,d.useState)(!1),[Y]=A.Z.useForm(),[W,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(null),[ee,es]=(0,d.useState)(!1),[et,el]=(0,d.useState)([]),[ea,er]=(0,d.useState)(!1),[ei,en]=(0,d.useState)({}),[ec,ed]=(0,d.useState)([]);console.log("userModels in team info",L);let em=w||C,eu=async()=>{try{if(K(!0),!Z)return;let e=await (0,j.teamInfoCall)(Z,v);z(e)}catch(e){eo.Z.fromBackend("Failed to load team information"),console.error("Error fetching team info:",e)}finally{K(!1)}};(0,d.useEffect)(()=>{eu()},[v,Z]),(0,d.useEffect)(()=>{(async()=>{try{if(!Z)return;let e=(await (0,j.getGuardrailsList)(Z)).guardrails.map(e=>e.guardrail_name);ed(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[Z]);let ex=async e=>{try{if(null==Z)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.teamMemberAddCall)(Z,v,s),eo.Z.success("Team member added successfully"),J(!1),Y.resetFields();let t=await (0,j.teamInfoCall)(Z,v);z(t),D(t)}catch(a){var s,t,l;let e="Failed to add team member";(null==a?void 0:null===(l=a.raw)||void 0===l?void 0:null===(t=l.detail)||void 0===t?void 0:null===(s=t.error)||void 0===s?void 0:s.includes("Assigning team admins is a premium feature"))?e="Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.":(null==a?void 0:a.message)&&(e=a.message),eo.Z.fromBackend(e),console.error("Error adding team member:",a)}},eh=async e=>{try{if(null==Z)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role,max_budget_in_team:e.max_budget_in_team,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit};console.log("Updating member with values:",s),tc.ZP.destroy(),await (0,j.teamMemberUpdateCall)(Z,v,s),eo.Z.success("Team member updated successfully"),$(!1);let t=await (0,j.teamInfoCall)(Z,v);z(t),D(t)}catch(l){var s,t;let e="Failed to update team member";(null==l?void 0:null===(t=l.raw)||void 0===t?void 0:null===(s=t.detail)||void 0===s?void 0:s.includes("Assigning team admins is a premium feature"))?e="Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.":(null==l?void 0:l.message)&&(e=l.message),$(!1),tc.ZP.destroy(),eo.Z.fromBackend(e),console.error("Error updating team member:",l)}},ep=async e=>{try{if(null==Z)return;await (0,j.teamMemberDeleteCall)(Z,v,e),eo.Z.success("Team member removed successfully");let s=await (0,j.teamInfoCall)(Z,v);z(s),D(s)}catch(e){eo.Z.fromBackend("Failed to remove team member"),console.error("Error removing team member:",e)}},eg=async e=>{try{if(!Z)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t=e=>null==e||"string"==typeof e&&""===e.trim()||"number"==typeof e&&Number.isNaN(e)?null:e,l={team_id:v,team_alias:e.team_alias,models:e.models,tpm_limit:t(e.tpm_limit),rpm_limit:t(e.rpm_limit),max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[],logging:e.logging_settings||[]},organization_id:e.organization_id};void 0!==e.team_member_budget&&(l.team_member_budget=Number(e.team_member_budget)),void 0!==e.team_member_key_duration&&(l.team_member_key_duration=e.team_member_key_duration),(void 0!==e.team_member_tpm_limit||void 0!==e.team_member_rpm_limit)&&(l.team_member_tpm_limit=t(e.team_member_tpm_limit),l.team_member_rpm_limit=t(e.team_member_rpm_limit));let{servers:a,accessGroups:r}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};(a&&a.length>0||r&&r.length>0)&&(l.object_permission={},a&&a.length>0&&(l.object_permission.mcp_servers=a),r&&r.length>0&&(l.object_permission.mcp_access_groups=r)),delete e.mcp_servers_and_groups,await (0,j.teamUpdateCall)(Z,l),eo.Z.success("Team settings updated successfully"),es(!1),eu()}catch(e){console.error("Error updating team:",e)}};if(q)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==R?void 0:R.team_info))return(0,c.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:ej}=R,ef=async(e,s)=>{await eM(e)&&(en(e=>({...e,[s]:!0})),setTimeout(()=>{en(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:N,className:"mb-4",children:"Back to Teams"}),(0,c.jsx)(S.Z,{children:ej.team_alias}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:ej.team_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:ei["team-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>ef(ej.team_id,"team-id"),className:"left-2 z-10 transition-all duration-200 ".concat(ei["team-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:T?3:0,children:[(0,c.jsx)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),...em?[(0,c.jsx)(e0.Z,{children:"Members"},"members"),(0,c.jsx)(e0.Z,{children:"Member Permissions"},"member-permissions"),(0,c.jsx)(e0.Z,{children:"Settings"},"settings")]:[]]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Budget Status"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(ej.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null===ej.max_budget?"Unlimited":"$".concat(eE(ej.max_budget,4))]}),ej.budget_duration&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Reset: ",ej.budget_duration]}),(0,c.jsx)("br",{}),ej.team_member_budget_table&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Team Member Budget: $",eE(ej.team_member_budget_table.max_budget,4)]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",ej.tpm_limit||"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",ej.rpm_limit||"Unlimited"]}),ej.max_parallel_requests&&(0,c.jsxs)(k.Z,{children:["Max Parallel Requests: ",ej.max_parallel_requests]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:0===ej.models.length?(0,c.jsx)(eX.Z,{color:"red",children:"All proxy models"}):ej.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Virtual Keys"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["User Keys: ",R.keys.filter(e=>e.user_id).length]}),(0,c.jsxs)(k.Z,{children:["Service Account Keys: ",R.keys.filter(e=>!e.user_id).length]}),(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Total: ",R.keys.length]})]})]}),(0,c.jsx)(sc,{objectPermission:ej.object_permission,variant:"card",accessToken:Z}),(0,c.jsx)(sd,{loggingConfigs:(null===(s=ej.metadata)||void 0===s?void 0:s.logging)||[],disabledCallbacks:[],variant:"card"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(te,{teamData:R,canEditTeam:em,handleMemberDelete:ep,setSelectedEditMember:X,setIsEditMemberModalVisible:$,setIsAddMemberModalVisible:J})}),em&&(0,c.jsx)(e4.Z,{children:(0,c.jsx)(to,{teamId:v,accessToken:Z,canEditTeam:em})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Team Settings"}),em&&!ee&&(0,c.jsx)(b.Z,{onClick:()=>es(!0),children:"Edit Settings"})]}),ee?(0,c.jsxs)(A.Z,{form:Y,onFinish:eg,initialValues:{...ej,team_alias:ej.team_alias,models:ej.models,tpm_limit:ej.tpm_limit,rpm_limit:ej.rpm_limit,max_budget:ej.max_budget,budget_duration:ej.budget_duration,team_member_tpm_limit:null===(t=ej.team_member_budget_table)||void 0===t?void 0:t.tpm_limit,team_member_rpm_limit:null===(l=ej.team_member_budget_table)||void 0===l?void 0:l.rpm_limit,guardrails:(null===(a=ej.metadata)||void 0===a?void 0:a.guardrails)||[],metadata:ej.metadata?JSON.stringify((e=>{let{logging:s,...t}=e;return t})(ej.metadata),null,2):"",logging_settings:(null===(r=ej.metadata)||void 0===r?void 0:r.logging)||[],organization_id:ej.organization_id,vector_stores:(null===(i=ej.object_permission)||void 0===i?void 0:i.vector_stores)||[],mcp_servers:(null===(n=ej.object_permission)||void 0===n?void 0:n.mcp_servers)||[],mcp_access_groups:(null===(o=ej.object_permission)||void 0===o?void 0:o.mcp_access_groups)||[],mcp_servers_and_groups:{servers:(null===(m=ej.object_permission)||void 0===m?void 0:m.mcp_servers)||[],accessGroups:(null===(u=ej.object_permission)||void 0===u?void 0:u.mcp_access_groups)||[]}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,c.jsx)(E.default,{type:""})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),Array.from(new Set(L)).map((e,s)=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},s))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Budget (USD)",name:"team_member_budget",tooltip:"This is the individual budget for a user in the team.",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Key Duration (eg: 1d, 1mo)",name:"team_member_key_duration",tooltip:"Set a limit to the duration of a team member's key. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days), 1mo (month)",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member TPM Limit",name:"team_member_tpm_limit",tooltip:"Default tokens per minute limit for an individual team member. This limit applies to all requests the user makes within this team. Can be overridden per member.",children:(0,c.jsx)(O,{step:1,style:{width:"100%"},placeholder:"e.g., 1000"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member RPM Limit",name:"team_member_rpm_limit",tooltip:"Default requests per minute limit for an individual team member. This limit applies to all requests the user makes within this team. Can be overridden per member.",children:(0,c.jsx)(O,{step:1,style:{width:"100%"},placeholder:"e.g., 100"})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Setup your first guardrail",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,c.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails",options:ec.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>Y.setFieldValue("vector_stores",e),value:Y.getFieldValue("vector_stores"),accessToken:Z||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers / Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>Y.setFieldValue("mcp_servers_and_groups",e),value:Y.getFieldValue("mcp_servers_and_groups"),accessToken:Z||"",placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,c.jsx)(E.default,{type:""})}),(0,c.jsx)(A.Z.Item,{label:"Logging Settings",name:"logging_settings",children:(0,c.jsx)(e8,{value:Y.getFieldValue("logging_settings"),onChange:e=>Y.setFieldValue("logging_settings",e)})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:10})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{htmlType:"button",onClick:()=>es(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team Name"}),(0,c.jsx)("div",{children:ej.team_alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)("div",{className:"font-mono",children:ej.team_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:new Date(ej.created_at).toLocaleString()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:ej.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)("div",{children:["TPM: ",ej.tpm_limit||"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",ej.rpm_limit||"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team Budget"}),(0,c.jsxs)("div",{children:["Max Budget:"," ",null!==ej.max_budget?"$".concat(eE(ej.max_budget,4)):"No Limit"]}),(0,c.jsxs)("div",{children:["Budget Reset: ",ej.budget_duration||"Never"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Team Member Settings"," ",(0,c.jsx)(V.Z,{title:"These are limits on individual team members",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),(0,c.jsxs)("div",{children:["Max Budget:"," ",(null===(x=ej.team_member_budget_table)||void 0===x?void 0:x.max_budget)||"No Limit"]}),(0,c.jsxs)("div",{children:["Key Duration:"," ",(null===(h=ej.metadata)||void 0===h?void 0:h.team_member_key_duration)||"No Limit"]}),(0,c.jsxs)("div",{children:["TPM Limit:"," ",(null===(p=ej.team_member_budget_table)||void 0===p?void 0:p.tpm_limit)||"No Limit"]}),(0,c.jsxs)("div",{children:["RPM Limit:"," ",(null===(g=ej.team_member_budget_table)||void 0===g?void 0:g.rpm_limit)||"No Limit"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization ID"}),(0,c.jsx)("div",{children:ej.organization_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Status"}),(0,c.jsx)(eX.Z,{color:ej.blocked?"red":"green",children:ej.blocked?"Blocked":"Active"})]}),(0,c.jsx)(sc,{objectPermission:ej.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:Z}),(0,c.jsx)(sd,{loggingConfigs:(null===(f=ej.metadata)||void 0===f?void 0:f.logging)||[],disabledCallbacks:[],variant:"inline",className:"pt-4 border-t border-gray-200"})]})]})})]})]}),(0,c.jsx)(td,{visible:W,onCancel:()=>$(!1),onSubmit:eh,initialData:Q,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}],additionalFields:[{name:"max_budget_in_team",label:(0,c.jsxs)("span",{children:["Team Member Budget (USD)"," ",(0,c.jsx)(V.Z,{title:"Maximum amount in USD this member can spend within this team. This is separate from any global user budget limits",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:.01,min:0,placeholder:"Budget limit for this member within this team"},{name:"tpm_limit",label:(0,c.jsxs)("span",{children:["Team Member TPM Limit"," ",(0,c.jsx)(V.Z,{title:"Maximum tokens per minute this member can use within this team. This is separate from any global user TPM limit",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:1,min:0,placeholder:"Tokens per minute limit for this member in this team"},{name:"rpm_limit",label:(0,c.jsxs)("span",{children:["Team Member RPM Limit"," ",(0,c.jsx)(V.Z,{title:"Maximum requests per minute this member can make within this team. This is separate from any global user RPM limit",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:1,min:0,placeholder:"Requests per minute limit for this member in this team"}]}}),(0,c.jsx)(tm,{isVisible:H,onCancel:()=>J(!1),onSubmit:ex,accessToken:Z})]})},tx=t(45589);let{Title:th,Link:tp}=en.default;var tg=e=>{let{isVisible:s,onCancel:t,onAddCredential:l,existingCredential:a,setIsCredentialModalOpen:r}=e,[i]=A.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,c.jsx)(L.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{t(),i.resetFields()},footer:null,width:600,children:(0,c.jsxs)(A.Z,{form:i,onFinish:e=>{l(e),i.resetFields(),r(!1)},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,c.jsx)(sW.o,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,t]=e;return(0,c.jsx)(A.Z.Item,{label:s,name:s,initialValue:t,children:(0,c.jsx)(sW.o,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(tp,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:()=>{t(),i.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},tj=t(63709),tf=t(45246),tv=t(96473);let{Text:ty}=en.default;var tb=e=>{let{form:s,showCacheControl:t,onCacheControlChange:l}=e,a=e=>{let t=s.getFieldValue("litellm_extra_params");try{let l=t?JSON.parse(t):{};e.length>0?l.cache_control_injection_points=e:delete l.cache_control_injection_points,Object.keys(l).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,c.jsx)(tj.Z,{onChange:l,className:"bg-gray-600"})}),t&&(0,c.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,c.jsx)(ty,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,c.jsx)(A.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,t)=>{let{add:l,remove:r}=t;return(0,c.jsxs)(c.Fragment,{children:[e.map((t,l)=>(0,c.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,c.jsx)(A.Z.Item,{...t,label:"Type",name:[t.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,c.jsx)(I.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,c.jsx)(A.Z.Item,{...t,label:"Role",name:[t.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,c.jsx)(I.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,c.jsx)(A.Z.Item,{...t,label:"Index",name:[t.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,c.jsx)(O,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,c.jsx)(tf.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(t.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},t.key)),(0,c.jsx)(A.Z.Item,{children:(0,c.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>l(),children:[(0,c.jsx)(tv.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})},t_=t(44851),tN=t(67960),tZ=t(70464);let{TextArea:tw}=E.default,{Panel:tk}=t_.default;var tS=e=>{let{modelInfo:s,value:t,onChange:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]);(0,d.useEffect)(()=>{if(null==t?void 0:t.routes){let e=t.routes.map((e,s)=>({id:e.id||"route-".concat(s,"-").concat(Date.now()),model:e.name||e.model||"",utterances:e.utterances||[],description:e.description||"",score_threshold:e.score_threshold||.5}));r(e),m(e.map(e=>e.id))}else r([]),m([])},[t]);let u=e=>{let s=a.filter(s=>s.id!==e);r(s),h(s),m(s=>s.filter(s=>s!==e))},x=(e,s,t)=>{let l=a.map(l=>l.id===e?{...l,[s]:t}:l);r(l),h(l)},h=e=>{let s={routes:e.map(e=>({name:e.model,utterances:e.utterances,description:e.description,score_threshold:e.score_threshold}))};null==l||l(s)},p=s.map(e=>({value:e.model_group,label:e.model_group}));return(0,c.jsxs)("div",{className:"w-full max-w-none",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6 w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold",children:"Routes Configuration"}),(0,c.jsx)(V.Z,{title:"Configure routing logic to automatically select the best model based on user input patterns",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(P.ZP,{type:"primary",icon:(0,c.jsx)(tv.Z,{}),onClick:()=>{let e="route-".concat(Date.now()),s=[...a,{id:e,model:"",utterances:[],description:"",score_threshold:.5}];r(s),h(s),m(s=>[...s,e])},className:"bg-blue-600 hover:bg-blue-700",children:"Add Route"})]}),0===a.length?(0,c.jsx)("div",{className:"text-center py-12 text-gray-500 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200 mb-6",children:(0,c.jsx)(k.Z,{children:"No routes configured. Click “Add Route” to get started."})}):(0,c.jsx)("div",{className:"space-y-3 mb-6 w-full",children:a.map((e,s)=>(0,c.jsx)(tN.Z,{className:"border border-gray-200 shadow-sm w-full",bodyStyle:{padding:0},children:(0,c.jsx)(t_.default,{ghost:!0,expandIcon:e=>{let{isActive:s}=e;return(0,c.jsx)(tZ.Z,{rotate:s?180:0})},activeKey:o,onChange:e=>m(Array.isArray(e)?e:[e].filter(Boolean)),items:[{key:e.id,label:(0,c.jsxs)("div",{className:"flex justify-between items-center py-2",children:[(0,c.jsxs)(k.Z,{className:"font-medium text-base",children:["Route ",s+1,": ",e.model||"Unnamed"]}),(0,c.jsx)(P.ZP,{type:"text",danger:!0,icon:(0,c.jsx)(ep.Z,{}),onClick:s=>{s.stopPropagation(),u(e.id)},className:"mr-2"})]}),children:(0,c.jsxs)("div",{className:"px-6 pb-6 w-full",children:[(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-2 block",children:"Model"}),(0,c.jsx)(I.default,{value:e.model,onChange:s=>x(e.id,"model",s),placeholder:"Select model",showSearch:!0,style:{width:"100%"},options:p})]}),(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-2 block",children:"Description"}),(0,c.jsx)(tw,{value:e.description,onChange:s=>x(e.id,"description",s.target.value),placeholder:"Describe when this route should be used...",rows:2,style:{width:"100%"}})]}),(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium",children:"Score Threshold"}),(0,c.jsx)(V.Z,{title:"Minimum similarity score to route to this model (0-1)",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(eW.Z,{value:e.score_threshold,onChange:s=>x(e.id,"score_threshold",s||0),min:0,max:1,step:.1,style:{width:"100%"},placeholder:"0.5"})]}),(0,c.jsxs)("div",{className:"w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium",children:"Example Utterances"}),(0,c.jsx)(V.Z,{title:"Training examples for this route. Type an utterance and press Enter to add it.",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500 mb-2",children:"Type an utterance and press Enter to add it. You can also paste multiple lines."}),(0,c.jsx)(I.default,{mode:"tags",value:e.utterances,onChange:s=>x(e.id,"utterances",s),placeholder:"Type an utterance and press Enter...",style:{width:"100%"},tokenSeparators:["\n"],maxTagCount:"responsive",allowClear:!0})]})]})}]})},e.id))}),(0,c.jsxs)("div",{className:"border-t pt-6 w-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold",children:"JSON Preview"}),(0,c.jsx)(P.ZP,{type:"link",onClick:()=>n(!i),className:"text-blue-600 p-0",children:i?"Hide":"Show"})]}),i&&(0,c.jsx)(tN.Z,{className:"bg-gray-50 w-full",children:(0,c.jsx)("pre",{className:"text-sm overflow-auto max-h-64 w-full",children:JSON.stringify({routes:a.map(e=>({name:e.model,utterances:e.utterances,description:e.description,score_threshold:e.score_threshold}))},null,2)})})]})]})},tC=e=>{let{isVisible:s,onCancel:t,onSuccess:l,modelData:a,accessToken:r,userRole:i}=e,[n]=A.Z.useForm(),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)(!1),[b,N]=(0,d.useState)(null);(0,d.useEffect)(()=>{s&&a&&Z()},[s,a]),(0,d.useEffect)(()=>{let e=async()=>{if(r)try{let e=await (0,j.modelAvailableCall)(r,"","",!1,null,!0,!0);x(e.data.map(e=>e.id))}catch(e){console.error("Error fetching model access groups:",e)}},t=async()=>{if(r)try{let e=await eU(r);p(e)}catch(e){console.error("Error fetching model info:",e)}};s&&(e(),t())},[s,r]);let Z=()=>{try{var e,s,t,l,r,i;let o=null;(null===(e=a.litellm_params)||void 0===e?void 0:e.auto_router_config)&&(o="string"==typeof a.litellm_params.auto_router_config?JSON.parse(a.litellm_params.auto_router_config):a.litellm_params.auto_router_config),N(o),n.setFieldsValue({auto_router_name:a.model_name,auto_router_default_model:(null===(s=a.litellm_params)||void 0===s?void 0:s.auto_router_default_model)||"",auto_router_embedding_model:(null===(t=a.litellm_params)||void 0===t?void 0:t.auto_router_embedding_model)||"",model_access_group:(null===(l=a.model_info)||void 0===l?void 0:l.access_groups)||[]});let c=new Set(h.map(e=>e.model_group));f(!c.has(null===(r=a.litellm_params)||void 0===r?void 0:r.auto_router_default_model)),y(!c.has(null===(i=a.litellm_params)||void 0===i?void 0:i.auto_router_embedding_model))}catch(e){console.error("Error parsing auto router config:",e),eo.Z.fromBackend("Error loading auto router configuration")}},w=async()=>{try{m(!0);let e=await n.validateFields(),s={...a.litellm_params,auto_router_config:JSON.stringify(b),auto_router_default_model:e.auto_router_default_model,auto_router_embedding_model:e.auto_router_embedding_model||void 0},i={...a.model_info,access_groups:e.model_access_group||[]},o={model_name:e.auto_router_name,litellm_params:s,model_info:i};await (0,j.modelPatchUpdateCall)(r,o,a.model_info.id);let c={...a,model_name:e.auto_router_name,litellm_params:s,model_info:i};eo.Z.success("Auto router configuration updated successfully"),l(c),t()}catch(e){console.error("Error updating auto router:",e),eo.Z.fromBackend("Failed to update auto router configuration")}finally{m(!1)}},S=h.map(e=>({value:e.model_group,label:e.model_group}));return(0,c.jsx)(L.Z,{title:"Edit Auto Router Configuration",open:s,onCancel:t,footer:[(0,c.jsx)(P.ZP,{onClick:t,children:"Cancel"},"cancel"),(0,c.jsx)(P.ZP,{loading:o,onClick:w,children:"Save Changes"},"submit")],width:1e3,destroyOnClose:!0,children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsx)(k.Z,{className:"text-gray-600",children:"Edit the auto router configuration including routing logic, default models, and access settings."}),(0,c.jsxs)(A.Z,{form:n,layout:"vertical",className:"space-y-4",children:[(0,c.jsx)(A.Z.Item,{label:"Auto Router Name",name:"auto_router_name",rules:[{required:!0,message:"Auto router name is required"}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., auto_router_1, smart_routing"})}),(0,c.jsx)("div",{className:"w-full",children:(0,c.jsx)(tS,{modelInfo:h,value:b,onChange:e=>{N(e)}})}),(0,c.jsx)(A.Z.Item,{label:"Default Model",name:"auto_router_default_model",rules:[{required:!0,message:"Default model is required"}],children:(0,c.jsx)(I.default,{placeholder:"Select a default model",onChange:e=>{f("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model name"}],showSearch:!0})}),(0,c.jsx)(A.Z.Item,{label:"Embedding Model",name:"auto_router_embedding_model",children:(0,c.jsx)(I.default,{placeholder:"Select an embedding model (optional)",onChange:e=>{y("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model name"}],showSearch:!0,allowClear:!0})}),"Admin"===i&&(0,c.jsx)(A.Z.Item,{label:"Model Access Groups",name:"model_access_group",tooltip:"Control who can access this auto router",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:u.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})})]})]})})};function tI(e){var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f,v,N,Z,w,C,T,M,D,F,R,z,U,q;let{modelId:K,onClose:H,modelData:J,accessToken:Y,userID:$,userRole:Q,editModel:X,setEditModalVisible:ee,setSelectedModel:es,onModelUpdate:et,modelAccessGroups:el}=e,[ea]=A.Z.useForm(),[er,ei]=(0,d.useState)(null),[en,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(!1),[eu,ex]=(0,d.useState)(!1),[eh,ep]=(0,d.useState)(!1),[eg,ej]=(0,d.useState)(!1),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(!1),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)(!1),[ek,eS]=(0,d.useState)([]),eC="Admin"===Q||(null==J?void 0:null===(s=J.model_info)||void 0===s?void 0:s.created_by)===$,eI=(null==J?void 0:null===(t=J.litellm_params)||void 0===t?void 0:t.auto_router_config)!=null,eA=(null==J?void 0:null===(l=J.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=null&&(null==J?void 0:null===(a=J.litellm_params)||void 0===a?void 0:a.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",eA),console.log("modelData.litellm_params.litellm_credential_name, ",null==J?void 0:null===(r=J.litellm_params)||void 0===r?void 0:r.litellm_credential_name),(0,d.useEffect)(()=>{let e=async()=>{var e;if(!Y)return;let s=await (0,j.modelInfoV1Call)(Y,K);console.log("modelInfoResponse, ",s);let t=s.data[0];ei(t),(null==t?void 0:null===(e=t.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&eb(!0)},s=async()=>{if(Y)try{let e=(await (0,j.getGuardrailsList)(Y)).guardrails.map(e=>e.guardrail_name);eS(e)}catch(e){console.error("Failed to fetch guardrails:",e)}};(async()=>{if(console.log("accessToken, ",Y),!Y||eA)return;let e=await (0,j.credentialGetCall)(Y,null,K);console.log("existingCredentialResponse, ",e),ev({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e(),s()},[Y,K]);let eL=async e=>{var s;if(console.log("values, ",e),!Y)return;let t={credential_name:e.credential_name,model_id:K,credential_info:{custom_llm_provider:null===(s=er.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};eo.Z.info("Storing credential.."),console.log("credentialResponse, ",await (0,j.credentialCreateCall)(Y,t)),eo.Z.success("Credential stored successfully")},eT=async e=>{try{var s;let t;if(!Y)return;ep(!0),console.log("values.model_name, ",e.model_name);let l={...er.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};e.guardrails&&(l.guardrails=e.guardrails),e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;try{t=e.model_info?JSON.parse(e.model_info):J.model_info,e.model_access_group&&(t={...t,access_groups:e.model_access_group})}catch(e){eo.Z.fromBackend("Invalid JSON in Model Info");return}let a={model_name:e.model_name,litellm_params:l,model_info:t};await (0,j.modelPatchUpdateCall)(Y,a,K);let r={...er,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l,model_info:t};ei(r),et&&et(r),eo.Z.success("Model settings updated successfully"),ex(!1),ej(!1)}catch(e){console.error("Error updating model:",e),eo.Z.fromBackend("Failed to update model settings")}finally{ep(!1)}};if(!J)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:H,className:"mb-4",children:"Back to Models"}),(0,c.jsx)(k.Z,{children:"Model not found"})]});let eP=async()=>{try{if(!Y)return;await (0,j.modelDeleteCall)(Y,K),eo.Z.success("Model deleted successfully"),et&&et({deleted:!0,model_info:{id:K}}),H()}catch(e){console.error("Error deleting the model:",e),eo.Z.fromBackend("Failed to delete model")}},eE=async(e,s)=>{await eM(e)&&(eN(e=>({...e,[s]:!0})),setTimeout(()=>{eN(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:H,className:"mb-4",children:"Back to Models"}),(0,c.jsxs)(S.Z,{children:["Public Model Name: ",s2(J)]}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:J.model_info.id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["model-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eE(J.model_info.id,"model-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["model-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{className:"flex gap-2",children:["Admin"===Q&&(0,c.jsx)(b.Z,{icon:tx.Z,variant:"secondary",onClick:()=>em(!0),className:"flex items-center",children:"Re-use Credentials"}),eC&&(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>ec(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Raw JSON"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Provider"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[J.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(J.provider).logo,alt:"".concat(J.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var l;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===(l=J.provider)||void 0===l?void 0:l.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,c.jsx)(S.Z,{children:J.provider||"Not Set"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"LiteLLM Model"}),(0,c.jsx)("div",{className:"mt-2 overflow-hidden",children:(0,c.jsx)(V.Z,{title:J.litellm_model_name||"Not Set",children:(0,c.jsx)("div",{className:"break-all text-sm font-medium leading-relaxed cursor-pointer",children:J.litellm_model_name||"Not Set"})})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Pricing"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["Input: $",J.input_cost,"/1M tokens"]}),(0,c.jsxs)(k.Z,{children:["Output: $",J.output_cost,"/1M tokens"]})]})]})]}),(0,c.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,c.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"," ",J.model_info.created_at?new Date(J.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,c.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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 ",J.model_info.created_by||"Not Set"]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Model Settings"}),(0,c.jsxs)("div",{className:"flex gap-2",children:[eI&&eC&&!eg&&(0,c.jsx)(b.Z,{variant:"primary",onClick:()=>ew(!0),className:"flex items-center",children:"Edit Auto Router"}),eC&&!eg&&(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>ej(!0),className:"flex items-center",children:"Edit Model"})]})]}),er?(0,c.jsx)(A.Z,{form:ea,onFinish:eT,initialValues:{model_name:er.model_name,litellm_model_name:er.litellm_model_name,api_base:er.litellm_params.api_base,custom_llm_provider:er.litellm_params.custom_llm_provider,organization:er.litellm_params.organization,tpm:er.litellm_params.tpm,rpm:er.litellm_params.rpm,max_retries:er.litellm_params.max_retries,timeout:er.litellm_params.timeout,stream_timeout:er.litellm_params.stream_timeout,input_cost:er.litellm_params.input_cost_per_token?1e6*er.litellm_params.input_cost_per_token:(null===(i=er.model_info)||void 0===i?void 0:i.input_cost_per_token)*1e6||null,output_cost:(null===(n=er.litellm_params)||void 0===n?void 0:n.output_cost_per_token)?1e6*er.litellm_params.output_cost_per_token:(null===(o=er.model_info)||void 0===o?void 0:o.output_cost_per_token)*1e6||null,cache_control:null!==(m=er.litellm_params)&&void 0!==m&&!!m.cache_control_injection_points,cache_control_injection_points:(null===(u=er.litellm_params)||void 0===u?void 0:u.cache_control_injection_points)||[],model_access_group:Array.isArray(null===(x=er.model_info)||void 0===x?void 0:x.access_groups)?er.model_info.access_groups:[],guardrails:Array.isArray(null===(h=er.litellm_params)||void 0===h?void 0:h.guardrails)?er.litellm_params.guardrails:[]},layout:"vertical",onValuesChange:()=>ex(!0),children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Name"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter model name"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:er.model_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Model Name"}),eg?(0,c.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter LiteLLM model name"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:er.litellm_model_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),eg?(0,c.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter input cost"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==er?void 0:null===(p=er.litellm_params)||void 0===p?void 0:p.input_cost_per_token)?((null===(g=er.litellm_params)||void 0===g?void 0:g.input_cost_per_token)*1e6).toFixed(4):(null==er?void 0:null===(f=er.model_info)||void 0===f?void 0:f.input_cost_per_token)?(1e6*er.model_info.input_cost_per_token).toFixed(4):null})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),eg?(0,c.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter output cost"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==er?void 0:null===(v=er.litellm_params)||void 0===v?void 0:v.output_cost_per_token)?(1e6*er.litellm_params.output_cost_per_token).toFixed(4):(null==er?void 0:null===(N=er.model_info)||void 0===N?void 0:N.output_cost_per_token)?(1e6*er.model_info.output_cost_per_token).toFixed(4):null})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"API Base"}),eg?(0,c.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter API base"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=er.litellm_params)||void 0===Z?void 0:Z.api_base)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Custom LLM Provider"}),eg?(0,c.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter custom LLM provider"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=er.litellm_params)||void 0===w?void 0:w.custom_llm_provider)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization"}),eg?(0,c.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter organization"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=er.litellm_params)||void 0===C?void 0:C.organization)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),eg?(0,c.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter TPM"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(T=er.litellm_params)||void 0===T?void 0:T.tpm)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),eg?(0,c.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter RPM"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(M=er.litellm_params)||void 0===M?void 0:M.rpm)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Max Retries"}),eg?(0,c.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter max retries"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(D=er.litellm_params)||void 0===D?void 0:D.max_retries)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Timeout (seconds)"}),eg?(0,c.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter timeout"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(F=er.litellm_params)||void 0===F?void 0:F.timeout)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),eg?(0,c.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter stream timeout"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(R=er.litellm_params)||void 0===R?void 0:R.stream_timeout)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Access Groups"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_access_group",className:"mb-0",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],maxTagCount:"responsive",allowClear:!0,style:{width:"100%"},options:null==el?void 0:el.map(e=>({value:e,label:e}))})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(z=er.model_info)||void 0===z?void 0:z.access_groups)?Array.isArray(er.model_info.access_groups)?er.model_info.access_groups.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:er.model_info.access_groups.map((e,s)=>(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800",children:e},s))}):"No groups assigned":er.model_info.access_groups:"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this model to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),eg?(0,c.jsx)(A.Z.Item,{name:"guardrails",className:"mb-0",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing guardrails or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],maxTagCount:"responsive",allowClear:!0,style:{width:"100%"},options:ek.map(e=>({value:e,label:e}))})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(U=er.litellm_params)||void 0===U?void 0:U.guardrails)?Array.isArray(er.litellm_params.guardrails)?er.litellm_params.guardrails.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:er.litellm_params.guardrails.map((e,s)=>(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800",children:e},s))}):"No guardrails assigned":er.litellm_params.guardrails:"Not Set"})]}),eg?(0,c.jsx)(tb,{form:ea,showCacheControl:ey,onCacheControlChange:e=>eb(e)}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cache Control"}),(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(q=er.litellm_params)||void 0===q?void 0:q.cache_control_injection_points)?(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"Enabled"}),(0,c.jsx)("div",{className:"mt-2",children:er.litellm_params.cache_control_injection_points.map((e,s)=>(0,c.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,c.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,c.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Info"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_info",className:"mb-0",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}',defaultValue:JSON.stringify(J.model_info,null,2)})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(er.model_info,null,2)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:J.model_info.team_id||"Not Set"})]})]}),eg&&(0,c.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{ea.resetFields(),ex(!1),ej(!1)},children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",onClick:()=>ea.submit(),loading:eh,children:"Save Changes"})]})]})}):(0,c.jsx)(k.Z,{children:"Loading..."})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(G.Z,{children:(0,c.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(J,null,2)})})})]})]}),en&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(P.ZP,{onClick:eP,className:"ml-2",danger:!0,children:"Delete"}),(0,c.jsx)(P.ZP,{onClick:()=>ec(!1),children:"Cancel"})]})]})]})}),ed&&!eA?(0,c.jsx)(tg,{isVisible:ed,onCancel:()=>em(!1),onAddCredential:eL,existingCredential:ef,setIsCredentialModalOpen:em}):(0,c.jsx)(L.Z,{open:ed,onCancel:()=>em(!1),title:"Using Existing Credential",children:(0,c.jsx)(k.Z,{children:J.litellm_params.litellm_credential_name})}),(0,c.jsx)(tC,{isVisible:eZ,onCancel:()=>ew(!1),onSuccess:e=>{ei(e),et&&et(e)},modelData:er||J,accessToken:Y||"",userRole:Q||""})]})}var tA=e=>{let{selectedProvider:s,providerModels:t,getPlaceholder:l}=e,a=A.Z.useFormInstance(),r=e=>{let t=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?s===sU.Cl.Azure?{public_name:t,litellm_model:"azure/".concat(t)}:{public_name:t,litellm_model:t}:e);a.setFieldsValue({model_mappings:l})};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"The model name LiteLLM will send to the LLM API",className:"mb-0",children:[(0,c.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please enter ".concat(s===sU.Cl.Azure?"a deployment name":"at least one model",".")}],noStyle:!0,children:s===sU.Cl.Azure||s===sU.Cl.OpenAI_Compatible||s===sU.Cl.Ollama?(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(_.Z,{placeholder:l(s),onChange:s===sU.Cl.Azure?e=>{let s=e.target.value,t=s?[{public_name:s,litellm_model:"azure/".concat(s)}]:[];a.setFieldsValue({model:s,model_mappings:t})}:void 0})}):t.length>0?(0,c.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let t=Array.isArray(e)?e:[e];if(t.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(t)){let e=t.map(e=>s===sU.Cl.Azure?{public_name:e,litellm_model:"azure/".concat(e)}:{public_name:e,litellm_model:e});a.setFieldsValue({model:t,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...t.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,c.jsx)(_.Z,{placeholder:l(s)})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:t}=e,l=t("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,c.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,c.jsx)(_.Z,{placeholder:s===sU.Cl.Azure?"Enter Azure deployment name":"Enter custom model name",onChange:r})})}})]}),(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:14,children:(0,c.jsx)(k.Z,{className:"mb-3 mt-1",children:s===sU.Cl.Azure?"Your deployment name will be saved as the public model name, and LiteLLM will use 'azure/deployment-name' internally":"The model name LiteLLM will send to the LLM API"})})]})]})},tL=t(67187);let tT=e=>{let{content:s,children:t,width:l="auto",className:a=""}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)("top"),m=(0,d.useRef)(null),u=()=>{if(m.current){let e=m.current.getBoundingClientRect(),s=e.top,t=window.innerHeight-e.bottom;s<300&&t>300?o("bottom"):o("top")}};return(0,c.jsxs)("div",{className:"relative inline-block",ref:m,children:[t||(0,c.jsx)(tL.Z,{className:"ml-1 text-gray-500 cursor-help",onMouseEnter:()=>{u(),i(!0)},onMouseLeave:()=>i(!1)}),r&&(0,c.jsxs)("div",{className:"absolute left-1/2 -translate-x-1/2 z-50 bg-black/90 text-white p-2 rounded-md text-sm font-normal shadow-lg ".concat(a),style:{["top"===n?"bottom":"top"]:"100%",width:l,marginBottom:"top"===n?"8px":"0",marginTop:"bottom"===n?"8px":"0"},children:[s,(0,c.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 w-0 h-0",style:{top:"top"===n?"100%":"auto",bottom:"bottom"===n?"100%":"auto",borderTop:"top"===n?"6px solid rgba(0, 0, 0, 0.9)":"6px solid transparent",borderBottom:"bottom"===n?"6px solid rgba(0, 0, 0, 0.9)":"6px solid transparent",borderLeft:"6px solid transparent",borderRight:"6px solid transparent"}})]})]})};var tP=()=>{let e=A.Z.useFormInstance(),[s,t]=(0,d.useState)(0),l=A.Z.useWatch("model",e)||[],a=Array.isArray(l)?l:[l],r=A.Z.useWatch("custom_model_name",e),i=!a.includes("all-wildcard"),n=A.Z.useWatch("custom_llm_provider",e);if((0,d.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?n===sU.Cl.Azure?{public_name:r,litellm_model:"azure/".concat(r)}:{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),t(e=>e+1)}},[r,a,n,e]),(0,d.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>"custom"===e?"custom"===s.litellm_model||s.litellm_model===r:n===sU.Cl.Azure?s.litellm_model==="azure/".concat(e):s.litellm_model===e))){let s=a.map(e=>"custom"===e&&r?n===sU.Cl.Azure?{public_name:r,litellm_model:"azure/".concat(r)}:{public_name:r,litellm_model:r}:n===sU.Cl.Azure?{public_name:e,litellm_model:"azure/".concat(e)}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),t(e=>e+1)}}},[a,r,n,e]),!i)return null;let o=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mb-2 font-normal",children:"The name you specify in your API calls to LiteLLM Proxy"}),(0,c.jsxs)("div",{className:"mb-2 font-normal",children:[(0,c.jsx)("strong",{children:"Example:"})," If you name your public model ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"example-name"}),", and choose ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"openai/qwen-plus-latest"})," as the LiteLLM model"]}),(0,c.jsxs)("div",{className:"mb-2 font-normal",children:[(0,c.jsx)("strong",{children:"Usage:"})," You make an API call to the LiteLLM proxy with ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:'model = "example-name"'})]}),(0,c.jsxs)("div",{className:"font-normal",children:[(0,c.jsx)("strong",{children:"Result:"})," LiteLLM sends ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"qwen-plus-latest"})," to the provider"]})]}),m=(0,c.jsx)("div",{children:"The model name LiteLLM will send to the LLM API"}),u=[{title:(0,c.jsxs)("span",{className:"flex items-center",children:["Public Model Name",(0,c.jsx)(tT,{content:o,width:"500px"})]}),dataIndex:"public_name",key:"public_name",render:(s,t,l)=>(0,c.jsx)(sW.o,{value:s,onChange:s=>{let t=[...e.getFieldValue("model_mappings")];t[l].public_name=s.target.value,e.setFieldValue("model_mappings",t)}})},{title:(0,c.jsxs)("span",{className:"flex items-center",children:["LiteLLM Model Name",(0,c.jsx)(tT,{content:m,width:"360px"})]}),dataIndex:"litellm_model",key:"litellm_model"}];return(0,c.jsx)(c.Fragment,{children:(0,c.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",rules:[{required:!0,validator:async(e,s)=>{if(!s||0===s.length)throw Error("At least one model mapping is required");if(s.filter(e=>!e.public_name||""===e.public_name.trim()).length>0)throw Error("All model mappings must have valid public names")}}],children:(0,c.jsx)(em.Z,{dataSource:e.getFieldValue("model_mappings"),columns:u,pagination:!1,size:"small"},s)})})},tE=t(90464);let{Link:tM}=en.default;var tO=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:t,teams:l,guardrailsList:a}=e,[r]=A.Z.useForm(),[i,n]=d.useState(!1),[o,m]=d.useState("per_token"),[u,x]=d.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),p=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)(N.Z,{className:"mt-2 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Advanced Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,c.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,c.jsx)(tj.Z,{onChange:e=>{n(e),e||r.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails. Go to 'Guardrails' tab to create new guardrails.",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:a.map(e=>({value:e,label:e}))})}),i&&(0,c.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,c.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,c.jsx)(I.default,{defaultValue:"per_token",onChange:e=>m(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===o?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})})]}):(0,c.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})})]}),(0,c.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,c.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,c.jsx)(tM,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,c.jsx)(tj.Z,{onChange:e=>{let s=r.getFieldValue("litellm_extra_params");try{let t=s?JSON.parse(s):{};e?t.use_in_pass_through=!0:delete t.use_in_pass_through,Object.keys(t).length>0?r.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):r.setFieldValue("litellm_extra_params","")}catch(s){e?r.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):r.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,c.jsx)(tb,{form:r,showCacheControl:u,onCacheControlChange:e=>{if(x(e),!e){let e=r.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?r.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):r.setFieldValue("litellm_extra_params","")}catch(e){r.setFieldValue("litellm_extra_params","")}}}}),(0,c.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:p}],children:(0,c.jsx)(tE.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,c.jsxs)(sK.Z,{className:"mb-4",children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,c.jsx)(tM,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,c.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:p}],children:(0,c.jsx)(tE.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},tD=t(29),tF=t.n(tD),tR=t(23639);let{Text:tz}=en.default;var tU=e=>{let{formValues:s,accessToken:t,testMode:l,modelName:a="this model",onClose:r,onTestComplete:i}=e,[n,o]=d.useState(null),[m,u]=d.useState(null),[x,h]=d.useState(null),[p,g]=d.useState(!0),[f,v]=d.useState(!1),[y,b]=d.useState(!1),_=async()=>{g(!0),b(!1),o(null),u(null),h(null),v(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sq(s,t,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),v(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:i,modelName:n}=a[0],c=await (0,j.testConnectionRequest)(t,r,i,null==i?void 0:i.mode);if("success"===c.status)eo.Z.success("Connection test successful!"),o(null),v(!0);else{var e,l;let s=(null===(e=c.result)||void 0===e?void 0:e.error)||c.message||"Unknown error";o(s),u(r),h(null===(l=c.result)||void 0===l?void 0:l.raw_request_typed_dict),v(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),v(!1)}finally{g(!1),i&&i()}};d.useEffect(()=>{let e=setTimeout(()=>{_()},200);return()=>clearTimeout(e)},[]);let N=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",Z="string"==typeof n?N(n):(null==n?void 0:n.message)?N(n.message):"Unknown error",w=x?((e,s,t)=>{let l=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(t).map(e=>{let[s,t]=e;return"-H '".concat(s,": ").concat(t,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(l,"\n }'")})(x.raw_request_api_base,x.raw_request_body,x.raw_request_headers||{}):"";return(0,c.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,c.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,c.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,c.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,c.jsxs)(tz,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,c.jsx)(tF(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):f?(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"32px 20px"},children:[(0,c.jsx)("div",{style:{color:"#52c41a",fontSize:"24px",display:"flex",alignItems:"center"},children:(0,c.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,c.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,c.jsxs)(tz,{type:"success",style:{fontSize:"18px",fontWeight:500,marginLeft:"10px"},children:["Connection to ",a," successful!"]})]}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,c.jsx)(eg.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,c.jsxs)(tz,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,c.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,c.jsx)(tz,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:Z}),n&&(0,c.jsx)("div",{style:{marginTop:"12px"},children:(0,c.jsx)(P.ZP,{type:"link",onClick:()=>b(!y),style:{paddingLeft:0,height:"auto"},children:y?"Hide Details":"Show Details"})})]}),y&&(0,c.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,c.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof n?n:JSON.stringify(n,null,2)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,c.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,c.jsx)(P.ZP,{style:{marginTop:"8px"},icon:(0,c.jsx)(tR.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),eo.Z.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,c.jsx)(K.Z,{style:{margin:"24px 0 16px"}}),(0,c.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,c.jsx)(P.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,c.jsx)(B.Z,{}),children:"View Documentation"})})]})};let tq=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"},{value:"batch",label:"Batch - /batch"}];var tB=t(92858);let tV=async(e,s,t,l)=>{try{console.log("=== AUTO ROUTER SUBMIT HANDLER CALLED ==="),console.log("handling auto router submit for formValues:",e),console.log("Access token:",s?"Present":"Missing"),console.log("Form:",t?"Present":"Missing"),console.log("Callback:",l?"Present":"Missing");let a={model_name:e.auto_router_name,litellm_params:{model:"auto_router/".concat(e.auto_router_name),auto_router_config:JSON.stringify(e.auto_router_config),auto_router_default_model:e.auto_router_default_model},model_info:{}};e.auto_router_embedding_model&&"custom"!==e.auto_router_embedding_model?a.litellm_params.auto_router_embedding_model=e.auto_router_embedding_model:e.custom_embedding_model&&(a.litellm_params.auto_router_embedding_model=e.custom_embedding_model),e.team_id&&(a.model_info.team_id=e.team_id),e.model_access_group&&e.model_access_group.length>0&&(a.model_info.access_groups=e.model_access_group),console.log("Auto router configuration to be created:",a),console.log("Auto router config (stringified):",a.litellm_params.auto_router_config),console.log("Calling modelCreateCall with:",{accessToken:s?"Present":"Missing",config:a});let r=await (0,j.modelCreateCall)(s,a);console.log("response for auto router create call:",r),t.resetFields()}catch(e){console.error("Failed to add auto router:",e),eo.Z.fromBackend("Failed to add auto router: "+e)}},{Title:tK,Link:tG}=en.default;var tH=e=>{let{form:s,handleOk:t,accessToken:l,userRole:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)([]),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1),[N,Z]=(0,d.useState)(null);(0,d.useEffect)(()=>{(async()=>{h((await (0,j.modelAvailableCall)(l,"","",!1,null,!0,!0)).data.map(e=>e.id))})()},[l]),(0,d.useEffect)(()=>{(async()=>{try{let e=await eU(l);console.log("Fetched models for auto router:",e),g(e)}catch(e){console.error("Error fetching model info for auto router:",e)}})()},[l]);let w=eI.ZL.includes(a),S=async()=>{o(!0),u("test-".concat(Date.now())),i(!0)},C=()=>{console.log("Auto router submit triggered!"),console.log("Router config:",N);let e=s.getFieldsValue();if(console.log("Form values:",e),!e.auto_router_name){eo.Z.fromBackend("Please enter an Auto Router Name");return}if(!e.auto_router_default_model){eo.Z.fromBackend("Please select a Default Model");return}if(s.setFieldsValue({custom_llm_provider:"auto_router",model:e.auto_router_name,api_key:"not_required_for_auto_router"}),!N||!N.routes||0===N.routes.length){eo.Z.fromBackend("Please configure at least one route for the auto router");return}if(N.routes.filter(e=>!e.name||!e.description||0===e.utterances.length).length>0){eo.Z.fromBackend("Please ensure all routes have a target model, description, and at least one utterance");return}s.validateFields().then(e=>{console.log("Form validation passed, submitting with values:",e);let a={...e,auto_router_config:N};console.log("Final submit values:",a),tV(a,l,s,t)}).catch(e=>{console.error("Validation failed:",e);let s=e.errorFields||[];if(s.length>0){let e=s.map(e=>{let s=e.name[0];return({auto_router_name:"Auto Router Name",auto_router_default_model:"Default Model",auto_router_embedding_model:"Embedding Model"})[s]||s});eo.Z.fromBackend("Please fill in the following required fields: ".concat(e.join(", ")))}else eo.Z.fromBackend("Please fill in all required fields")})};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(tK,{level:2,children:"Add Auto Router"}),(0,c.jsx)(k.Z,{className:"text-gray-600 mb-6",children:"Create an auto router with intelligent routing logic that automatically selects the best model based on user input patterns and semantic matching."}),(0,c.jsx)(tN.Z,{children:(0,c.jsxs)(A.Z,{form:s,onFinish:C,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Auto router name is required"}],label:"Auto Router Name",name:"auto_router_name",tooltip:"Unique name for this auto router configuration",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(_.Z,{placeholder:"e.g., auto_router_1, smart_routing"})}),(0,c.jsx)("div",{className:"w-full mb-4",children:(0,c.jsx)(tS,{modelInfo:p,value:N,onChange:e=>{Z(e),s.setFieldValue("auto_router_config",e)}})}),(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Default model is required"}],label:"Default Model",name:"auto_router_default_model",tooltip:"Fallback model to use when auto routing logic cannot determine the best model",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(I.default,{placeholder:"Select a default model",onChange:e=>{v("custom"===e)},options:[...Array.from(new Set(p.map(e=>e.model_group))).map(e=>({value:e,label:e})),{value:"custom",label:"Enter custom model name"}],style:{width:"100%"},showSearch:!0})}),(0,c.jsx)(A.Z.Item,{label:"Embedding Model",name:"auto_router_embedding_model",tooltip:"Optional: Embedding model to use for semantic routing decisions",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(I.default,{value:s.getFieldValue("auto_router_embedding_model"),placeholder:"Select an embedding model (optional)",onChange:e=>{b("custom"===e),s.setFieldValue("auto_router_embedding_model",e)},options:[...Array.from(new Set(p.map(e=>e.model_group))).map(e=>({value:e,label:e})),{value:"custom",label:"Enter custom model name"}],style:{width:"100%"},showSearch:!0,allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Additional Settings"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),w&&(0,c.jsx)(A.Z.Item,{label:"Model Access Group",name:"model_access_group",className:"mb-4",tooltip:"Use model access groups to control who can access this auto router",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:x.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})}),(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(en.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{className:"space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:S,loading:n,children:"Test Connect"}),(0,c.jsx)(P.ZP,{onClick:()=>{console.log("Add Auto Router button clicked!"),console.log("Current router config:",N),console.log("Current form values:",s.getFieldsValue()),C()},children:"Add Auto Router"})]})]})]})}),(0,c.jsx)(L.Z,{title:"Connection Test Results",open:r,onCancel:()=>{i(!1),o(!1)},footer:[(0,c.jsx)(P.ZP,{onClick:()=>{i(!1),o(!1)},children:"Close"},"close")],width:700,children:r&&(0,c.jsx)(tU,{formValues:s.getFieldsValue(),accessToken:l,testMode:"chat",modelName:s.getFieldValue("auto_router_name"),onClose:()=>{i(!1),o(!1)},onTestComplete:()=>o(!1)},m)})]})};let{Title:tJ,Link:tY}=en.default;var tW=e=>{let{form:s,handleOk:t,selectedProvider:l,setSelectedProvider:a,providerModels:r,setProviderModelsFn:i,getPlaceholder:n,uploadProps:o,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:x,credentials:h,accessToken:p,userRole:g,premiumUser:f}=e,[v]=A.Z.useForm(),[y,b]=(0,d.useState)("chat"),[_,N]=(0,d.useState)(!1),[Z,w]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[T,E]=(0,d.useState)("");(0,d.useEffect)(()=>{(async()=>{try{let e=(await (0,j.getGuardrailsList)(p)).guardrails.map(e=>e.guardrail_name);C(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[p]);let M=async()=>{w(!0),E("test-".concat(Date.now())),N(!0)},[O,D]=(0,d.useState)(!1),[F,R]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{R((await (0,j.modelAvailableCall)(p,"","",!1,null,!0,!0)).data.map(e=>e.id))})()},[p]);let z=eI.ZL.includes(g);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(e1.Z,{className:"w-full",children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Add Model"}),(0,c.jsx)(e0.Z,{children:"Add Auto Router"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(tJ,{level:2,children:"Add Model"}),(0,c.jsx)(tN.Z,{children:(0,c.jsx)(A.Z,{form:s,onFinish:e=>{console.log("\uD83D\uDD25 Form onFinish triggered with values:",e),t()},onFinishFailed:e=>{console.log("\uD83D\uDCA5 Form onFinishFailed triggered:",e)},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(I.default,{showSearch:!0,value:l,onChange:e=>{a(e),i(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(tA,{selectedProvider:l,providerModels:r,getPlaceholder:n}),(0,c.jsx)(tP,{}),(0,c.jsx)(A.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,c.jsx)(I.default,{style:{width:"100%"},value:y,onChange:e=>b(e),options:tq})}),(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"mb-5 mt-1",children:[(0,c.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,c.jsx)(tY,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(en.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,c.jsx)(A.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...h.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,t=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",t),t)?(0,c.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,c.jsx)(sY,{selectedProvider:l,uploadProps:o})}}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Additional Model Info Settings"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{label:"Team-BYOK Model",tooltip:"Only use this model + credential combination for this team. Useful when teams want to onboard their own OpenAI keys.",className:"mb-4",children:(0,c.jsx)(V.Z,{title:f?"":"This is an enterprise-only feature. Upgrade to premium to restrict model+credential combinations to a specific team.",placement:"top",children:(0,c.jsx)(tB.Z,{checked:O,onChange:e=>{D(e),e||s.setFieldValue("team_id",void 0)},disabled:!f})})}),O&&(0,c.jsx)(A.Z.Item,{label:"Select Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team will be able to call this model.",rules:[{required:O&&!z,message:"Please select a team."}],children:(0,c.jsx)(q,{teams:x,disabled:!f})}),z&&(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(A.Z.Item,{label:"Model Access Group",name:"model_access_group",className:"mb-4",tooltip:"Use model access groups to give users access to select models, and add new ones to the group over time.",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:F.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})})}),(0,c.jsx)(tO,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:x,guardrailsList:S}),(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(en.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{className:"space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:M,loading:Z,children:"Test Connect"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(tH,{form:v,handleOk:()=>{v.validateFields().then(e=>{tV(e,p,v,t)}).catch(e=>{console.error("Validation failed:",e)})},accessToken:p,userRole:g})})]})]}),(0,c.jsx)(L.Z,{title:"Connection Test Results",open:_,onCancel:()=>{N(!1),w(!1)},footer:[(0,c.jsx)(P.ZP,{onClick:()=>{N(!1),w(!1)},children:"Close"},"close")],width:700,children:_&&(0,c.jsx)(tU,{formValues:s.getFieldsValue(),accessToken:p,testMode:y,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{N(!1),w(!1)},onTestComplete:()=>w(!1)},T)})]})},t$=t(8048);let tQ=(e,s,t,l,a,r,i,n,o,d,m)=>[{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model ID"}),accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.model_info.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>l(t.model_info.id),children:t.model_info.id})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model Information"}),accessorKey:"model_name",size:250,cell:e=>{let{row:s}=e,t=s.original,l=r(s.original)||"-",a=(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"Provider:"})," ",t.provider||"-"]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"Public Model Name:"})," ",l]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"LiteLLM Model Name:"})," ",t.litellm_model_name||"-"]})]});return(0,c.jsx)(V.Z,{title:a,children:(0,c.jsxs)("div",{className:"flex items-start space-x-2 min-w-0 w-full max-w-[250px]",children:[(0,c.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:t.provider?(0,c.jsx)("img",{src:(0,sU.dr)(t.provider).logo,alt:"".concat(t.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(e,s)}}}):(0,c.jsx)("div",{className:"w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",children:"-"})}),(0,c.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,c.jsx)("div",{className:"text-xs font-medium text-gray-900 truncate max-w-[210px]",children:l}),(0,c.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5 max-w-[210px]",children:t.litellm_model_name||"-"})]})]})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Credentials"}),accessorKey:"litellm_credential_name",size:180,cell:e=>{var s;let{row:t}=e,l=null===(s=t.original.litellm_params)||void 0===s?void 0:s.litellm_credential_name;return l?(0,c.jsx)(V.Z,{title:"Credential: ".concat(l),children:(0,c.jsxs)("div",{className:"flex items-center space-x-2 max-w-[180px]",children:[(0,c.jsx)(tx.Z,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),(0,c.jsx)("span",{className:"text-xs truncate",title:l,children:l})]})}):(0,c.jsxs)("div",{className:"flex items-center space-x-2 max-w-[180px]",children:[(0,c.jsx)(tx.Z,{className:"w-4 h-4 text-gray-300 flex-shrink-0"}),(0,c.jsx)("span",{className:"text-xs text-gray-400",children:"No credentials"})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Created By"}),accessorKey:"model_info.created_by",sortingFn:"datetime",size:160,cell:e=>{let{row:s}=e,t=s.original,l=t.model_info.created_by,a=t.model_info.created_at?new Date(t.model_info.created_at).toLocaleDateString():null;return(0,c.jsxs)("div",{className:"flex flex-col min-w-0 max-w-[160px]",children:[(0,c.jsx)("div",{className:"text-xs font-medium text-gray-900 truncate",title:l||"Unknown",children:l||"Unknown"}),(0,c.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",title:a||"Unknown date",children:a||"Unknown date"})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Updated At"}),accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.model_info.updated_at?new Date(t.model_info.updated_at).toLocaleDateString():"-"})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Costs"}),accessorKey:"input_cost",size:120,cell:e=>{let{row:s}=e,t=s.original,l=t.input_cost,a=t.output_cost;return l||a?(0,c.jsx)(V.Z,{title:"Cost per 1M tokens",children:(0,c.jsxs)("div",{className:"flex flex-col min-w-0 max-w-[120px]",children:[l&&(0,c.jsxs)("div",{className:"text-xs font-medium text-gray-900 truncate",children:["In: $",l]}),a&&(0,c.jsxs)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:["Out: $",a]})]})}):(0,c.jsx)("div",{className:"max-w-[120px]",children:(0,c.jsx)("span",{className:"text-xs text-gray-400",children:"-"})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Team ID"}),accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,t=s.original;return t.model_info.team_id?(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:t.model_info.team_id,children:(0,c.jsxs)(b.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:()=>a(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model Access Group"}),accessorKey:"model_info.model_access_group",enableSorting:!1,cell:e=>{let{row:s}=e,t=s.original,l=t.model_info.access_groups;if(!l||0===l.length)return"-";let a=t.model_info.id,r=d.has(a),i=l.length>1,n=()=>{let e=new Set(d);r?e.delete(a):e.add(a),m(e)};return(0,c.jsxs)("div",{className:"flex items-center gap-1 overflow-hidden",children:[(0,c.jsx)(eX.Z,{size:"xs",color:"blue",className:"text-xs px-1.5 py-0.5 h-5 leading-tight flex-shrink-0",children:l[0]}),(r||!i&&2===l.length)&&l.slice(1).map((e,s)=>(0,c.jsx)(eX.Z,{size:"xs",color:"blue",className:"text-xs px-1.5 py-0.5 h-5 leading-tight flex-shrink-0",children:e},s+1)),i&&(0,c.jsx)("button",{onClick:e=>{e.stopPropagation(),n()},className:"text-xs text-blue-600 hover:text-blue-800 px-1 py-0.5 rounded hover:bg-blue-50 h-5 leading-tight flex-shrink-0 whitespace-nowrap",children:r?"−":"+".concat(l.length-1)})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Status"}),accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(t.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:t.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:t=>{var a;let{row:r}=t,i=r.original,n="Admin"===e||(null===(a=i.model_info)||void 0===a?void 0:a.created_by)===s;return(0,c.jsx)("div",{className:"flex items-center justify-end gap-2 pr-4",children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>{n&&(l(i.model_info.id),o(!1))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"})})}}];var tX=t(93142),t0=t(867),t1=t(3810),t2=t(5540),t4=t(8881);let{Text:t5}=en.default;var t6=e=>{let{accessToken:s,onReloadSuccess:t,buttonText:l="Reload Price Data",showIcon:a=!0,size:r="middle",type:i="primary",className:n=""}=e,[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)(6),[b,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(!1);(0,d.useEffect)(()=>{w();let e=setInterval(()=>{w()},3e4);return()=>clearInterval(e)},[s]);let w=async()=>{if(s){Z(!0);try{console.log("Fetching reload status...");let e=await (0,j.getModelCostMapReloadStatus)(s);console.log("Received status:",e),_(e)}catch(e){console.error("Failed to fetch reload status:",e),_({scheduled:!1,interval_hours:null,last_run:null,next_run:null})}finally{Z(!1)}}},k=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}m(!0);try{let e=await (0,j.reloadModelCostMap)(s);"success"===e.status?(eo.Z.success("Price data reloaded successfully! ".concat(e.models_count||0," models updated.")),null==t||t(),await w()):eo.Z.fromBackend("Failed to reload price data")}catch(e){console.error("Error reloading price data:",e),eo.Z.fromBackend("Failed to reload price data. Please try again.")}finally{m(!1)}},S=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}if(v<=0){eo.Z.fromBackend("Hours must be greater than 0");return}x(!0);try{let e=await (0,j.scheduleModelCostMapReload)(s,v);"success"===e.status?(eo.Z.success("Periodic reload scheduled for every ".concat(v," hours")),f(!1),await w()):eo.Z.fromBackend("Failed to schedule periodic reload")}catch(e){console.error("Error scheduling reload:",e),eo.Z.fromBackend("Failed to schedule periodic reload. Please try again.")}finally{x(!1)}},C=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}p(!0);try{let e=await (0,j.cancelModelCostMapReload)(s);"success"===e.status?(eo.Z.success("Periodic reload cancelled successfully"),await w()):eo.Z.fromBackend("Failed to cancel periodic reload")}catch(e){console.error("Error cancelling reload:",e),eo.Z.fromBackend("Failed to cancel periodic reload. Please try again.")}finally{p(!1)}},I=e=>{if(!e)return"Never";try{return new Date(e).toLocaleString()}catch(s){return e}};return(0,c.jsxs)("div",{className:n,children:[(0,c.jsxs)(tX.Z,{direction:"horizontal",size:"middle",style:{marginBottom:16},children:[(0,c.jsx)(t0.Z,{title:"Hard Refresh Price Data",description:"This will immediately fetch the latest pricing information from the remote source. Continue?",onConfirm:k,okText:"Yes",cancelText:"No",okButtonProps:{style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem",transition:"all 0.2s ease-in-out"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#4f46e5"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1"}},children:(0,c.jsx)(P.ZP,{type:i,size:r,loading:o,icon:a?(0,c.jsx)(tl.Z,{}):void 0,style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem",transition:"all 0.2s ease-in-out"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#4f46e5"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1"},children:l})}),(null==b?void 0:b.scheduled)?(0,c.jsx)(P.ZP,{type:"default",size:r,danger:!0,icon:(0,c.jsx)(t4.Z,{}),loading:h,onClick:C,style:{borderColor:"#ff4d4f",color:"#ff4d4f",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem"},children:"Cancel Periodic Reload"}):(0,c.jsx)(P.ZP,{type:"default",size:r,icon:(0,c.jsx)(t2.Z,{}),onClick:()=>f(!0),style:{borderColor:"#d9d9d9",color:"#6366f1",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem"},children:"Set Up Periodic Reload"})]}),b&&(0,c.jsx)(tN.Z,{size:"small",style:{backgroundColor:"#f8f9fa",border:"1px solid #e9ecef",borderRadius:8},children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"small",style:{width:"100%"},children:[b.scheduled?(0,c.jsx)("div",{children:(0,c.jsxs)(t1.Z,{color:"green",icon:(0,c.jsx)(t2.Z,{}),children:["Scheduled every ",b.interval_hours," hours"]})}):(0,c.jsx)(t5,{type:"secondary",children:"No periodic reload scheduled"}),(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Last run:"}),(0,c.jsx)(t5,{style:{fontSize:"12px"},children:I(b.last_run)})]}),b.scheduled&&(0,c.jsxs)(c.Fragment,{children:[b.next_run&&(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Next run:"}),(0,c.jsx)(t5,{style:{fontSize:"12px"},children:I(b.next_run)})]}),(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Status:"}),(0,c.jsx)(t1.Z,{color:(null==b?void 0:b.scheduled)?b.last_run?"success":"processing":"default",children:(null==b?void 0:b.scheduled)?b.last_run?"Active":"Ready":"Not scheduled"})]})]})]})}),(0,c.jsxs)(L.Z,{title:"Set Up Periodic Reload",open:g,onOk:S,onCancel:()=>f(!1),confirmLoading:u,okText:"Schedule",cancelText:"Cancel",okButtonProps:{style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white"}},children:[(0,c.jsx)("div",{style:{marginBottom:16},children:(0,c.jsx)(t5,{children:"Set up automatic reload of price data every:"})}),(0,c.jsx)("div",{style:{marginBottom:16},children:(0,c.jsx)(eW.Z,{min:1,max:168,value:v,onChange:e=>y(e||6),addonAfter:"hours",style:{width:"100%"}})}),(0,c.jsx)("div",{children:(0,c.jsxs)(t5,{type:"secondary",children:["This will automatically fetch the latest pricing data from the remote source every ",v," hours."]})})]})]})},t3=t(15731),t8=t(91126);let t7=(e,s,t,l,a,r,i,n,o,d,m)=>[{header:()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(ts.Z,{checked:t,indeterminate:s.length>0&&!t,onChange:e=>a(e.target.checked),onClick:e=>e.stopPropagation()}),(0,c.jsx)("span",{children:"Model ID"})]}),accessorKey:"model_info.id",enableSorting:!0,sortingFn:"alphanumeric",cell:e=>{let{row:t}=e,a=t.original,r=a.model_name,i=s.includes(r);return(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(ts.Z,{checked:i,onChange:e=>l(r,e.target.checked),onClick:e=>e.stopPropagation()}),(0,c.jsx)(V.Z,{title:a.model_info.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>m&&m(a.model_info.id),children:a.model_info.id})})]})}},{header:"Model Name",accessorKey:"model_name",enableSorting:!0,sortingFn:"alphanumeric",cell:e=>{let{row:s}=e,t=s.original,l=n(t)||t.model_name;return(0,c.jsx)("div",{className:"font-medium text-sm",children:(0,c.jsx)(V.Z,{title:l,children:(0,c.jsx)("div",{className:"truncate max-w-[200px]",children:l})})})}},{header:"Health Status",accessorKey:"health_status",enableSorting:!0,sortingFn:(e,s,t)=>{var l,a;let r=e.getValue("health_status")||"unknown",i=s.getValue("health_status")||"unknown",n={healthy:0,checking:1,unknown:2,unhealthy:3};return(null!==(l=n[r])&&void 0!==l?l:4)-(null!==(a=n[i])&&void 0!==a?a:4)},cell:s=>{var t;let{row:l}=s,a=l.original,r={status:a.health_status,loading:a.health_loading,error:a.health_error};if(r.loading)return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse"}),(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse",style:{animationDelay:"0.2s"}}),(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse",style:{animationDelay:"0.4s"}})]}),(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:"Checking..."})]});let n=a.model_name,o="healthy"===r.status&&(null===(t=e[n])||void 0===t?void 0:t.successResponse);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[i(r.status),o&&d&&(0,c.jsx)(V.Z,{title:"View response details",placement:"top",children:(0,c.jsx)("button",{onClick:()=>{var s;return d(n,null===(s=e[n])||void 0===s?void 0:s.successResponse)},className:"p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded cursor-pointer transition-colors",children:(0,c.jsx)(t3.Z,{className:"h-4 w-4"})})})]})}},{header:"Error Details",accessorKey:"health_error",enableSorting:!1,cell:s=>{let{row:t}=s,l=t.original.model_name,a=e[l];if(!(null==a?void 0:a.error))return(0,c.jsx)(k.Z,{className:"text-gray-400 text-sm",children:"No errors"});let r=a.error,i=a.fullError||a.error;return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"max-w-[200px]",children:(0,c.jsx)(V.Z,{title:r,placement:"top",children:(0,c.jsx)(k.Z,{className:"text-red-600 text-sm truncate",children:r})})}),o&&i!==r&&(0,c.jsx)(V.Z,{title:"View full error details",placement:"top",children:(0,c.jsx)("button",{onClick:()=>o(l,r,i),className:"p-1 text-red-600 hover:text-red-800 hover:bg-red-50 rounded cursor-pointer transition-colors",children:(0,c.jsx)(t3.Z,{className:"h-4 w-4"})})})]})}},{header:"Last Check",accessorKey:"last_check",enableSorting:!0,sortingFn:(e,s,t)=>{let l=e.getValue("last_check")||"Never checked",a=s.getValue("last_check")||"Never checked";if("Never checked"===l&&"Never checked"===a)return 0;if("Never checked"===l)return 1;if("Never checked"===a)return -1;if("Check in progress..."===l&&"Check in progress..."===a)return 0;if("Check in progress..."===l)return -1;if("Check in progress..."===a)return 1;let r=new Date(l),i=new Date(a);return isNaN(r.getTime())&&isNaN(i.getTime())?0:isNaN(r.getTime())?1:isNaN(i.getTime())?-1:i.getTime()-r.getTime()},cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:t.health_loading?"Check in progress...":t.last_check})}},{header:"Last Success",accessorKey:"last_success",enableSorting:!0,sortingFn:(e,s,t)=>{let l=e.getValue("last_success")||"Never succeeded",a=s.getValue("last_success")||"Never succeeded";if("Never succeeded"===l&&"Never succeeded"===a)return 0;if("Never succeeded"===l)return 1;if("Never succeeded"===a)return -1;if("None"===l&&"None"===a)return 0;if("None"===l)return 1;if("None"===a)return -1;let r=new Date(l),i=new Date(a);return isNaN(r.getTime())&&isNaN(i.getTime())?0:isNaN(r.getTime())?1:isNaN(i.getTime())?-1:i.getTime()-r.getTime()},cell:s=>{let{row:t}=s,l=e[t.original.model_name],a=(null==l?void 0:l.lastSuccess)||"None";return(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:a})}},{header:"Actions",id:"actions",cell:e=>{let{row:s}=e,t=s.original,l=t.model_name,a=t.health_status&&"none"!==t.health_status,i=t.health_loading?"Checking...":a?"Re-run Health Check":"Run Health Check";return(0,c.jsx)(V.Z,{title:i,placement:"top",children:(0,c.jsx)("button",{className:"p-2 rounded-md transition-colors ".concat(t.health_loading?"text-gray-400 cursor-not-allowed bg-gray-100":"text-indigo-600 hover:text-indigo-700 hover:bg-indigo-50"),onClick:()=>{t.health_loading||r(l)},disabled:t.health_loading,children:t.health_loading?(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse"}),(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"0.2s"}}),(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"0.4s"}})]}):a?(0,c.jsx)(e3.Z,{className:"h-4 w-4"}):(0,c.jsx)(t8.Z,{className:"h-4 w-4"})})})},enableSorting:!1}],t9=[{pattern:/Missing .* API Key/i,replacement:"Missing API Key"},{pattern:/Connection timeout/i,replacement:"Connection timeout"},{pattern:/Network.*not.*ok/i,replacement:"Network connection failed"},{pattern:/403.*Forbidden/i,replacement:"Access forbidden - check API key permissions"},{pattern:/401.*Unauthorized/i,replacement:"Unauthorized - invalid API key"},{pattern:/429.*rate limit/i,replacement:"Rate limit exceeded"},{pattern:/500.*Internal Server Error/i,replacement:"Provider internal server error"},{pattern:/litellm\.AuthenticationError/i,replacement:"Authentication failed"},{pattern:/litellm\.RateLimitError/i,replacement:"Rate limit exceeded"},{pattern:/litellm\.APIError/i,replacement:"API error"}];var le=e=>{let{accessToken:s,modelData:t,all_models_on_proxy:l,getDisplayModelName:a,setSelectedModelId:r}=e,[i,n]=(0,d.useState)({}),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(null),[v,y]=(0,d.useState)(!1),[_,N]=(0,d.useState)(null),Z=(0,d.useRef)(null);(0,d.useEffect)(()=>{s&&(null==t?void 0:t.data)&&(async()=>{let e={};t.data.forEach(s=>{e[s.model_name]={status:"none",lastCheck:"None",lastSuccess:"None",loading:!1,error:void 0,fullError:void 0,successResponse:void 0}});try{let l=await (0,j.latestHealthChecksCall)(s);l&&l.latest_health_checks&&"object"==typeof l.latest_health_checks&&Object.entries(l.latest_health_checks).forEach(s=>{let[l,a]=s;if(!a)return;let r=null,i=t.data.find(e=>e.model_name===l);if(i)r=i.model_name;else{let e=t.data.find(e=>e.model_info&&e.model_info.id===l);if(e)r=e.model_name;else if(a.model_name){let e=t.data.find(e=>e.model_name===a.model_name);e&&(r=e.model_name)}}if(r){let s=a.error_message||void 0;e[r]={status:a.status||"unknown",lastCheck:a.checked_at?new Date(a.checked_at).toLocaleString():"None",lastSuccess:"healthy"===a.status&&a.checked_at?new Date(a.checked_at).toLocaleString():"None",loading:!1,error:s?w(s):void 0,fullError:s,successResponse:"healthy"===a.status?a:void 0}}})}catch(e){console.warn("Failed to load health check history (using default states):",e)}n(e)})()},[s,t]);let w=e=>{var s;if(!e)return"Health check failed";let t="string"==typeof e?e:JSON.stringify(e),l=t.match(/(\w+Error):\s*(\d{3})/i);if(l)return"".concat(l[1],": ").concat(l[2]);let a=t.match(/(AuthenticationError|RateLimitError|BadRequestError|InternalServerError|TimeoutError|NotFoundError|ForbiddenError|ServiceUnavailableError|BadGatewayError|ContentPolicyViolationError|\w+Error)/i),r=t.match(/\b(400|401|403|404|408|429|500|502|503|504)\b/);if(a&&r)return"".concat(a[1],": ").concat(r[1]);if(r){let e=r[1];return"".concat({400:"BadRequestError",401:"AuthenticationError",403:"ForbiddenError",404:"NotFoundError",408:"TimeoutError",429:"RateLimitError",500:"InternalServerError",502:"BadGatewayError",503:"ServiceUnavailableError",504:"GatewayTimeoutError"}[e],": ").concat(e)}if(a){let e=a[1],s={AuthenticationError:"401",RateLimitError:"429",BadRequestError:"400",InternalServerError:"500",TimeoutError:"408",NotFoundError:"404",ForbiddenError:"403",ServiceUnavailableError:"503",BadGatewayError:"502",GatewayTimeoutError:"504",ContentPolicyViolationError:"400"}[e];return s?"".concat(e,": ").concat(s):e}for(let{pattern:e,replacement:s}of t9)if(e.test(t))return s;if(/missing.*api.*key|invalid.*key|unauthorized/i.test(t))return"AuthenticationError: 401";if(/rate.*limit|too.*many.*requests/i.test(t))return"RateLimitError: 429";if(/timeout|timed.*out/i.test(t))return"TimeoutError: 408";if(/not.*found/i.test(t))return"NotFoundError: 404";if(/forbidden|access.*denied/i.test(t))return"ForbiddenError: 403";if(/internal.*server.*error/i.test(t))return"InternalServerError: 500";let i=t.replace(/[\n\r]+/g," ").replace(/\s+/g," ").trim(),n=null===(s=i.split(/[.!?]/)[0])||void 0===s?void 0:s.trim();return n&&n.length>0?n.length>100?n.substring(0,97)+"...":n:i.length>100?i.substring(0,97)+"...":i},C=async e=>{if(s){n(s=>({...s,[e]:{...s[e],loading:!0,status:"checking"}}));try{var l,a;let r=await (0,j.individualModelHealthCheckCall)(s,e),i=new Date().toLocaleString();if(r.unhealthy_count>0&&r.unhealthy_endpoints&&r.unhealthy_endpoints.length>0){let s=(null===(l=r.unhealthy_endpoints[0])||void 0===l?void 0:l.error)||"Health check failed",t=w(s);n(l=>{var a;return{...l,[e]:{status:"unhealthy",lastCheck:i,lastSuccess:(null===(a=l[e])||void 0===a?void 0:a.lastSuccess)||"None",loading:!1,error:t,fullError:s}}})}else n(s=>({...s,[e]:{status:"healthy",lastCheck:i,lastSuccess:i,loading:!1,successResponse:r}}));try{let l=await (0,j.latestHealthChecksCall)(s),r=t.data.find(s=>s.model_name===e);if(r){let s=r.model_info.id,t=null===(a=l.latest_health_checks)||void 0===a?void 0:a[s];if(t){let s=t.error_message||void 0;n(l=>{var a,r,i,n,o,c,d;return{...l,[e]:{status:t.status||(null===(a=l[e])||void 0===a?void 0:a.status)||"unknown",lastCheck:t.checked_at?new Date(t.checked_at).toLocaleString():(null===(r=l[e])||void 0===r?void 0:r.lastCheck)||"None",lastSuccess:"healthy"===t.status?t.checked_at?new Date(t.checked_at).toLocaleString():(null===(i=l[e])||void 0===i?void 0:i.lastSuccess)||"None":(null===(n=l[e])||void 0===n?void 0:n.lastSuccess)||"None",loading:!1,error:s?w(s):null===(o=l[e])||void 0===o?void 0:o.error,fullError:s||(null===(c=l[e])||void 0===c?void 0:c.fullError),successResponse:"healthy"===t.status?t:null===(d=l[e])||void 0===d?void 0:d.successResponse}}})}}}catch(e){console.debug("Could not fetch updated status from database (non-critical):",e)}}catch(a){let s=new Date().toLocaleString(),t=a instanceof Error?a.message:String(a),l=w(t);n(a=>{var r;return{...a,[e]:{status:"unhealthy",lastCheck:s,lastSuccess:(null===(r=a[e])||void 0===r?void 0:r.lastSuccess)||"None",loading:!1,error:l,fullError:t}}})}}},I=async()=>{let e=o.length>0?o:l,a=e.reduce((e,s)=>(e[s]={...i[s],loading:!0,status:"checking"},e),{});n(e=>({...e,...a}));let r={},c=e.map(async e=>{if(s)try{let l=await (0,j.individualModelHealthCheckCall)(s,e);r[e]=l;let a=new Date().toLocaleString();if(l.unhealthy_count>0&&l.unhealthy_endpoints&&l.unhealthy_endpoints.length>0){var t;let s=(null===(t=l.unhealthy_endpoints[0])||void 0===t?void 0:t.error)||"Health check failed",r=w(s);n(t=>{var l;return{...t,[e]:{status:"unhealthy",lastCheck:a,lastSuccess:(null===(l=t[e])||void 0===l?void 0:l.lastSuccess)||"None",loading:!1,error:r,fullError:s}}})}else n(s=>({...s,[e]:{status:"healthy",lastCheck:a,lastSuccess:a,loading:!1,successResponse:l}}))}catch(a){console.error("Health check failed for ".concat(e,":"),a);let s=new Date().toLocaleString(),t=a instanceof Error?a.message:String(a),l=w(t);n(a=>{var r;return{...a,[e]:{status:"unhealthy",lastCheck:s,lastSuccess:(null===(r=a[e])||void 0===r?void 0:r.lastSuccess)||"None",loading:!1,error:l,fullError:t}}})}});await Promise.allSettled(c);try{if(!s)return;let l=await (0,j.latestHealthChecksCall)(s);l.latest_health_checks&&Object.entries(l.latest_health_checks).forEach(s=>{let[l,a]=s,r=t.data.find(e=>e.model_info.id===l);if(r&&e.includes(r.model_name)&&a){let e=r.model_name,s=a.error_message||void 0;n(t=>{let l=t[e];return{...t,[e]:{status:a.status||(null==l?void 0:l.status)||"unknown",lastCheck:a.checked_at?new Date(a.checked_at).toLocaleString():(null==l?void 0:l.lastCheck)||"None",lastSuccess:"healthy"===a.status&&a.checked_at?new Date(a.checked_at).toLocaleString():(null==l?void 0:l.lastSuccess)||"None",loading:!1,error:s?w(s):null==l?void 0:l.error,fullError:s||(null==l?void 0:l.fullError),successResponse:"healthy"===a.status?a:null==l?void 0:l.successResponse}}})}})}catch(e){console.warn("Failed to fetch updated health statuses from database (non-critical):",e)}},A=e=>{x(e),e?m(l):m([])},T=()=>{p(!1),f(null)},E=()=>{y(!1),N(null)};return(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"mb-6",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Model Health Status"}),(0,c.jsx)(k.Z,{className:"text-gray-600 mt-1",children:"Run health checks on individual models to verify they are working correctly"})]}),(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[o.length>0&&(0,c.jsx)(b.Z,{size:"sm",variant:"light",onClick:()=>A(!1),className:"px-3 py-1 text-sm",children:"Clear Selection"}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:I,disabled:Object.values(i).some(e=>e.loading),className:"px-3 py-1 text-sm",children:o.length>0&&o.length{s?m(s=>[...s,e]):(m(s=>s.filter(s=>s!==e)),x(!1))},A,C,e=>{switch(e){case"healthy":return(0,c.jsx)(eX.Z,{color:"emerald",children:"healthy"});case"unhealthy":return(0,c.jsx)(eX.Z,{color:"red",children:"unhealthy"});case"checking":return(0,c.jsx)(eX.Z,{color:"blue",children:"checking"});case"none":return(0,c.jsx)(eX.Z,{color:"gray",children:"none"});default:return(0,c.jsx)(eX.Z,{color:"gray",children:"unknown"})}},a,(e,s,t)=>{f({modelName:e,cleanedError:s,fullError:t}),p(!0)},(e,s)=>{N({modelName:e,response:s}),y(!0)},r),data:t.data.map(e=>{let s=i[e.model_name]||{status:"none",lastCheck:"None",loading:!1};return{model_name:e.model_name,model_info:e.model_info,provider:e.provider,litellm_model_name:e.litellm_model_name,health_status:s.status,last_check:s.lastCheck,last_success:s.lastSuccess||"None",health_loading:s.loading,health_error:s.error,health_full_error:s.fullError}}),isLoading:!1,table:Z})}),(0,c.jsx)(L.Z,{title:g?"Health Check Error - ".concat(g.modelName):"Error Details",open:h,onCancel:T,footer:[(0,c.jsx)(P.ZP,{onClick:T,children:"Close"},"close")],width:800,children:g&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Error:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-red-50 border border-red-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-red-800",children:g.cleanedError})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Full Error Details:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md max-h-96 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:g.fullError})})]})]})}),(0,c.jsx)(L.Z,{title:_?"Health Check Response - ".concat(_.modelName):"Response Details",open:v,onCancel:E,footer:[(0,c.jsx)(P.ZP,{onClick:E,children:"Close"},"close")],width:800,children:_&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Status:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-green-50 border border-green-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-green-800",children:"Health check passed successfully"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Response Details:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md max-h-96 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:JSON.stringify(_.response,null,2)})})]})]})})]})},ls=t(61778),lt=t(12660),ll=e=>{let{value:s={},onChange:t}=e,[l,a]=(0,d.useState)(Object.entries(s)),r=e=>{let s=l.filter((s,t)=>t!==e);a(s),null==t||t(Object.fromEntries(s))},i=(e,s,r)=>{let i=[...l];i[e]=[s,r],a(i),null==t||t(Object.fromEntries(i))};return(0,c.jsxs)("div",{children:[l.map((e,s)=>{let[t,l]=e;return(0,c.jsxs)(tX.Z,{style:{display:"flex",marginBottom:8},align:"center",children:[(0,c.jsx)(sW.o,{placeholder:"Header Name",value:t,onChange:e=>i(s,e.target.value,l)}),(0,c.jsx)(sW.o,{placeholder:"Header Value",value:l,onChange:e=>i(s,t,e.target.value)}),(0,c.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%"},children:(0,c.jsx)(tf.Z,{onClick:()=>r(s),style:{cursor:"pointer"}})})]},s)}),(0,c.jsx)(P.ZP,{type:"dashed",onClick:()=>{a([...l,["",""]])},icon:(0,c.jsx)(tv.Z,{}),children:"Add Header"})]})},la=t(77565),lr=e=>{let{pathValue:s,targetValue:t,includeSubpath:l}=e,a=(0,j.getProxyBaseUrl)();return s&&t?(0,c.jsxs)(G.Z,{className:"p-5",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Route Preview"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-5",children:"How your requests will be routed"}),(0,c.jsxs)("div",{className:"space-y-5",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-semibold text-gray-900 mb-3",children:"Basic routing:"}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Your endpoint"}),(0,c.jsx)("code",{className:"font-mono text-sm text-gray-900",children:s?"".concat(a).concat(s):""})]}),(0,c.jsx)("div",{className:"text-gray-400",children:(0,c.jsx)(la.Z,{className:"text-lg"})}),(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Forwards to"}),(0,c.jsx)("code",{className:"font-mono text-sm text-gray-900",children:t})]})]})]}),l&&(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-semibold text-gray-900 mb-3",children:"With subpaths:"}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Your endpoint + subpath"}),(0,c.jsxs)("code",{className:"font-mono text-sm text-gray-900",children:[s&&"".concat(a).concat(s),(0,c.jsx)("span",{className:"text-blue-600",children:"/v1/text-to-image/base/model"})]})]}),(0,c.jsx)("div",{className:"text-gray-400",children:(0,c.jsx)(la.Z,{className:"text-lg"})}),(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Forwards to"}),(0,c.jsxs)("code",{className:"font-mono text-sm text-gray-900",children:[t,(0,c.jsx)("span",{className:"text-blue-600",children:"/v1/text-to-image/base/model"})]})]})]}),(0,c.jsxs)("div",{className:"mt-3 text-sm text-gray-600",children:["Any path after ",s," will be appended to the target URL"]})]})}),!l&&(0,c.jsx)("div",{className:"mt-4 p-3 bg-blue-50 rounded-md border border-blue-200",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(B.Z,{className:"text-blue-500 mt-0.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{className:"text-sm text-blue-700",children:[(0,c.jsx)("span",{className:"font-medium",children:"Not seeing the routing you wanted?"})," Try enabling - Include Subpaths - above - this allows subroutes like ",(0,c.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded font-mono text-xs",children:"/api/v1/models"})," to be forwarded automatically."]})]})})]})]}):null};let{Option:li}=I.default;var ln=e=>{let{accessToken:s,setPassThroughItems:t,passThroughItems:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)(""),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(!0),y=()=>{a.resetFields(),h(""),g(""),v(!0),i(!1)},N=e=>{let s=e;e&&!e.startsWith("/")&&(s="/"+e),h(s),a.setFieldsValue({path:s})},Z=async e=>{console.log("addPassThrough called with:",e),o(!0);try{console.log("formValues: ".concat(JSON.stringify(e)));let r=(await (0,j.createPassThroughEndpoint)(s,e)).endpoints[0],n=[...l,r];t(n),eo.Z.success("Pass-through endpoint created successfully"),a.resetFields(),h(""),g(""),v(!0),i(!1)}catch(e){eo.Z.fromBackend("Error creating pass-through endpoint: "+e)}finally{o(!1)}};return(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{className:"mx-auto mb-4 mt-4",onClick:()=>i(!0),children:"+ Add Pass-Through Endpoint"}),(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:[(0,c.jsx)(lt.Z,{className:"text-xl text-blue-500"}),(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Pass-Through Endpoint"})]}),open:r,width:1e3,onCancel:y,footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsxs)("div",{className:"mt-6",children:[(0,c.jsx)(ls.Z,{message:"What is a Pass-Through Endpoint?",description:"Route requests from your LiteLLM proxy to any external API. Perfect for custom models, image generation APIs, or any service you want to proxy through LiteLLM.",type:"info",showIcon:!0,className:"mb-6"}),(0,c.jsxs)(A.Z,{form:a,onFinish:Z,layout:"vertical",className:"space-y-6",initialValues:{include_subpath:!0,path:x,target:p},children:[(0,c.jsxs)(G.Z,{className:"p-5",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Route Configuration"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-5",children:"Configure how requests to your domain will be forwarded to the target API"}),(0,c.jsxs)("div",{className:"space-y-5",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Path Prefix"}),name:"path",rules:[{required:!0,message:"Path is required",pattern:/^\//}],extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:"Example: /bria, /adobe-photoshop, /elasticsearch"}),className:"mb-4",children:(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)(_.Z,{placeholder:"bria",value:x,onChange:e=>N(e.target.value),className:"flex-1"})})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Target URL"}),name:"target",rules:[{required:!0,message:"Target URL is required"},{type:"url",message:"Please enter a valid URL"}],extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:"Example:https://engine.prod.bria-api.com"}),className:"mb-4",children:(0,c.jsx)(_.Z,{placeholder:"https://engine.prod.bria-api.com",value:p,onChange:e=>{g(e.target.value),a.setFieldsValue({target:e.target.value})}})}),(0,c.jsxs)("div",{className:"flex items-center justify-between py-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-700",children:"Include Subpaths"}),(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-0.5",children:"Forward all subpaths to the target API (recommended for REST APIs)"})]}),(0,c.jsx)(A.Z.Item,{name:"include_subpath",valuePropName:"checked",className:"mb-0",children:(0,c.jsx)(tB.Z,{checked:f,onChange:v})})]})]})]}),(0,c.jsx)(lr,{pathValue:x,targetValue:p,includeSubpath:f}),(0,c.jsxs)(G.Z,{className:"p-6",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Headers"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-6",children:"Add headers that will be sent with every request to the target API"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Authentication Headers",(0,c.jsx)(V.Z,{title:"Authentication and other headers to forward with requests",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"headers",rules:[{required:!0,message:"Please configure the headers"}],extra:(0,c.jsxs)("div",{className:"text-xs text-gray-500 mt-2",children:[(0,c.jsx)("div",{className:"font-medium mb-1",children:"Add authentication tokens and other required headers"}),(0,c.jsx)("div",{children:"Common examples: auth_token, Authorization, x-api-key"})]}),children:(0,c.jsx)(ll,{})})]}),(0,c.jsxs)(G.Z,{className:"p-6",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Billing"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-6",children:"Optional cost tracking for this endpoint"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Cost Per Request (USD)",(0,c.jsx)(V.Z,{title:"Optional: Track costs for requests to this endpoint",children:(0,c.jsx)(B.Z,{className:"ml-2 text-gray-400 hover:text-gray-600"})})]}),name:"cost_per_request",extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-2",children:"The cost charged for each request through this endpoint"}),children:(0,c.jsx)(O,{min:0,step:.001,precision:4,placeholder:"2.0000",size:"large"})})]}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:y,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",loading:n,onClick:()=>{console.log("Submit button clicked"),a.submit()},children:n?"Creating...":"Add Pass-Through Endpoint"})]})]})]})})]})},lo=t(87769),lc=t(42208);let ld=e=>{let{value:s}=e,[t,l]=(0,d.useState)(!1),a=JSON.stringify(s,null,2);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("pre",{className:"font-mono text-xs bg-gray-50 p-2 rounded max-w-md overflow-auto",children:t?a:"••••••••"}),(0,c.jsx)("button",{onClick:()=>l(!t),className:"p-1 hover:bg-gray-100 rounded",type:"button",children:t?(0,c.jsx)(lo.Z,{className:"w-4 h-4 text-gray-500"}):(0,c.jsx)(lc.Z,{className:"w-4 h-4 text-gray-500"})})]})};var lm=e=>{let{endpointData:s,onClose:t,accessToken:l,isAdmin:a,onEndpointUpdated:r}=e,[i,n]=(0,d.useState)(s),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(!1),[h]=A.Z.useForm(),p=async e=>{try{if(!l||!(null==i?void 0:i.id))return;let s={};if(e.headers)try{s="string"==typeof e.headers?JSON.parse(e.headers):e.headers}catch(e){eo.Z.fromBackend("Invalid JSON format for headers");return}let t={path:i.path,target:e.target,headers:s,include_subpath:e.include_subpath,cost_per_request:e.cost_per_request};await (0,j.updatePassThroughEndpoint)(l,i.id,t),n({...i,...t}),x(!1),r&&r()}catch(e){console.error("Error updating endpoint:",e),eo.Z.fromBackend("Failed to update pass through endpoint")}},g=async()=>{try{if(!l||!(null==i?void 0:i.id))return;await (0,j.deletePassThroughEndpointsCall)(l,i.id),eo.Z.success("Pass through endpoint deleted successfully"),t(),r&&r()}catch(e){console.error("Error deleting endpoint:",e),eo.Z.fromBackend("Failed to delete pass through endpoint")}};return o?(0,c.jsx)("div",{className:"p-4",children:"Loading..."}):i?(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,c.jsxs)(S.Z,{children:["Pass Through Endpoint: ",i.path]}),(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:i.id})]})}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),a?(0,c.jsx)(e0.Z,{children:"Settings"},"settings"):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Path"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{className:"font-mono",children:i.path})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Target"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{children:i.target})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Configuration"}),(0,c.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,c.jsx)("div",{children:(0,c.jsx)(eX.Z,{color:i.include_subpath?"green":"gray",children:i.include_subpath?"Include Subpath":"Exact Path"})}),void 0!==i.cost_per_request&&(0,c.jsx)("div",{children:(0,c.jsxs)(k.Z,{children:["Cost per request: $",i.cost_per_request]})})]})]})]}),(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsx)(lr,{pathValue:i.path,targetValue:i.target,includeSubpath:i.include_subpath||!1})}),i.headers&&Object.keys(i.headers).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Headers"}),(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(i.headers).length," headers configured"]})]}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(ld,{value:i.headers})})]})]}),a&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Pass Through Endpoint Settings"}),(0,c.jsx)("div",{className:"space-x-2",children:!u&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(b.Z,{onClick:()=>x(!0),children:"Edit Settings"}),(0,c.jsx)(b.Z,{onClick:g,variant:"secondary",color:"red",children:"Delete Endpoint"})]})})]}),u?(0,c.jsxs)(A.Z,{form:h,onFinish:p,initialValues:{target:i.target,headers:i.headers?JSON.stringify(i.headers,null,2):"",include_subpath:i.include_subpath||!1,cost_per_request:i.cost_per_request},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Target URL",name:"target",rules:[{required:!0,message:"Please input a target URL"}],children:(0,c.jsx)(_.Z,{placeholder:"https://api.example.com"})}),(0,c.jsx)(A.Z.Item,{label:"Headers (JSON)",name:"headers",children:(0,c.jsx)(E.default.TextArea,{rows:5,placeholder:'{"Authorization": "Bearer your-token", "Content-Type": "application/json"}'})}),(0,c.jsx)(A.Z.Item,{label:"Include Subpath",name:"include_subpath",valuePropName:"checked",children:(0,c.jsx)(tj.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Cost per Request",name:"cost_per_request",children:(0,c.jsx)(eW.Z,{min:0,step:.01,precision:2,placeholder:"0.00",addonBefore:"$"})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,c.jsx)(P.ZP,{onClick:()=>x(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{children:"Save Changes"})]})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Path"}),(0,c.jsx)("div",{className:"font-mono",children:i.path})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Target URL"}),(0,c.jsx)("div",{children:i.target})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Include Subpath"}),(0,c.jsx)(eX.Z,{color:i.include_subpath?"green":"gray",children:i.include_subpath?"Yes":"No"})]}),void 0!==i.cost_per_request&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cost per Request"}),(0,c.jsxs)("div",{children:["$",i.cost_per_request]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Headers"}),i.headers&&Object.keys(i.headers).length>0?(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(ld,{value:i.headers})}):(0,c.jsx)("div",{className:"text-gray-500",children:"No headers configured"})]})]})]})})]})]})]}):(0,c.jsx)("div",{className:"p-4",children:"Pass through endpoint not found"})},lu=t(19130);function lx(e){let{data:s=[],columns:t,getRowCanExpand:l,renderSubComponent:a,isLoading:r=!1,loadingMessage:i="\uD83D\uDE85 Loading logs...",noDataMessage:n="No logs found"}=e,o=(0,s_.b7)({data:s,columns:t,getRowCanExpand:l,getRowId:(e,s)=>{var t;return null!==(t=null==e?void 0:e.request_id)&&void 0!==t?t:String(s)},getCoreRowModel:(0,sN.sC)(),getExpandedRowModel:(0,sN.rV)()});return(0,c.jsx)("div",{className:"rounded-lg custom-border overflow-x-auto w-full max-w-full box-border",children:(0,c.jsxs)(lu.iA,{className:"[&_td]:py-0.5 [&_th]:py-1 table-fixed w-full box-border",style:{minWidth:"800px"},children:[(0,c.jsx)(lu.ss,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(lu.SC,{children:e.headers.map(e=>(0,c.jsx)(lu.xs,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,c.jsx)(lu.RM,{children:r?(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:t.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:i})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsxs)(d.Fragment,{children:[(0,c.jsx)(lu.SC,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(lu.pj,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:e.getVisibleCells().length,className:"p-0",children:(0,c.jsx)("div",{className:"w-full max-w-full overflow-hidden box-border",children:a({row:e})})})})]},e.id)):(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:t.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:n})})})})})]})})}let lh=e=>{let{value:s}=e,[t,l]=(0,d.useState)(!1),a=JSON.stringify(s);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"font-mono text-xs",children:t?a:"••••••••"}),(0,c.jsx)("button",{onClick:()=>l(!t),className:"p-1 hover:bg-gray-100 rounded",type:"button",children:t?(0,c.jsx)(lo.Z,{className:"w-4 h-4 text-gray-500"}):(0,c.jsx)(lc.Z,{className:"w-4 h-4 text-gray-500"})})]})};var lp=e=>{let{accessToken:s,userRole:t,userID:l,modelData:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null);(0,d.useEffect)(()=>{s&&t&&l&&(0,j.getPassThroughEndpointsCall)(s).then(e=>{i(e.endpoints)})},[s,t,l]);let p=async e=>{h(e),u(!0)},g=async()=>{if(null!=x&&s){try{await (0,j.deletePassThroughEndpointsCall)(s,x);let e=r.filter(e=>e.id!==x);i(e),eo.Z.success("Endpoint deleted successfully.")}catch(e){console.error("Error deleting the endpoint:",e),eo.Z.fromBackend("Error deleting the endpoint: "+e)}u(!1),h(null)}},f=(e,s)=>{p(e)},v=[{header:"ID",accessorKey:"id",cell:e=>(0,c.jsx)(V.Z,{title:e.row.original.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>e.row.original.id&&o(e.row.original.id),children:e.row.original.id})})},{header:"Path",accessorKey:"path"},{header:"Target",accessorKey:"target",cell:e=>(0,c.jsx)(k.Z,{children:e.getValue()})},{header:"Headers",accessorKey:"headers",cell:e=>(0,c.jsx)(lh,{value:e.getValue()||{}})},{header:"Actions",id:"actions",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>s.original.id&&o(s.original.id),title:"Edit"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>f(s.original.id,s.index),title:"Delete"})]})}}];if(!s)return null;if(n){console.log("selectedEndpointId",n),console.log("generalSettings",r);let e=r.find(e=>e.id===n);return e?(0,c.jsx)(lm,{endpointData:e,onClose:()=>o(null),accessToken:s,isAdmin:"Admin"===t||"admin"===t,onEndpointUpdated:()=>{s&&(0,j.getPassThroughEndpointsCall)(s).then(e=>{i(e.endpoints)})}}):(0,c.jsx)("div",{children:"Endpoint not found"})}return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Pass Through Endpoints"}),(0,c.jsx)(k.Z,{className:"text-tremor-content",children:"Configure and manage your pass-through endpoints"})]}),(0,c.jsx)(ln,{accessToken:s,setPassThroughItems:i,passThroughItems:r}),(0,c.jsx)(lx,{data:r,columns:v,renderSubComponent:()=>(0,c.jsx)("div",{}),getRowCanExpand:()=>!1,isLoading:!1,noDataMessage:"No pass-through endpoints configured"}),m&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Pass-Through Endpoint"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this pass-through endpoint? This action cannot be undone."})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:g,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{u(!1),h(null)},children:"Cancel"})]})]})]})})]})},lg=e=>{let{accessToken:s,initialModelGroupAlias:t={},onAliasUpdate:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)({aliasName:"",targetModelGroup:""}),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!0);(0,d.useEffect)(()=>{r(Object.entries(t).map((e,s)=>{let[t,l]=e;return{id:"".concat(s,"-").concat(t),aliasName:t,targetModelGroup:l}}))},[t]);let h=async e=>{if(!s)return console.error("Access token is missing"),!1;try{let t={};return e.forEach(e=>{t[e.aliasName]=e.targetModelGroup}),console.log("Saving model group alias:",t),await (0,j.setCallbacksCall)(s,{router_settings:{model_group_alias:t}}),l&&l(t),!0}catch(e){return console.error("Failed to save model group alias settings:",e),eo.Z.fromBackend("Failed to save model group alias settings"),!1}},p=async()=>{if(!i.aliasName||!i.targetModelGroup){eo.Z.fromBackend("Please provide both alias name and target model group");return}if(a.some(e=>e.aliasName===i.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=[...a,{id:"".concat(Date.now(),"-").concat(i.aliasName),aliasName:i.aliasName,targetModelGroup:i.targetModelGroup}];await h(e)&&(r(e),n({aliasName:"",targetModelGroup:""}),eo.Z.success("Alias added successfully"))},g=e=>{m({...e})},f=async()=>{if(!o)return;if(!o.aliasName||!o.targetModelGroup){eo.Z.fromBackend("Please provide both alias name and target model group");return}if(a.some(e=>e.id!==o.id&&e.aliasName===o.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=a.map(e=>e.id===o.id?o:e);await h(e)&&(r(e),m(null),eo.Z.success("Alias updated successfully"))},v=()=>{m(null)},y=async e=>{let s=a.filter(s=>s.id!==e);await h(s)&&(r(s),eo.Z.success("Alias deleted successfully"))},b=a.reduce((e,s)=>(e[s.aliasName]=s.targetModelGroup,e),{});return(0,c.jsxs)(eR.Zb,{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>x(!u),children:[(0,c.jsxs)("div",{className:"flex flex-col",children:[(0,c.jsx)(eR.Dx,{className:"mb-0",children:"Model Group Alias Settings"}),(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Create aliases for your model groups to simplify API calls. For example, you can create an alias 'gpt-4o' that points to 'gpt-4o-mini-openai' model group."})]}),(0,c.jsx)("div",{className:"flex items-center",children:u?(0,c.jsx)(sL.Z,{className:"w-5 h-5 text-gray-500"}):(0,c.jsx)(sT.Z,{className:"w-5 h-5 text-gray-500"})})]}),u&&(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Add New Alias"}),(0,c.jsxs)("div",{className:"grid grid-cols-3 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Alias Name"}),(0,c.jsx)("input",{type:"text",value:i.aliasName,onChange:e=>n({...i,aliasName:e.target.value}),placeholder:"e.g., gpt-4o",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Target Model Group"}),(0,c.jsx)("input",{type:"text",value:i.targetModelGroup,onChange:e=>n({...i,targetModelGroup:e.target.value}),placeholder:"e.g., gpt-4o-mini-openai",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsx)("div",{className:"flex items-end",children:(0,c.jsxs)("button",{onClick:p,disabled:!i.aliasName||!i.targetModelGroup,className:"flex items-center px-4 py-2 rounded-md text-sm ".concat(i.aliasName&&i.targetModelGroup?"bg-green-600 text-white hover:bg-green-700":"bg-gray-300 text-gray-500 cursor-not-allowed"),children:[(0,c.jsx)(eD.Z,{className:"w-4 h-4 mr-1"}),"Add Alias"]})})]})]}),(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Manage Existing Aliases"}),(0,c.jsx)("div",{className:"rounded-lg custom-border relative mb-6",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(eR.iA,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(eR.ss,{children:(0,c.jsxs)(eR.SC,{children:[(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Alias Name"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Target Model Group"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Actions"})]})}),(0,c.jsxs)(eR.RM,{children:[a.map(e=>(0,c.jsx)(eR.SC,{className:"h-8",children:o&&o.id===e.id?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:o.aliasName,onChange:e=>m({...o,aliasName:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:o.targetModelGroup,onChange:e=>m({...o,targetModelGroup:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:f,className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:"Save"}),(0,c.jsx)("button",{onClick:v,className:"text-xs bg-gray-50 text-gray-600 px-2 py-1 rounded hover:bg-gray-100",children:"Cancel"})]})})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-900",children:e.aliasName}),(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-500",children:e.targetModelGroup}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>g(e),className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:(0,c.jsx)(eF.Z,{className:"w-3 h-3"})}),(0,c.jsx)("button",{onClick:()=>y(e.id),className:"text-xs bg-red-50 text-red-600 px-2 py-1 rounded hover:bg-red-100",children:(0,c.jsx)(W.Z,{className:"w-3 h-3"})})]})})]})},e.id)),0===a.length&&(0,c.jsx)(eR.SC,{children:(0,c.jsx)(eR.pj,{colSpan:3,className:"py-0.5 text-sm text-gray-500 text-center",children:"No aliases added yet. Add a new alias above."})})]})]})})}),(0,c.jsxs)(eR.Zb,{children:[(0,c.jsx)(eR.Dx,{className:"mb-4",children:"Configuration Example"}),(0,c.jsx)(eR.xv,{className:"text-gray-600 mb-4",children:"Here's how your current aliases would look in the config.yaml:"}),(0,c.jsx)("div",{className:"bg-gray-100 rounded-lg p-4 font-mono text-sm",children:(0,c.jsxs)("div",{className:"text-gray-700",children:["router_settings:",(0,c.jsx)("br",{}),"\xa0\xa0model_group_alias:",0===Object.keys(b).length?(0,c.jsxs)("span",{className:"text-gray-500",children:[(0,c.jsx)("br",{}),"\xa0\xa0\xa0\xa0# No aliases configured yet"]}):Object.entries(b).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[(0,c.jsx)("br",{}),'\xa0\xa0\xa0\xa0"',s,'": "',t,'"']},s)})]})})]})]})]})};let lj={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lf=e=>{let{accessToken:s,token:t,userRole:l,userID:a,modelData:r={data:[]},keys:i,setModelData:n,premiumUser:o,teams:m}=e,[u]=A.Z.useForm(),[x]=A.Z.useForm(),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(""),[_,N]=(0,d.useState)([]),[Z,w]=(0,d.useState)([]),[C,I]=(0,d.useState)(sU.Cl.OpenAI),[L,T]=(0,d.useState)(null),[P,E]=(0,d.useState)(!1),[M,O]=(0,d.useState)(!1),[D,F]=(0,d.useState)(null),[R,z]=(0,d.useState)([]),[U,q]=(0,d.useState)([]),[V,K]=(0,d.useState)(null),[H,J]=(0,d.useState)([]),[Y,W]=(0,d.useState)([]),[$,Q]=(0,d.useState)([]),[X,ee]=(0,d.useState)([]),[es,et]=(0,d.useState)([]),[el,ea]=(0,d.useState)([]),[er,ec]=(0,d.useState)([]),[ed,em]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[eu,ex]=(0,d.useState)(null),[eh,ep]=(0,d.useState)(null),[eg,ej]=(0,d.useState)(0),[ef,ev]=(0,d.useState)({}),[ey,eb]=(0,d.useState)([]),[e_,eN]=(0,d.useState)(!1),[eZ,ew]=(0,d.useState)(null),[ek,eS]=(0,d.useState)(null),[eC,eA]=(0,d.useState)([]),[eL,eT]=(0,d.useState)([]),[eP,eE]=(0,d.useState)({}),[eM,eO]=(0,d.useState)(!1),[eD,eF]=(0,d.useState)(null),[eR,ez]=(0,d.useState)(!1),[eU,eq]=(0,d.useState)(null),[eB,eV]=(0,d.useState)(null),[eK,eG]=(0,d.useState)(null),[eH,eJ]=(0,d.useState)(null),[eY,e$]=(0,d.useState)(""),[eX,e6]=(0,d.useState)("personal"),[e8,e7]=(0,d.useState)("current_team"),[e9,se]=(0,d.useState)(!1),[ss,st]=(0,d.useState)(!1),[sl,sa]=(0,d.useState)(!1),[sr,si]=(0,d.useState)(new Set),sn=(0,d.useRef)(null),so=(0,d.useRef)(null),[sc,sd]=(0,d.useState)({pageIndex:0,pageSize:50}),[sm,su]=(0,d.useState)(0),sx=(0,d.useMemo)(()=>r&&r.data&&0!==r.data.length?r.data.filter(e=>{var s,t,l,a,r;let i=""===eY||e.model_name.toLowerCase().includes(eY.toLowerCase()),n="all"===V||e.model_name===V||!V||"wildcard"===V&&(null===(s=e.model_name)||void 0===s?void 0:s.includes("*")),o="all"===eH||(null===(t=e.model_info.access_groups)||void 0===t?void 0:t.includes(eH))||!eH,c=!0;return"current_team"===e8&&(c="personal"===eX?(null===(l=e.model_info)||void 0===l?void 0:l.direct_access)===!0:(null===(r=e.model_info)||void 0===r?void 0:null===(a=r.access_via_team_ids)||void 0===a?void 0:a.includes(eX))===!0),i&&n&&o&&c}):[],[r,eY,V,eH,eX,e8]),sh=(0,d.useMemo)(()=>{let e=sc.pageIndex*sc.pageSize,s=e+sc.pageSize;return sx.slice(e,s)},[sx,sc.pageIndex,sc.pageSize]);(0,d.useEffect)(()=>{sd(e=>({...e,pageIndex:0}))},[eY,V,eH,eX,e8]);let sg=async(e,t,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!l||!t||!r)return;console.log("inside updateModelMetrics - startTime:",t,"endTime:",r),K(e);let i=null==eZ?void 0:eZ.token;void 0===i&&(i=null);let n=ek;void 0===n&&(n=null);try{let o=await (0,j.modelMetricsCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);console.log("Model metrics response:",o),J(o.data),W(o.all_api_bases);let c=await (0,j.streamingModelMetricsCall)(s,e,t.toISOString(),r.toISOString());Q(c.data),ee(c.all_api_bases);let d=await (0,j.modelExceptionsCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);console.log("Model exceptions response:",d),et(d.data),ea(d.exception_types);let m=await (0,j.modelMetricsSlowResponsesCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);if(console.log("slowResponses:",m),ec(m),e){let l=await (0,j.adminGlobalActivityExceptions)(s,null==t?void 0:t.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ev(l);let a=await (0,j.adminGlobalActivityExceptionsPerDeployment)(s,null==t?void 0:t.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);eb(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},sj=async e=>{try{let s=await (0,j.credentialListCall)(e);console.log("credentials: ".concat(JSON.stringify(s))),eT(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,d.useEffect)(()=>{sg(V,ed.from,ed.to)},[eZ,ek,eB]),(0,d.useEffect)(()=>{let e=e=>{sn.current&&!sn.current.contains(e.target)&&sa(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sf={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),u.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",u.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",u.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?eo.Z.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&eo.Z.fromBackend("".concat(e.file.name," file upload failed."))}},sv=()=>{f(new Date().toLocaleString())},sy=async()=>{if(!s){console.error("Access token is missing");return}try{let e={router_settings:{}};"global"===V?(console.log("Saving global retry policy:",eh),eh&&(e.router_settings.retry_policy=eh),eo.Z.success("Global retry settings saved successfully")):(console.log("Saving model group retry policy for",V,":",eu),eu&&(e.router_settings.model_group_retry_policy=eu),eo.Z.success("Retry settings saved successfully for ".concat(V))),await (0,j.setCallbacksCall)(s,e)}catch(e){console.error("Failed to save retry settings:",e),eo.Z.fromBackend("Failed to save retry settings")}};if((0,d.useEffect)(()=>{if(!s||!t||!l||!a)return;let e=async()=>{try{var e,t,r,i,o,c,d,m,u,x,h,p;let g=await (0,j.modelInfoCall)(s,a,l);console.log("Model data response:",g.data),n(g);let f=await (0,j.modelSettingsCall)(s);f&&w(f);let v=new Set;for(let e=0;e0&&(_=y[y.length-1],console.log("_initial_model_group:",_)),console.log("selectedModelGroup:",V);let N=await (0,j.modelMetricsCall)(s,a,l,_,null===(e=ed.from)||void 0===e?void 0:e.toISOString(),null===(t=ed.to)||void 0===t?void 0:t.toISOString(),null==eZ?void 0:eZ.token,ek);console.log("Model metrics response:",N),J(N.data),W(N.all_api_bases);let Z=await (0,j.streamingModelMetricsCall)(s,_,null===(r=ed.from)||void 0===r?void 0:r.toISOString(),null===(i=ed.to)||void 0===i?void 0:i.toISOString());Q(Z.data),ee(Z.all_api_bases);let k=await (0,j.modelExceptionsCall)(s,a,l,_,null===(o=ed.from)||void 0===o?void 0:o.toISOString(),null===(c=ed.to)||void 0===c?void 0:c.toISOString(),null==eZ?void 0:eZ.token,ek);console.log("Model exceptions response:",k),et(k.data),ea(k.exception_types);let S=await (0,j.modelMetricsSlowResponsesCall)(s,a,l,_,null===(d=ed.from)||void 0===d?void 0:d.toISOString(),null===(m=ed.to)||void 0===m?void 0:m.toISOString(),null==eZ?void 0:eZ.token,ek),C=await (0,j.adminGlobalActivityExceptions)(s,null===(u=ed.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(x=ed.to)||void 0===x?void 0:x.toISOString().split("T")[0],_);ev(C);let I=await (0,j.adminGlobalActivityExceptionsPerDeployment)(s,null===(h=ed.from)||void 0===h?void 0:h.toISOString().split("T")[0],null===(p=ed.to)||void 0===p?void 0:p.toISOString().split("T")[0],_);eb(I),console.log("dailyExceptions:",C),console.log("dailyExceptionsPerDeplyment:",I),console.log("slowResponses:",S),ec(S);let A=await (0,j.allEndUsersCall)(s);eA(null==A?void 0:A.end_users);let L=(await (0,j.getCallbacksCall)(s,a,l)).router_settings;console.log("routerSettingsInfo:",L);let T=L.model_group_retry_policy,P=L.num_retries;console.log("model_group_retry_policy:",T),console.log("default_retries:",P),ex(T),ep(L.retry_policy),ej(P);let E=L.model_group_alias||{};eE(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&t&&l&&a&&e();let r=async()=>{let e=await (0,j.modelCostMap)(s);console.log("received model cost map data: ".concat(Object.keys(e))),p(e)};null==h&&r(),sv()},[s,t,l,a,h,g,eB]),!r||!s||!t||!l||!a)return(0,c.jsx)("div",{children:"Loading..."});let sb=[],s_=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(h)),null!=h&&"object"==typeof h&&e in h)?h[e].litellm_provider:"openai";if(t){let e=t.split("/"),s=e[0];(i=l)||(i=1===e.length?u(t):s)}else i="-";a&&(n=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,c=null==a?void 0:a.max_tokens,d=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=i,r.data[e].input_cost=n,r.data[e].output_cost=o,r.data[e].litellm_model_name=t,s_.push(i),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=c,r.data[e].max_input_tokens=d,r.data[e].api_base=null==s?void 0:null===(sT=s.litellm_params)||void 0===sT?void 0:sT.api_base,r.data[e].cleanedLitellmParams=m,sb.push(s.model_name),console.log(r.data[e])}if(l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sP=(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mb-1",children:"Select API Key Name"}),o?(0,c.jsxs)("div",{children:[(0,c.jsxs)(eQ.Z,{defaultValue:"all-keys",children:[(0,c.jsx)(ei.Z,{value:"all-keys",onClick:()=>{ew(null)},children:"All Keys"},"all-keys"),null==i?void 0:i.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,c.jsx)(ei.Z,{value:String(s),onClick:()=>{ew(e)},children:e.key_alias},s):null)]}),(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Customer Name"}),(0,c.jsxs)(eQ.Z,{defaultValue:"all-customers",children:[(0,c.jsx)(ei.Z,{value:"all-customers",onClick:()=>{eS(null)},children:"All Customers"},"all-customers"),null==eC?void 0:eC.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>{eS(e)},children:e},s))]}),(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Team"}),(0,c.jsxs)(eQ.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eK?eK:"all",onValueChange:e=>eG("all"===e?null:e),children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Teams"}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Team"}),(0,c.jsxs)(eQ.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eK?eK:"all",onValueChange:e=>eG("all"===e?null:e),children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Teams"}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sE=e=>{var s,t;let{payload:l,active:a}=e;if(!a||!l)return null;let r=null===(t=l[0])||void 0===t?void 0:null===(s=t.payload)||void 0===s?void 0:s.date,i=l.sort((e,s)=>s.value-e.value);if(i.length>5){let e=i.length-5;(i=i.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:l.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,c.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,c.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),i.map((e,s)=>{let t=parseFloat(e.value.toFixed(5)),l=0===t&&e.value>0?"<0.00001":t.toFixed(5);return(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,c.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,c.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:l})]},s)})]})};console.log("selectedProvider: ".concat(C)),console.log("providerModels.length: ".concat(_.length));let sM=Object.keys(sU.Cl).find(e=>sU.Cl[e]===C);return(sM&&Z&&Z.find(e=>e.name===sU.fK[sM]),eU)?(0,c.jsx)("div",{className:"w-full h-full",children:(0,c.jsx)(tu,{teamId:eU,onClose:()=>eq(null),accessToken:s,is_team_admin:"Admin"===l,is_proxy_admin:"Proxy Admin"===l,userModels:sb,editTeam:!1,onUpdate:sv})}):(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("h2",{className:"text-lg font-semibold",children:"Model Management"}),eI.ZL.includes(l)?(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"Add and manage models for the proxy"}):(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"Add models for teams you are an admin for."})]})}),eD?(0,c.jsx)(tI,{modelId:eD,editModel:!0,onClose:()=>{eF(null),ez(!1)},modelData:r.data.find(e=>e.model_info.id===eD),accessToken:s,userID:a,userRole:l,setEditModalVisible:O,setSelectedModel:F,onModelUpdate:e=>{n({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sv()},modelAccessGroups:U}):(0,c.jsxs)(e1.Z,{index:sm,onIndexChange:su,className:"gap-2 h-[75vh] w-full ",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[eI.ZL.includes(l)?(0,c.jsx)(e0.Z,{children:"All Models"}):(0,c.jsx)(e0.Z,{children:"Your Models"}),(0,c.jsx)(e0.Z,{children:"Add Model"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"LLM Credentials"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Pass-Through Endpoints"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Health Status"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Analytics"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Retry Settings"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Group Alias"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Price Data Reload"})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[g&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",g]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sv})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(y.Z,{children:(0,c.jsx)("div",{className:"flex flex-col space-y-4",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"border-b px-6 py-4 bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"Current Team:"}),(0,c.jsxs)(eQ.Z,{className:"w-80",defaultValue:"personal",value:eX,onValueChange:e=>e6(e),children:[(0,c.jsx)(ei.Z,{value:"personal",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Personal"})]})}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e.team_alias?"".concat(e.team_alias.slice(0,30),"..."):"Team ".concat(e.team_id.slice(0,30),"...")})]})},e.team_id))]})]}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"View:"}),(0,c.jsxs)(eQ.Z,{className:"w-64",defaultValue:"current_team",value:e8,onValueChange:e=>e7(e),children:[(0,c.jsx)(ei.Z,{value:"current_team",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-purple-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Current Team Models"})]})}),(0,c.jsx)(ei.Z,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-gray-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"All Available Models"})]})})]})]})]}),"current_team"===e8&&(0,c.jsxs)("div",{className:"flex items-start gap-2 mt-3",children:[(0,c.jsx)(B.Z,{className:"text-gray-400 mt-0.5 flex-shrink-0 text-xs"}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"personal"===eX?(0,c.jsxs)("span",{children:["To access these models: Create a Virtual Key without selecting a team on the"," ",(0,c.jsx)("a",{href:"/?login=success&page=api-keys",className:"text-gray-600 hover:text-gray-800 underline",children:"Virtual Keys page"})]}):(0,c.jsxs)("span",{children:['To access these models: Create a Virtual Key and select Team as "',eX,'" on the'," ",(0,c.jsx)("a",{href:"/?login=success&page=api-keys",className:"text-gray-600 hover:text-gray-800 underline",children:"Virtual Keys page"})]})})]})]}),(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search model names...",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:eY,onChange:e=>e$(e.target.value)}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(e9?"bg-gray-100":""),onClick:()=>se(!e9),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters"]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{e$(""),K("all"),eJ(null),e6("personal"),e7("current_team"),sd({pageIndex:0,pageSize:50})},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),e9&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsx)("div",{className:"w-64",children:(0,c.jsxs)(eQ.Z,{value:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),placeholder:"Filter by Public Model Name",children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Models"}),(0,c.jsx)(ei.Z,{value:"wildcard",children:"Wildcard Models (*)"}),R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,children:e},s))]})}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsxs)(eQ.Z,{value:null!=eH?eH:"all",onValueChange:e=>eJ("all"===e?null:e),placeholder:"Filter by Model Access Group",children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Model Access Groups"}),U.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,children:e},s))]})})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-sm text-gray-700",children:sx.length>0?"Showing ".concat(sc.pageIndex*sc.pageSize+1," - ").concat(Math.min((sc.pageIndex+1)*sc.pageSize,sx.length)," of ").concat(sx.length," results"):"Showing 0 results"}),sx.length>sc.pageSize&&(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("button",{onClick:()=>sd(e=>({...e,pageIndex:e.pageIndex-1})),disabled:0===sc.pageIndex,className:"px-3 py-1 text-sm border rounded-md ".concat(0===sc.pageIndex?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,c.jsx)("button",{onClick:()=>sd(e=>({...e,pageIndex:e.pageIndex+1})),disabled:sc.pageIndex>=Math.ceil(sx.length/sc.pageSize)-1,className:"px-3 py-1 text-sm border rounded-md ".concat(sc.pageIndex>=Math.ceil(sx.length/sc.pageSize)-1?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,c.jsx)(t$.C,{columns:tQ(l,a,o,eF,eq,s2,e=>{F(e),O(!0)},sv,ez,sr,si),data:sh,isLoading:!1,table:so})]})})})}),(0,c.jsx)(e4.Z,{className:"h-full",children:(0,c.jsx)(tW,{form:u,handleOk:()=>{console.log("\uD83D\uDE80 handleOk called from model dashboard!"),console.log("Current form values:",u.getFieldsValue()),u.validateFields().then(e=>{console.log("✅ Validation passed, submitting:",e),sB(e,s,u,sv)}).catch(e=>{var s;console.error("❌ Validation failed:",e),console.error("Form errors:",e.errorFields);let t=(null===(s=e.errorFields)||void 0===s?void 0:s.map(e=>"".concat(e.name.join("."),": ").concat(e.errors.join(", "))).join(" | "))||"Unknown validation error";eo.Z.fromBackend("Please fill in the following required fields: ".concat(t))})},selectedProvider:C,setSelectedProvider:I,providerModels:_,setProviderModelsFn:e=>{let s=(0,sU.bK)(e,h);N(s),console.log("providerModels: ".concat(s))},getPlaceholder:sU.ph,uploadProps:sf,showAdvancedSettings:eM,setShowAdvancedSettings:eO,teams:m,credentials:eL,accessToken:s,userRole:l,premiumUser:o})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(s1,{accessToken:s,uploadProps:sf,credentialList:eL,fetchCredentials:sj})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lp,{accessToken:s,userRole:l,userID:a,modelData:r})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(le,{accessToken:s,modelData:r,all_models_on_proxy:sb,getDisplayModelName:s2,setSelectedModelId:eF})}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:ed,className:"mr-2",onValueChange:e=>{em(e),sg(V,e.from,e.to)}})}),(0,c.jsxs)(v.Z,{className:"ml-2",children:[(0,c.jsx)(k.Z,{children:"Select Model Group"}),(0,c.jsx)(eQ.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>sg(e,ed.from,ed.to),children:e},s))})]}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(s8.Z,{trigger:"click",content:sP,overlayStyle:{width:"20vw"},children:(0,c.jsx)(b.Z,{icon:sp.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(G.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Avg. Latency per Token"}),(0,c.jsx)(e0.Z,{value:"2",children:"Time to first token"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,c.jsx)(k.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),H&&Y&&(0,c.jsx)(s6.Z,{title:"Model Latency",className:"h-72",data:H,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sE})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(s9,{modelMetrics:$,modelMetricsCategories:X,customTooltip:sE,premiumUser:o})})]})]})})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(G.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Deployment"}),(0,c.jsx)(sI.Z,{children:"Success Responses"}),(0,c.jsxs)(sI.Z,{children:["Slow Responses ",(0,c.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,c.jsx)(sk.Z,{children:er.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.api_base}),(0,c.jsx)(sS.Z,{children:e.total_count}),(0,c.jsx)(sS.Z,{children:e.slow_count})]},s))})]})})})]}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["All Exceptions for ",V]}),(0,c.jsx)(s3.Z,{className:"h-60",data:es,index:"model",categories:el,stack:!0,yAxisWidth:30})]})}),(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,c.jsxs)(y.Z,{numItems:1,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,c.jsx)(v.Z,{})]})]}),o?(0,c.jsx)(c.Fragment,{children:ey.map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,c.jsx)(c.Fragment,{children:ey&&ey.length>0&&ey.slice(0,1).map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,c.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,c.jsx)(b.Z,{variant:"primary",className:"mb-2",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.api_base}),(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"flex items-center gap-4 mb-6",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{children:"Retry Policy Scope:"}),(0,c.jsxs)(eQ.Z,{className:"ml-2 w-48",defaultValue:"global",value:"global"===V?"global":V||R[0],onValueChange:e=>K(e),children:[(0,c.jsx)(ei.Z,{value:"global",children:"Global Default"}),R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>K(e),children:e},s))]})]})}),"global"===V?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(S.Z,{children:"Global Retry Policy"}),(0,c.jsx)(k.Z,{className:"mb-6",children:"Default retry settings applied to all model groups unless overridden"})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(S.Z,{children:["Retry Policy for ",V]}),(0,c.jsx)(k.Z,{className:"mb-6",children:"Model-specific retry settings. Falls back to global defaults if not set."})]}),lj&&(0,c.jsx)("table",{children:(0,c.jsx)("tbody",{children:Object.entries(lj).map((e,s)=>{var t,l,a,r;let i,[n,o]=e;if("global"===V)i=null!==(t=null==eh?void 0:eh[o])&&void 0!==t?t:eg;else{let e=null==eu?void 0:null===(l=eu[V])||void 0===l?void 0:l[o];i=null!=e?e:null!==(a=null==eh?void 0:eh[o])&&void 0!==a?a:eg}return(0,c.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,c.jsxs)("td",{children:[(0,c.jsx)(k.Z,{children:n}),"global"!==V&&(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500 ml-2",children:["(Global: ",null!==(r=null==eh?void 0:eh[o])&&void 0!==r?r:eg,")"]})]}),(0,c.jsx)("td",{children:(0,c.jsx)(eW.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{"global"===V?ep(s=>null==e?s:{...null!=s?s:{},[o]:e}):ex(s=>{var t;let l=null!==(t=null==s?void 0:s[V])&&void 0!==t?t:{};return{...null!=s?s:{},[V]:{...l,[o]:e}}})}})})]},s)})})}),(0,c.jsx)(b.Z,{className:"mt-6 mr-8",onClick:sy,children:"Save"})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lg,{accessToken:s,initialModelGroupAlias:eP,onAliasUpdate:eE})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"p-6",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"Price Data Management"}),(0,c.jsx)(k.Z,{className:"text-tremor-content",children:"Manage model pricing data and configure automatic reload schedules"})]}),(0,c.jsx)(t6,{accessToken:s,onReloadSuccess:()=>{(async()=>{p(await (0,j.modelCostMap)(s))})()},buttonText:"Reload Price Data",size:"middle",type:"primary",className:"w-full"})]})})]})]})]})})})},lv=e=>{let{visible:s,possibleUIRoles:t,onCancel:l,user:a,onSubmit:r}=e,[i,n]=(0,d.useState)(a),[o]=A.Z.useForm();(0,d.useEffect)(()=>{o.resetFields()},[a]);let m=async()=>{o.resetFields(),l()},u=async e=>{r(e),o.resetFields(),l()};return a?(0,c.jsx)(L.Z,{visible:s,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,c.jsx)(A.Z,{form:o,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,c.jsx)(I.default,{children:t&&Object.entries(t).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.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,c.jsx)(eW.Z,{min:0,step:.01})}),(0,c.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,c.jsx)(O,{min:0,step:.01})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsx)(eT,{})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},ly=t(16853);function lb(e){let{userData:s,onCancel:t,onSubmit:l,teams:a,accessToken:r,userID:i,userRole:n,userModels:o,possibleUIRoles:m,isBulkEdit:u=!1}=e,[x]=A.Z.useForm();return d.useEffect(()=>{var e,t,l,a,r,i;x.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(t=s.user_info)||void 0===t?void 0:t.user_role,models:(null===(l=s.user_info)||void 0===l?void 0:l.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,budget_duration:null===(r=s.user_info)||void 0===r?void 0:r.budget_duration,metadata:(null===(i=s.user_info)||void 0===i?void 0:i.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,x]),(0,c.jsxs)(A.Z,{form:x,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}l(e)},layout:"vertical",children:[!u&&(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",children:(0,c.jsx)(_.Z,{disabled:!0})}),!u&&(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Global Proxy Role"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{})})]}),name:"user_role",children:(0,c.jsx)(I.default,{children:m&&Object.entries(m).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Personal Models"," ",(0,c.jsx)(V.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eI.ZL.includes(n||""),children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),(0,c.jsx)(I.default.Option,{value:"no-default-models",children:"No Default Models"},"no-default-models"),o.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsx)(eT,{})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(ly.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",type:"button",onClick:t,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})]})}let{Text:l_,Title:lN}=en.default;var lZ=e=>{let{visible:s,onCancel:t,selectedUsers:l,possibleUIRoles:a,accessToken:r,onSuccess:i,teams:n,userRole:o,userModels:m,allowAllUsers:u=!1}=e,[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(!1),[_,N]=(0,d.useState)(!1),Z=()=>{g([]),v(null),b(!1),N(!1),t()},w=d.useMemo(()=>({user_id:"bulk_edit",user_info:{user_email:"",user_role:"",teams:[],models:[],max_budget:null,spend:0,metadata:{},created_at:null,updated_at:null},keys:[],teams:n||[]}),[n,s]),k=async e=>{if(console.log("formValues",e),!r){eo.Z.fromBackend("Access token not found");return}h(!0);try{let s=l.map(e=>e.user_id),a={};e.user_role&&""!==e.user_role&&(a.user_role=e.user_role),null!==e.max_budget&&void 0!==e.max_budget&&(a.max_budget=e.max_budget),e.models&&e.models.length>0&&(a.models=e.models),e.budget_duration&&""!==e.budget_duration&&(a.budget_duration=e.budget_duration),e.metadata&&Object.keys(e.metadata).length>0&&(a.metadata=e.metadata);let n=Object.keys(a).length>0,o=y&&p.length>0;if(!n&&!o){eo.Z.fromBackend("Please modify at least one field or select teams to add users to");return}let c=[];if(n){if(_){let e=await (0,j.userBulkUpdateUserCall)(r,a,void 0,!0);c.push("Updated all users (".concat(e.total_requested," total)"))}else await (0,j.userBulkUpdateUserCall)(r,a,s),c.push("Updated ".concat(s.length," user(s)"))}if(o){let e=[];for(let s of p)try{let t=null;_?t=null:l.map(e=>({user_id:e.user_id,role:"user",user_email:e.user_email||null}));let a=await (0,j.teamBulkMemberAddCall)(r,s,t||null,f||void 0,_);console.log("result",a),e.push({teamId:s,success:!0,successfulAdditions:a.successful_additions,failedAdditions:a.failed_additions})}catch(t){console.error("Failed to add users to team ".concat(s,":"),t),e.push({teamId:s,success:!1,error:t})}let s=e.filter(e=>e.success),t=e.filter(e=>!e.success);if(s.length>0){let e=s.reduce((e,s)=>e+s.successfulAdditions,0);c.push("Added users to ".concat(s.length," team(s) (").concat(e," total additions)"))}t.length>0&&tc.ZP.warning("Failed to add users to ".concat(t.length," team(s)"))}c.length>0&&eo.Z.success(c.join(". ")),g([]),v(null),b(!1),N(!1),i(),t()}catch(e){console.error("Bulk operation failed:",e),eo.Z.fromBackend("Failed to perform bulk operations")}finally{h(!1)}};return(0,c.jsxs)(L.Z,{visible:s,onCancel:Z,footer:null,title:_?"Bulk Edit All Users":"Bulk Edit ".concat(l.length," User(s)"),width:800,children:[u&&(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsx)(ts.Z,{checked:_,onChange:e=>N(e.target.checked),children:(0,c.jsx)(l_,{strong:!0,children:"Update ALL users in the system"})}),_&&(0,c.jsx)("div",{style:{marginTop:8},children:(0,c.jsx)(l_,{type:"warning",style:{fontSize:"12px"},children:"⚠️ This will apply changes to ALL users in the system, not just the selected ones."})})]}),!_&&(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsxs)(lN,{level:5,children:["Selected Users (",l.length,"):"]}),(0,c.jsx)(em.Z,{size:"small",bordered:!0,dataSource:l,pagination:!1,scroll:{y:200},rowKey:"user_id",columns:[{title:"User ID",dataIndex:"user_id",key:"user_id",width:"30%",render:e=>(0,c.jsx)(l_,{strong:!0,style:{fontSize:"12px"},children:e.length>20?"".concat(e.slice(0,20),"..."):e})},{title:"Email",dataIndex:"user_email",key:"user_email",width:"25%",render:e=>(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:e||"No email"})},{title:"Current Role",dataIndex:"user_role",key:"user_role",width:"25%",render:e=>{var s;return(0,c.jsx)(l_,{style:{fontSize:"12px"},children:(null==a?void 0:null===(s=a[e])||void 0===s?void 0:s.ui_label)||e})}},{title:"Budget",dataIndex:"max_budget",key:"max_budget",width:"20%",render:e=>(0,c.jsx)(l_,{style:{fontSize:"12px"},children:null!==e?"$".concat(e):"Unlimited"})}]})]}),(0,c.jsx)(K.Z,{}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsxs)(l_,{children:[(0,c.jsx)("strong",{children:"Instructions:"})," Fill in the fields below with the values you want to apply to all selected users. You can bulk edit: role, budget, models, and metadata. You can also add users to teams."]})}),(0,c.jsx)(tN.Z,{title:"Team Management",size:"small",className:"mb-4",style:{backgroundColor:"#fafafa"},children:(0,c.jsxs)(tX.Z,{direction:"vertical",style:{width:"100%"},children:[(0,c.jsx)(ts.Z,{checked:y,onChange:e=>b(e.target.checked),children:"Add selected users to teams"}),y&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(l_,{strong:!0,children:"Select Teams:"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select teams to add users to",value:p,onChange:g,style:{width:"100%",marginTop:8},options:(null==n?void 0:n.map(e=>({label:e.team_alias||e.team_id,value:e.team_id})))||[]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(l_,{strong:!0,children:"Team Budget (Optional):"}),(0,c.jsx)(eW.Z,{placeholder:"Max budget per user in team",value:f,onChange:e=>v(e),style:{width:"100%",marginTop:8},min:0,step:.01,precision:2}),(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:"Leave empty for unlimited budget within team limits"})]}),(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:'Users will be added with "user" role by default. All users will be added to each selected team.'})]})]})}),(0,c.jsx)(lb,{userData:w,onCancel:Z,onSubmit:k,teams:n,accessToken:r,userID:"bulk_edit",userRole:o,userModels:m,possibleUIRoles:a,isBulkEdit:!0}),x&&(0,c.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,c.jsxs)(l_,{children:["Updating ",_?"all users":l.length," user(s)..."]})})]})};let lw=(e,s,t,l,a,r)=>{let i=[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,c.jsx)(V.Z,{title:s.original.user_id,children:(0,c.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var t;let{row:l}=s;return(0,c.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(t=e[l.original.user_role])||void 0===t?void 0:t.ui_label)||"-"})}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.spend?eE(s.original.spend,4):"-"})}},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{children:"SSO ID"}),(0,c.jsx)(V.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,c.jsx)(t3.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,c.jsx)(y.Z,{numItems:2,children:s.original.key_count>0?(0,c.jsxs)(eX.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,c.jsx)(eX.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(V.Z,{title:"Edit user details",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>a(s.original.user_id,!0)})}),(0,c.jsx)(V.Z,{title:"Delete user",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>t(s.original.user_id)})}),(0,c.jsx)(V.Z,{title:"Reset Password",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:e3.Z,size:"sm",onClick:()=>l(s.original.user_id)})})]})}}];if(r){let{onSelectUser:e,onSelectAll:s,isUserSelected:t,isAllSelected:l,isIndeterminate:a}=r;return[{id:"select",header:()=>(0,c.jsx)(ts.Z,{indeterminate:a,checked:l,onChange:e=>s(e.target.checked),onClick:e=>e.stopPropagation()}),cell:s=>{let{row:l}=s;return(0,c.jsx)(ts.Z,{checked:t(l.original),onChange:s=>e(l.original,s.target.checked),onClick:e=>e.stopPropagation()})}},...i]}return i};function lk(e){var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f,v,_,N,Z,w,C,I,A,L,T,E,M,O,D,F,R,z,U,q,B,V,K;let{userId:H,onClose:J,accessToken:Y,userRole:$,onDelete:Q,possibleUIRoles:X,initialTab:ee=0,startInEditMode:es=!1}=e,[et,el]=(0,d.useState)(null),[ea,er]=(0,d.useState)(!1),[ei,en]=(0,d.useState)(!0),[ed,em]=(0,d.useState)(es),[eu,ex]=(0,d.useState)([]),[eh,ep]=(0,d.useState)(!1),[eg,ej]=(0,d.useState)(null),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(ee),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)(!1);d.useEffect(()=>{ev((0,j.getProxyBaseUrl)())},[]),d.useEffect(()=>{console.log("userId: ".concat(H,", userRole: ").concat($,", accessToken: ").concat(Y)),(async()=>{try{if(!Y)return;let e=await (0,j.userInfoCall)(Y,H,$||"",!1,null,null,!0);el(e);let s=(await (0,j.modelAvailableCall)(Y,H,$||"")).data.map(e=>e.id);ex(s)}catch(e){console.error("Error fetching user data:",e),eo.Z.fromBackend("Failed to fetch user data")}finally{en(!1)}})()},[Y,H,$]);let ek=async()=>{if(!Y){eo.Z.fromBackend("Access token not found");return}try{eo.Z.success("Generating password reset link...");let e=await (0,j.invitationCreateCall)(Y,H);ej(e),ep(!0)}catch(e){eo.Z.fromBackend("Failed to generate password reset link")}},eS=async()=>{try{if(!Y)return;await (0,j.userDeleteCall)(Y,[H]),eo.Z.success("User deleted successfully"),Q&&Q(),J()}catch(e){console.error("Error deleting user:",e),eo.Z.fromBackend("Failed to delete user")}},eC=async e=>{try{if(!Y||!et)return;await (0,j.userUpdateUserCall)(Y,e,null),el({...et,user_info:{...et.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:e.metadata}}),eo.Z.success("User updated successfully"),em(!1)}catch(e){console.error("Error updating user:",e),eo.Z.fromBackend("Failed to update user")}};if(ei)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(k.Z,{children:"Loading user data..."})]});if(!et)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(k.Z,{children:"User not found"})]});let eA=async(e,s)=>{await eM(e)&&(eN(e=>({...e,[s]:!0})),setTimeout(()=>{eN(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(S.Z,{children:(null===(s=et.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:et.user_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["user-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eA(et.user_id,"user-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["user-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),$&&eI.LQ.includes($)&&(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(b.Z,{icon:e3.Z,variant:"secondary",onClick:ek,className:"flex items-center",children:"Reset Password"}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>er(!0),className:"flex items-center",children:"Delete User"})]})]}),ea&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:eS,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>er(!1),children:"Cancel"})]})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:ey,onIndexChange:eb,children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Details"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Spend"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE((null===(t=et.user_info)||void 0===t?void 0:t.spend)||0,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",(null===(l=et.user_info)||void 0===l?void 0:l.max_budget)!==null?"$".concat(eE(et.user_info.max_budget,4)):"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Teams"}),(0,c.jsx)("div",{className:"mt-2",children:(null===(a=et.teams)||void 0===a?void 0:a.length)&&(null===(r=et.teams)||void 0===r?void 0:r.length)>0?(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[null===(i=et.teams)||void 0===i?void 0:i.slice(0,eZ?et.teams.length:20).map((e,s)=>(0,c.jsx)(eX.Z,{color:"blue",title:e.team_alias,children:e.team_alias},s)),!eZ&&(null===(n=et.teams)||void 0===n?void 0:n.length)>20&&(0,c.jsxs)(eX.Z,{color:"gray",className:"cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!0),children:["+",et.teams.length-20," more"]}),eZ&&(null===(o=et.teams)||void 0===o?void 0:o.length)>20&&(0,c.jsx)(eX.Z,{color:"gray",className:"cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!1),children:"Show Less"})]}):(0,c.jsx)(k.Z,{children:"No teams"})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"API Keys"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsxs)(k.Z,{children:[(null===(m=et.keys)||void 0===m?void 0:m.length)||0," keys"]})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Personal Models"}),(0,c.jsx)("div",{className:"mt-2",children:(null===(x=et.user_info)||void 0===x?void 0:null===(u=x.models)||void 0===u?void 0:u.length)&&(null===(p=et.user_info)||void 0===p?void 0:null===(h=p.models)||void 0===h?void 0:h.length)>0?null===(f=et.user_info)||void 0===f?void 0:null===(g=f.models)||void 0===g?void 0:g.map((e,s)=>(0,c.jsx)(k.Z,{children:e},s)):(0,c.jsx)(k.Z,{children:"All proxy models"})})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"User Settings"}),!ed&&$&&eI.LQ.includes($)&&(0,c.jsx)(b.Z,{variant:"light",onClick:()=>em(!0),children:"Edit Settings"})]}),ed&&et?(0,c.jsx)(lb,{userData:et,onCancel:()=>em(!1),onSubmit:eC,teams:et.teams,accessToken:Y,userID:H,userRole:$,userModels:eu,possibleUIRoles:X}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"User ID"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"font-mono",children:et.user_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["user-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eA(et.user_id,"user-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["user-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Email"}),(0,c.jsx)(k.Z,{children:(null===(v=et.user_info)||void 0===v?void 0:v.user_email)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Global Proxy Role"}),(0,c.jsx)(k.Z,{children:(null===(_=et.user_info)||void 0===_?void 0:_.user_role)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:(null===(N=et.user_info)||void 0===N?void 0:N.created_at)?new Date(et.user_info.created_at).toLocaleString():"Unknown"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(k.Z,{children:(null===(Z=et.user_info)||void 0===Z?void 0:Z.updated_at)?new Date(et.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Teams"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(w=et.teams)||void 0===w?void 0:w.length)&&(null===(C=et.teams)||void 0===C?void 0:C.length)>0?(0,c.jsxs)(c.Fragment,{children:[null===(I=et.teams)||void 0===I?void 0:I.slice(0,eZ?et.teams.length:20).map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",title:e.team_alias||e.team_id,children:e.team_alias||e.team_id},s)),!eZ&&(null===(A=et.teams)||void 0===A?void 0:A.length)>20&&(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded text-xs cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!0),children:["+",et.teams.length-20," more"]}),eZ&&(null===(L=et.teams)||void 0===L?void 0:L.length)>20&&(0,c.jsx)("span",{className:"px-2 py-1 bg-gray-100 rounded text-xs cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!1),children:"Show Less"})]}):(0,c.jsx)(k.Z,{children:"No teams"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Personal Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(E=et.user_info)||void 0===E?void 0:null===(T=E.models)||void 0===T?void 0:T.length)&&(null===(O=et.user_info)||void 0===O?void 0:null===(M=O.models)||void 0===M?void 0:M.length)>0?null===(F=et.user_info)||void 0===F?void 0:null===(D=F.models)||void 0===D?void 0:D.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,c.jsx)(k.Z,{children:"All proxy models"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"API Keys"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(R=et.keys)||void 0===R?void 0:R.length)&&(null===(z=et.keys)||void 0===z?void 0:z.length)>0?et.keys.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,c.jsx)(k.Z,{children:"No API keys"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Max Budget"}),(0,c.jsx)(k.Z,{children:(null===(U=et.user_info)||void 0===U?void 0:U.max_budget)!==null&&(null===(q=et.user_info)||void 0===q?void 0:q.max_budget)!==void 0?"$".concat(eE(et.user_info.max_budget,4)):"Unlimited"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget Reset"}),(0,c.jsx)(k.Z,{children:eL(null!==(K=null===(B=et.user_info)||void 0===B?void 0:B.budget_duration)&&void 0!==K?K:null)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(V=et.user_info)||void 0===V?void 0:V.metadata)||{},null,2)})]})]})]})})]})]}),(0,c.jsx)(ec,{isInvitationLinkModalVisible:eh,setIsInvitationLinkModalVisible:ep,baseUrl:ef||"",invitationLinkData:eg,modalType:"resetPassword"})]})}function lS(e){let{data:s=[],columns:t,isLoading:l=!1,onSortChange:a,currentSort:r,accessToken:i,userRole:n,possibleUIRoles:o,handleEdit:m,handleDelete:u,handleResetPassword:x,selectedUsers:h=[],onSelectionChange:p,enableSelection:g=!1,filters:j,updateFilters:f,initialFilters:v,teams:y,userListResponse:b,currentPage:_,handlePageChange:N}=e,[Z,w]=d.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[k,S]=d.useState(null),[C,I]=d.useState(!1),[A,L]=d.useState(!1),T=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];S(e),I(s)},P=(e,s)=>{p&&(s?p([...h,e]):p(h.filter(s=>s.user_id!==e.user_id)))},E=e=>{p&&(e?p(s):p([]))},M=e=>h.some(s=>s.user_id===e.user_id),O=s.length>0&&h.length===s.length,D=h.length>0&&h.lengtho?lw(o,m,u,x,T,g?{selectedUsers:h,onSelectUser:P,onSelectAll:E,isUserSelected:M,isAllSelected:O,isIndeterminate:D}:void 0):t,[o,m,u,x,T,t,g,h,O,D]),R=(0,s_.b7)({data:s,columns:F,state:{sorting:Z},onSortingChange:e=>{if(w(e),e.length>0){let s=e[0],t=s.id,l=s.desc?"desc":"asc";null==a||a(t,l)}},getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(d.useEffect(()=>{r&&w([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),k)?(0,c.jsx)(lk,{userId:k,onClose:()=>{S(null),I(!1)},accessToken:i,userRole:n,possibleUIRoles:o,initialTab:C?1:0,startInEditMode:C}):(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search by email...",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:j.email,onChange:e=>f({email:e.target.value})}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(A?"bg-gray-100":""),onClick:()=>L(!A),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters",(j.user_id||j.user_role||j.team)&&(0,c.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{f(v)},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),A&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Filter by User 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:j.user_id,onChange:e=>f({user_id:e.target.value})}),(0,c.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,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:j.user_role,onValueChange:e=>f({user_role:e}),placeholder:"Select Role",children:o&&Object.entries(o).map(e=>{let[s,t]=e;return(0,c.jsx)(ei.Z,{value:s,children:t.ui_label},s)})})}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:j.team,onValueChange:e=>f({team:e}),placeholder:"Select Team",children:null==y?void 0:y.map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,c.jsx)("div",{className:"relative w-64",children:(0,c.jsx)("input",{type:"text",placeholder:"Filter by SSO 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:j.sso_user_id,onChange:e=>f({sso_user_id:e.target.value})})})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",b&&b.users&&b.users.length>0?(b.page-1)*b.page_size+1:0," ","-"," ",b&&b.users?Math.min(b.page*b.page_size,b.total):0," ","of ",b?b.total:0," results"]}),(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>N(_-1),disabled:1===_,className:"px-3 py-1 text-sm border rounded-md ".concat(1===_?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,c.jsx)("button",{onClick:()=>N(_+1),disabled:!b||_>=b.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!b||_>=b.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,c.jsx)("div",{className:"overflow-auto",children:(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:R.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:l?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:F.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?R.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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)]":""),onClick:()=>{"user_id"===e.column.id&&T(e.getValue(),!1)},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:F.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No users found"})})})})})]})})})})]})}var lC=t(67982),lI=t(87908),lA=e=>{var s;let{accessToken:t,possibleUIRoles:l,userID:a,userRole:r}=e,[i,n]=(0,d.useState)(!0),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)({}),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),{Paragraph:N}=en.default,{Option:Z}=I.default;(0,d.useEffect)(()=>{(async()=>{if(!t){n(!1);return}try{let e=await (0,j.getInternalUserSettings)(t);if(m(e),p(e.values||{}),t)try{let e=await (0,j.modelAvailableCall)(t,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);y(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),eo.Z.fromBackend("Failed to fetch SSO settings")}finally{n(!1)}})()},[t]);let w=async()=>{if(t){f(!0);try{let e=Object.entries(h).reduce((e,s)=>{let[t,l]=s;return e[t]=""===l?null:l,e},{}),s=await (0,j.updateInternalUserSettings)(t,e);m({...o,values:s.settings}),x(!1)}catch(e){console.error("Error updating SSO settings:",e),eo.Z.fromBackend("Failed to update settings: "+e)}finally{f(!1)}}},C=(e,s)=>{p(t=>({...t,[e]:s}))},A=e=>e&&Array.isArray(e)?e.map(e=>"string"==typeof e?{team_id:e,user_role:"user"}:"object"==typeof e&&e.team_id?{team_id:e.team_id,max_budget_in_team:e.max_budget_in_team,user_role:e.user_role||"user"}:{team_id:"",user_role:"user"}):[],L=e=>{let s=A(e),t=(e,t,l)=>{let a=[...s];a[e]={...a[e],[t]:l},C("teams",a)},l=e=>{C("teams",s.filter((s,t)=>t!==e))};return(0,c.jsxs)("div",{className:"space-y-3",children:[s.map((e,s)=>(0,c.jsxs)("div",{className:"border rounded-lg p-4 bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Team ",s+1]}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",icon:ep.Z,onClick:()=>l(s),className:"text-red-500 hover:text-red-700",children:"Remove"})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"Team ID"}),(0,c.jsx)(_.Z,{value:e.team_id,onChange:e=>t(s,"team_id",e.target.value),placeholder:"Enter team ID"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"Max Budget in Team"}),(0,c.jsx)(eW.Z,{style:{width:"100%"},value:e.max_budget_in_team,onChange:e=>t(s,"max_budget_in_team",e),placeholder:"Optional",min:0,step:.01,precision:2})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"User Role"}),(0,c.jsxs)(I.default,{style:{width:"100%"},value:e.user_role,onChange:e=>t(s,"user_role",e),children:[(0,c.jsx)(Z,{value:"user",children:"User"}),(0,c.jsx)(Z,{value:"admin",children:"Admin"})]})]})]})]},s)),(0,c.jsx)(b.Z,{variant:"secondary",icon:tv.Z,onClick:()=>{C("teams",[...s,{team_id:"",user_role:"user"}])},className:"w-full",children:"Add Team"})]})},T=(e,s,t)=>{var a;let r=s.type;if("teams"===e)return(0,c.jsx)("div",{className:"mt-2",children:L(h[e]||[])});if("user_role"===e&&l)return(0,c.jsx)(I.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>C(e,s),className:"mt-2",children:Object.entries(l).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(Z,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{children:t}),(0,c.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:l})]})},s)})});if("budget_duration"===e)return(0,c.jsx)(eT,{value:h[e]||null,onChange:s=>C(e,s),className:"mt-2"});if("boolean"===r)return(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(tj.Z,{checked:!!h[e],onChange:s=>C(e,s)})});if("array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum))return(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>C(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,c.jsx)(Z,{value:e,children:e},e))});if("models"===e)return(0,c.jsxs)(I.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>C(e,s),className:"mt-2",children:[(0,c.jsx)(Z,{value:"no-default-models",children:"No Default Models"}),v.map(e=>(0,c.jsx)(Z,{value:e,children:F(e)},e))]});if("string"===r&&s.enum)return(0,c.jsx)(I.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>C(e,s),className:"mt-2",children:s.enum.map(e=>(0,c.jsx)(Z,{value:e,children:e},e))});else return(0,c.jsx)(_.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>C(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},P=(e,s)=>{if(null==s)return(0,c.jsx)("span",{className:"text-gray-400",children:"Not set"});if("teams"===e&&Array.isArray(s)){if(0===s.length)return(0,c.jsx)("span",{className:"text-gray-400",children:"No teams assigned"});let e=A(s);return(0,c.jsx)("div",{className:"space-y-2 mt-1",children:e.map((e,s)=>(0,c.jsx)("div",{className:"border rounded-lg p-3 bg-white",children:(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 text-sm",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Team ID:"}),(0,c.jsx)("p",{className:"text-gray-900",children:e.team_id||"Not specified"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Max Budget:"}),(0,c.jsx)("p",{className:"text-gray-900",children:void 0!==e.max_budget_in_team?"$".concat(eE(e.max_budget_in_team,4)):"No limit"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Role:"}),(0,c.jsx)("p",{className:"text-gray-900 capitalize",children:e.user_role})]})]})},s))})}if("user_role"===e&&l&&l[s]){let{ui_label:e,description:t}=l[s];return(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium",children:e}),t&&(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:t})]})}return"budget_duration"===e?(0,c.jsx)("span",{children:eL(s)}):"boolean"==typeof s?(0,c.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:F(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,c.jsx)("span",{children:String(s)})};return i?(0,c.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,c.jsx)(lI.Z,{size:"large"})}):o?(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Default User Settings"}),!i&&o&&(u?(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{x(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:w,loading:g,children:"Save Changes"})]}):(0,c.jsx)(b.Z,{onClick:()=>x(!0),children:"Edit Settings"}))]}),(null==o?void 0:null===(s=o.field_schema)||void 0===s?void 0:s.description)&&(0,c.jsx)(N,{className:"mb-4",children:o.field_schema.description}),(0,c.jsx)(lC.Z,{}),(0,c.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,field_schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[t,l]=s,a=e[t],r=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,c.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,c.jsx)(k.Z,{className:"font-medium text-lg",children:r}),(0,c.jsx)(N,{className:"text-sm text-gray-500 mt-1",children:l.description||"No description available"}),u?(0,c.jsx)("div",{className:"mt-2",children:T(t,l,a)}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:P(t,a)})]},t)}):(0,c.jsx)(k.Z,{children:"No schema information available"})})()})]}):(0,c.jsx)(G.Z,{children:(0,c.jsx)(k.Z,{children:"No settings available or you do not have permission to view them."})})},lL=t(19616);let lT={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lP=e=>{var s;let{accessToken:t,token:l,userRole:a,userID:r,teams:i}=e,n=(0,h.NL)(),[o,m]=(0,d.useState)(1),[u,x]=(0,d.useState)(!1),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!1),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)("users"),[w,k]=(0,d.useState)(lT),[S,C,I]=(0,lL.G)(w,{wait:300}),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(null),[E,M]=(0,d.useState)(null),[O,D]=(0,d.useState)([]),[F,R]=(0,d.useState)(!1),[z,U]=(0,d.useState)(!1),[q,B]=(0,d.useState)([]),V=e=>{_(e),v(!0)};(0,d.useEffect)(()=>()=>{I.cancel()},[I]),(0,d.useEffect)(()=>{M((0,j.getProxyBaseUrl)())},[]),(0,d.useEffect)(()=>{(async()=>{try{if(!r||!a||!t)return;let e=(await (0,j.modelAvailableCall)(t,r,a)).data.map(e=>e.id);console.log("available_model_names:",e),B(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,a]);let K=e=>{k(s=>{let t={...s,...e};return C(t),t})},G=async e=>{if(!t){eo.Z.fromBackend("Access token not found");return}try{eo.Z.success("Generating password reset link...");let s=await (0,j.invitationCreateCall)(t,e);P(s),L(!0)}catch(e){eo.Z.fromBackend("Failed to generate password reset link")}},H=async()=>{if(y&&t)try{await (0,j.userDeleteCall)(t,[y]),n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==y);return{...e,users:s}}),eo.Z.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),eo.Z.fromBackend("Failed to delete user")}v(!1),_(null)},J=async()=>{g(null),x(!1)},Y=async e=>{if(console.log("inside handleEditSubmit:",e),t&&l&&a&&r){try{let s=await (0,j.userUpdateUserCall)(t,e,null);n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let t=e.users.map(e=>e.user_id===s.data.user_id?eP(e,s.data):e);return{...e,users:t}}),eo.Z.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}g(null),x(!1)}},W=async e=>{m(e)},$=(0,sj.a)({queryKey:["userList",{debouncedFilter:S,currentPage:o}],queryFn:async()=>{if(!t)throw Error("Access token required");return await (0,j.userListCall)(t,S.user_id?[S.user_id]:null,o,25,S.email||null,S.user_role||null,S.team||null,S.sso_user_id||null,S.sort_by,S.sort_order)},enabled:!!(t&&l&&a&&r),placeholderData:e=>e}),Q=$.data,X=(0,sj.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!t)throw Error("Access token required");return await (0,j.getPossibleUserRoles)(t)},enabled:!!(t&&l&&a&&r)}).data;if($.isLoading||!t||!l||!a||!r)return(0,c.jsx)("div",{children:"Loading..."});let ee=lw(X,e=>{g(e),x(!0)},V,G,()=>{});return(0,c.jsxs)("div",{className:"w-full p-8 overflow-hidden",children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,c.jsxs)("div",{className:"flex space-x-3",children:[(0,c.jsx)(ek,{userID:r,accessToken:t,teams:i,possibleUIRoles:X}),(0,c.jsx)(b.Z,{onClick:()=>{U(!z),D([])},variant:z?"primary":"secondary",className:"flex items-center",children:z?"Cancel Selection":"Select Users"}),z&&(0,c.jsxs)(b.Z,{onClick:()=>{if(0===O.length){eo.Z.fromBackend("Please select users to edit");return}R(!0)},disabled:0===O.length,className:"flex items-center",children:["Bulk Edit (",O.length," selected)"]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Users"}),(0,c.jsx)(e0.Z,{children:"Default User Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lS,{data:(null===(s=$.data)||void 0===s?void 0:s.users)||[],columns:ee,isLoading:$.isLoading,accessToken:t,userRole:a,onSortChange:(e,s)=>{K({sort_by:e,sort_order:s})},currentSort:{sortBy:w.sort_by,sortOrder:w.sort_order},possibleUIRoles:X,handleEdit:e=>{g(e),x(!0)},handleDelete:V,handleResetPassword:G,enableSelection:z,selectedUsers:O,onSelectionChange:e=>{D(e)},filters:w,updateFilters:K,initialFilters:lT,teams:i,userListResponse:Q,currentPage:o,handlePageChange:W})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lA,{accessToken:t,possibleUIRoles:X,userID:r,userRole:a})})]})]}),(0,c.jsx)(lv,{visible:u,possibleUIRoles:X,onCancel:J,user:p,onSubmit:Y}),f&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,c.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",y]})]})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:H,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{v(!1),_(null)},children:"Cancel"})]})]})]})}),(0,c.jsx)(ec,{isInvitationLinkModalVisible:A,setIsInvitationLinkModalVisible:L,baseUrl:E||"",invitationLinkData:T,modalType:"resetPassword"}),(0,c.jsx)(lZ,{visible:F,onCancel:()=>R(!1),selectedUsers:O,possibleUIRoles:X,accessToken:t,onSuccess:()=>{n.invalidateQueries({queryKey:["userList"]}),D([]),U(!1)},teams:i,userRole:a,userModels:q,allowAllUsers:!!a&&(0,eI.tY)(a)})]})},lE=e=>{var s;let{accessToken:t,userID:l,userRole:a}=e,[r,i]=(0,d.useState)(!0),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)({}),[p,g]=(0,d.useState)(!1),[f,v]=(0,d.useState)([]),{Paragraph:y}=en.default,{Option:N}=I.default;(0,d.useEffect)(()=>{(async()=>{if(!t){i(!1);return}try{let e=await (0,j.getDefaultTeamSettings)(t);if(o(e),h(e.values||{}),t)try{let e=await (0,j.modelAvailableCall)(t,l,a);if(e&&e.data){let s=e.data.map(e=>e.id);v(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),eo.Z.fromBackend("Failed to fetch team settings")}finally{i(!1)}})()},[t]);let Z=async()=>{if(t){g(!0);try{let e=await (0,j.updateDefaultTeamSettings)(t,x);o({...n,values:e.settings}),u(!1),eo.Z.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),eo.Z.fromBackend("Failed to update team settings")}finally{g(!1)}}},w=(e,s)=>{h(t=>({...t,[e]:s}))},C=(e,s,t)=>{var l;let a=s.type;return"budget_duration"===e?(0,c.jsx)(eT,{value:x[e]||null,onChange:s=>w(e,s),className:"mt-2"}):"boolean"===a?(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(tj.Z,{checked:!!x[e],onChange:s=>w(e,s)})}):"array"===a&&(null===(l=s.items)||void 0===l?void 0:l.enum)?(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>w(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,c.jsx)(N,{value:e,children:e},e))}):"models"===e?(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>w(e,s),className:"mt-2",children:f.map(e=>(0,c.jsx)(N,{value:e,children:F(e)},e))}):"string"===a&&s.enum?(0,c.jsx)(I.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>w(e,s),className:"mt-2",children:s.enum.map(e=>(0,c.jsx)(N,{value:e,children:e},e))}):(0,c.jsx)(_.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>w(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},A=(e,s)=>null==s?(0,c.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,c.jsx)("span",{children:eL(s)}):"boolean"==typeof s?(0,c.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:F(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,c.jsx)("span",{children:String(s)});return r?(0,c.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,c.jsx)(lI.Z,{size:"large"})}):n?(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&n&&(m?(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{u(!1),h(n.values||{})},disabled:p,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:Z,loading:p,children:"Save Changes"})]}):(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Settings"}))]}),(0,c.jsx)(k.Z,{children:"These settings will be applied by default when creating new teams."}),(null==n?void 0:null===(s=n.field_schema)||void 0===s?void 0:s.description)&&(0,c.jsx)(y,{className:"mb-4 mt-2",children:n.field_schema.description}),(0,c.jsx)(lC.Z,{}),(0,c.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,field_schema:s}=n;return s&&s.properties?Object.entries(s.properties).map(s=>{let[t,l]=s,a=e[t],r=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,c.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,c.jsx)(k.Z,{className:"font-medium text-lg",children:r}),(0,c.jsx)(y,{className:"text-sm text-gray-500 mt-1",children:l.description||"No description available"}),m?(0,c.jsx)("div",{className:"mt-2",children:C(t,l,a)}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:A(t,a)})]},t)}):(0,c.jsx)(k.Z,{children:"No schema information available"})})()})]}):(0,c.jsx)(G.Z,{children:(0,c.jsx)(k.Z,{children:"No team settings available or you do not have permission to view them."})})},lM=e=>{let{accessToken:s,userID:t}=e,[l,a]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(s&&t)try{let e=await (0,j.availableTeamListCall)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,t]);let r=async e=>{if(s&&t)try{await (0,j.teamMemberAddCall)(s,e,{user_id:t,role:"user"}),eo.Z.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),eo.Z.fromBackend("Failed to join team")}};return(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Team Name"}),(0,c.jsx)(sI.Z,{children:"Description"}),(0,c.jsx)(sI.Z,{children:"Members"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"Actions"})]})}),(0,c.jsxs)(sk.Z,{children:[l.map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.team_alias})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.description||"No description available"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:[e.members_with_roles.length," members"]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})})})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===l.length&&(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:5,className:"text-center",children:(0,c.jsx)(k.Z,{children:"No available teams to join"})})})]})]})})},lO=t(32489),lD=t(76865);let lF=(e,s)=>{let t=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),t=e.models):t=s,R(t,s)};var lR=e=>{let{teams:s,searchParams:t,accessToken:l,setTeams:a,userID:r,userRole:i,organizations:n,premiumUser:o=!1}=e,[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[S,C]=(0,d.useState)(!1),[T,M]=(0,d.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,d.useEffect)(()=>{console.log("inside useeffect - ".concat(m)),l&&f(l,r,i,x,a),eJ()},[m]);let[R]=A.Z.useForm(),[z]=A.Z.useForm(),{Title:q,Paragraph:K}=en.default,[H,J]=(0,d.useState)(""),[Y,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(null),[ee,es]=(0,d.useState)(null),[et,el]=(0,d.useState)(!1),[ea,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(!1),[eu,ex]=(0,d.useState)(!1),[eh,ep]=(0,d.useState)([]),[eg,ej]=(0,d.useState)(!1),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)([]),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)([]),[ek,eS]=(0,d.useState)({}),[eC,eA]=(0,d.useState)([]),[eL,eT]=(0,d.useState)([]),[eM,eD]=(0,d.useState)(!1),[eF,eR]=(0,d.useState)(""),[ez,eU]=(0,d.useState)({});(0,d.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(p));let e=lF(p,eh);console.log("models: ".concat(e)),eb(e),R.setFieldValue("models",[])},[p,eh]),(0,d.useEffect)(()=>{(async()=>{try{if(null==l)return;let e=(await (0,j.getGuardrailsList)(l)).guardrails.map(e=>e.guardrail_name);ew(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[l]);let eq=async()=>{try{if(null==l)return;let e=await (0,j.fetchMCPAccessGroups)(l);eT(e)}catch(e){console.error("Failed to fetch MCP access groups:",e)}};(0,d.useEffect)(()=>{eq()},[l]),(0,d.useEffect)(()=>{s&&eN(s.reduce((e,s)=>(e[s.team_id]={keys:s.keys||[],team_info:{members_with_roles:s.members_with_roles||[]}},e),{}))},[s]);let eV=async e=>{ev(e),ej(!0)},eK=async()=>{if(null!=ef&&null!=s&&null!=l){try{await (0,j.teamDeleteCall)(l,ef),f(l,r,i,x,a)}catch(e){console.error("Error deleting the team:",e)}ej(!1),ev(null)}},eG=()=>{ej(!1),ev(null)};(0,d.useEffect)(()=>{(async()=>{try{if(null===r||null===i||null===l)return;let e=await D(r,i,l);e&&ep(e)}catch(e){console.error("Error fetching user models:",e)}})()},[l,r,i,s]);let eH=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=l){var t,r,i;let n=null==e?void 0:e.team_alias,o=null!==(i=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==i?i:[],c=(null==e?void 0:e.organization_id)||(null==x?void 0:x.organization_id);if(""===c||"string"!=typeof c?e.organization_id=null:e.organization_id=c.trim(),o.includes(n))throw Error("Team alias ".concat(n," already exists, please pick another alias"));if(eo.Z.info("Creating Team"),eC.length>0){let s={};if(e.metadata)try{s=JSON.parse(e.metadata)}catch(e){console.warn("Invalid JSON in metadata field, starting with empty object")}s={...s,logging:eC.filter(e=>e.callback_name)},e.metadata=JSON.stringify(s)}if((e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0||e.allowed_mcp_servers_and_groups&&((null===(t=e.allowed_mcp_servers_and_groups.servers)||void 0===t?void 0:t.length)>0||(null===(r=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===r?void 0:r.length)>0))&&(e.object_permission={},e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission.vector_stores=e.allowed_vector_store_ids,delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups)){let{servers:s,accessGroups:t}=e.allowed_mcp_servers_and_groups;s&&s.length>0&&(e.object_permission.mcp_servers=s),t&&t.length>0&&(e.object_permission.mcp_access_groups=t),delete e.allowed_mcp_servers_and_groups}e.allowed_mcp_access_groups&&e.allowed_mcp_access_groups.length>0&&(e.object_permission||(e.object_permission={}),e.object_permission.mcp_access_groups=e.allowed_mcp_access_groups,delete e.allowed_mcp_access_groups),Object.keys(ez).length>0&&(e.model_aliases=ez);let d=await (0,j.teamCreateCall)(l,e);null!==s?a([...s,d]):a([d]),console.log("response for team create call: ".concat(d)),eo.Z.success("Team created"),R.resetFields(),eA([]),eU({}),ec(!1)}}catch(e){console.error("Error creating the team:",e),eo.Z.fromBackend("Error creating the team: "+e)}},eJ=()=>{u(new Date().toLocaleString())},eY=(e,s)=>{let t={...T,[e]:s};M(t),l&&(0,j.v2TeamListCall)(l,t.organization_id||null,null,t.team_id||null,t.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[("Admin"==i||"Org Admin"==i)&&(0,c.jsx)(b.Z,{className:"w-fit",onClick:()=>ec(!0),children:"+ Create New Team"}),ee?(0,c.jsx)(tu,{teamId:ee,onUpdate:e=>{a(s=>{if(null==s)return s;let t=s.map(s=>e.team_id===s.team_id?eP(s,e):s);return l&&f(l,r,i,x,a),t})},onClose:()=>{es(null),el(!1)},accessToken:l,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===ee)),is_proxy_admin:"Admin"==i,userModels:eh,editTeam:et}):(0,c.jsxs)(e1.Z,{className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"Your Teams"}),(0,c.jsx)(e0.Z,{children:"Available Teams"}),(0,eI.tY)(i||"")&&(0,c.jsx)(e0.Z,{children:"Default Team Settings"})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[m&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",m]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(k.Z,{children:["Click on “Team ID” to view team details"," ",(0,c.jsx)("b",{children:"and"})," manage team members."]}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search by Team Name...",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:T.team_alias,onChange:e=>eY("team_alias",e.target.value)}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(S?"bg-gray-100":""),onClick:()=>C(!S),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters",(T.team_id||T.team_alias||T.organization_id)&&(0,c.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{M({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),l&&(0,j.v2TeamListCall)(l,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),S&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Enter Team 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:T.team_id,onChange:e=>eY("team_id",e.target.value)}),(0,c.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,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:T.organization_id||"",onValueChange:e=>eY("organization_id",e),placeholder:"Select Organization",children:null==n?void 0:n.map(e=>(0,c.jsx)(ei.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Team Name"}),(0,c.jsx)(sI.Z,{children:"Team ID"}),(0,c.jsx)(sI.Z,{children:"Created"}),(0,c.jsx)(sI.Z,{children:"Spend (USD)"}),(0,c.jsx)(sI.Z,{children:"Budget (USD)"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"Organization"}),(0,c.jsx)(sI.Z,{children:"Info"})]})}),(0,c.jsx)(sk.Z,{children:s&&s.length>0?s.filter(e=>!x||e.organization_id===x.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.team_id,children:(0,c.jsxs)(b.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:()=>{es(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:eE(e.spend,4)}),(0,c.jsx)(sS.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,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:e.models.length>3?"px-0":"",children:(0,c.jsx)("div",{className:"flex flex-col",children:Array.isArray(e.models)?(0,c.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[e.models.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:ek[e.team_id]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{eS(s=>({...s,[e.team_id]:!s[e.team_id]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.models.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),e.models.length>3&&!ek[e.team_id]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",e.models.length-3," ",e.models.length-3==1?"more model":"more models"]})}),ek[e.team_id]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:e.models.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}),(0,c.jsx)(sS.Z,{children:e.organization_id}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsxs)(k.Z,{children:[e_&&e.team_id&&e_[e.team_id]&&e_[e.team_id].keys&&e_[e.team_id].keys.length," ","Keys"]}),(0,c.jsxs)(k.Z,{children:[e_&&e.team_id&&e_[e.team_id]&&e_[e.team_id].team_info&&e_[e.team_id].team_info.members_with_roles&&e_[e.team_id].team_info.members_with_roles.length," ","Members"]})]}),(0,c.jsx)(sS.Z,{children:"Admin"==i?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{es(e.team_id),el(!0)}}),(0,c.jsx)(sZ.Z,{onClick:()=>eV(e.team_id),icon:W.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),eg&&(()=>{var e;let t=null==s?void 0:s.find(e=>e.team_id===ef),l=(null==t?void 0:t.team_alias)||"",a=(null==t?void 0:null===(e=t.keys)||void 0===e?void 0:e.length)||0,r=eF===l;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Team"}),(0,c.jsx)("button",{onClick:()=>{eG(),eR("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)(lO.Z,{size:20})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[a>0&&(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)(lD.Z,{size:20})}),(0,c.jsxs)("div",{children:[(0,c.jsxs)("p",{className:"text-base font-medium text-red-600",children:["Warning: This team has ",a," associated key",a>1?"s":"","."]}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"Deleting the team will also delete all associated keys. This action is irreversible."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to force delete this team and all its keys?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:l})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:eF,onChange:e=>eR(e.target.value),placeholder:"Enter team name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{eG(),eR("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:eK,disabled:!r,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(r?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Force Delete"})]})]})})})()]})})})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lM,{accessToken:l,userID:r})}),(0,eI.tY)(i||"")&&(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lE,{accessToken:l,userID:r||"",userRole:i||""})})]})]}),("Admin"==i||"Org Admin"==i)&&(0,c.jsx)(L.Z,{title:"Create Team",visible:ea,width:1e3,footer:null,onOk:()=>{ec(!1),R.resetFields(),eA([]),eU({})},onCancel:()=>{ec(!1),R.resetFields(),eA([]),eU({})},children:(0,c.jsxs)(A.Z,{form:R,onFinish:eH,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Organization"," ",(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,c.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,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:x?x.organization_id:null,className:"mt-8",children:(0,c.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{R.setFieldValue("organization_id",e),g((null==n?void 0:n.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var t;return!!s&&((null===(t=s.children)||void 0===t?void 0:t.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==n?void 0:n.map(e=>(0,c.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,c.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,c.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.Z,{title:"These are the models that your selected team has access to",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ey.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",onClick:()=>{eM||(eq(),eD(!0))},children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Additional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.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,c.jsx)(_.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Budget (USD)",name:"team_member_budget",normalize:e=>e?Number(e):void 0,tooltip:"This is the individual budget for a user in the team.",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Key Duration (eg: 1d, 1mo)",name:"team_member_key_duration",tooltip:"Set a limit to the duration of a team member's key. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days), 1mo (month)",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member RPM Limit",name:"team_member_rpm_limit",tooltip:"The RPM (Requests Per Minute) limit for individual team members",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Team Member TPM Limit",name:"team_member_tpm_limit",tooltip:"The TPM (Tokens Per Minute) limit for individual team members",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Setup your first guardrail",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:eZ.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this team can access by default. Leave empty for access to all vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-8",help:"Select vector stores this team can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>R.setFieldValue("allowed_vector_store_ids",e),value:R.getFieldValue("allowed_vector_store_ids"),accessToken:l||"",placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers or access groups this team can access by default. ",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-8",help:"Select MCP servers or access groups this team can access. ",children:(0,c.jsx)(eO,{onChange:e=>R.setFieldValue("allowed_mcp_servers_and_groups",e),value:R.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:l||"",placeholder:"Select MCP servers or access groups (optional)"})})]})]}),(0,c.jsxs)(N.Z,{className:"mt-8 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:eC,onChange:eA,premiumUser:o})})})]}),(0,c.jsxs)(N.Z,{className:"mt-8 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Model Aliases"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600 mb-4",children:"Create custom aliases for models that can be used by team members in API calls. This allows you to create shortcuts for specific models."}),(0,c.jsx)(eB,{accessToken:l||"",initialModelAliases:ez,onAliasUpdate:eU,showExampleConfig:!1})]})})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create Team"})})]})})]})})})},lz=e=>{var s,t,l,a,r;let{organizationId:i,onClose:n,accessToken:o,is_org_admin:m,is_proxy_admin:u,userModels:x,editOrg:h}=e,[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!0),[N]=A.Z.useForm(),[Z,w]=(0,d.useState)(!1),[C,L]=(0,d.useState)(!1),[T,M]=(0,d.useState)(!1),[D,R]=(0,d.useState)(null),[z,q]=(0,d.useState)({}),B=m||u,V=async()=>{try{if(v(!0),!o)return;let e=await (0,j.organizationInfoCall)(o,i);g(e)}catch(e){eo.Z.fromBackend("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{v(!1)}};(0,d.useEffect)(()=>{V()},[i,o]);let K=async e=>{try{if(null==o)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.organizationMemberAddCall)(o,i,s),eo.Z.success("Organization member added successfully"),L(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to add organization member"),console.error("Error adding organization member:",e)}},H=async e=>{try{if(!o)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.organizationMemberUpdateCall)(o,i,s),eo.Z.success("Organization member updated successfully"),M(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to update organization member"),console.error("Error updating organization member:",e)}},J=async e=>{try{if(!o)return;await (0,j.organizationMemberDeleteCall)(o,i,e.user_id),eo.Z.success("Organization member deleted successfully"),M(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},Y=async e=>{try{if(!o)return;let s={organization_id:i,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};if((void 0!==e.vector_stores||void 0!==e.mcp_servers_and_groups)&&(s.object_permission={...null==p?void 0:p.object_permission,vector_stores:e.vector_stores||[]},void 0!==e.mcp_servers_and_groups)){let{servers:t,accessGroups:l}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};t&&t.length>0&&(s.object_permission.mcp_servers=t),l&&l.length>0&&(s.object_permission.mcp_access_groups=l)}await (0,j.organizationUpdateCall)(o,s),eo.Z.success("Organization settings updated successfully"),w(!1),V()}catch(e){eo.Z.fromBackend("Failed to update organization settings"),console.error("Error updating organization:",e)}};if(f)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!p)return(0,c.jsx)("div",{className:"p-4",children:"Organization not found"});let $=async(e,s)=>{await eM(e)&&(q(e=>({...e,[s]:!0})),setTimeout(()=>{q(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,onClick:n,variant:"light",className:"mb-4",children:"Back to Organizations"}),(0,c.jsx)(S.Z,{children:p.organization_alias}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:p.organization_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:z["org-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>$(p.organization_id,"org-id"),className:"left-2 z-10 transition-all duration-200 ".concat(z["org-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:h?2:0,children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Members"}),(0,c.jsx)(e0.Z,{children:"Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Organization Details"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["Created: ",new Date(p.created_at).toLocaleDateString()]}),(0,c.jsxs)(k.Z,{children:["Updated: ",new Date(p.updated_at).toLocaleDateString()]}),(0,c.jsxs)(k.Z,{children:["Created By: ",p.created_by]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Budget Status"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(p.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null===p.litellm_budget_table.max_budget?"Unlimited":"$".concat(eE(p.litellm_budget_table.max_budget,4))]}),p.litellm_budget_table.budget_duration&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Reset: ",p.litellm_budget_table.budget_duration]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",p.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",p.litellm_budget_table.rpm_limit||"Unlimited"]}),p.litellm_budget_table.max_parallel_requests&&(0,c.jsxs)(k.Z,{children:["Max Parallel Requests: ",p.litellm_budget_table.max_parallel_requests]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:0===p.models.length?(0,c.jsx)(eX.Z,{color:"red",children:"All proxy models"}):p.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Teams"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=p.teams)||void 0===s?void 0:s.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e.team_id},s))})]}),(0,c.jsx)(sc,{objectPermission:p.object_permission,variant:"card",accessToken:o})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"Role"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{children:"Created At"}),(0,c.jsx)(sI.Z,{})]})}),(0,c.jsx)(sk.Z,{children:null===(t=p.members)||void 0===t?void 0:t.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_role})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:["$",eE(e.spend,4)]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,c.jsx)(sS.Z,{children:B&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{R({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),M(!0)}}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>{J(e)}})]})})]},s))})]})}),B&&(0,c.jsx)(b.Z,{onClick:()=>{L(!0)},children:"Add Member"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Organization Settings"}),B&&!Z&&(0,c.jsx)(b.Z,{onClick:()=>w(!0),children:"Edit Settings"})]}),Z?(0,c.jsxs)(A.Z,{form:N,onFinish:Y,initialValues:{organization_alias:p.organization_alias,models:p.models,tpm_limit:p.litellm_budget_table.tpm_limit,rpm_limit:p.litellm_budget_table.rpm_limit,max_budget:p.litellm_budget_table.max_budget,budget_duration:p.litellm_budget_table.budget_duration,metadata:p.metadata?JSON.stringify(p.metadata,null,2):"",vector_stores:(null===(l=p.object_permission)||void 0===l?void 0:l.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(a=p.object_permission)||void 0===a?void 0:a.mcp_servers)||[],accessGroups:(null===(r=p.object_permission)||void 0===r?void 0:r.mcp_access_groups)||[]}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),x.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>N.setFieldValue("vector_stores",e),value:N.getFieldValue("vector_stores"),accessToken:o||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers & Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>N.setFieldValue("mcp_servers_and_groups",e),value:N.getFieldValue("mcp_servers_and_groups"),accessToken:o||"",placeholder:"Select MCP servers and access groups"})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{onClick:()=>w(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization Name"}),(0,c.jsx)("div",{children:p.organization_alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization ID"}),(0,c.jsx)("div",{className:"font-mono",children:p.organization_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:new Date(p.created_at).toLocaleString()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:p.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)("div",{children:["TPM: ",p.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",p.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget"}),(0,c.jsxs)("div",{children:["Max:"," ",null!==p.litellm_budget_table.max_budget?"$".concat(eE(p.litellm_budget_table.max_budget,4)):"No Limit"]}),(0,c.jsxs)("div",{children:["Reset: ",p.litellm_budget_table.budget_duration||"Never"]})]}),(0,c.jsx)(sc,{objectPermission:p.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:o})]})]})})]})]}),(0,c.jsx)(tm,{isVisible:C,onCancel:()=>L(!1),onSubmit:K,accessToken:o,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,c.jsx)(td,{visible:T,onCancel:()=>M(!1),onSubmit:H,initialData:D,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"}]}})]})};let lU=async(e,s)=>{s(await (0,j.organizationListCall)(e))};var lq=e=>{let{organizations:s,userRole:t,userModels:l,accessToken:a,lastRefreshed:r,handleRefreshClick:i,currentOrg:n,guardrailsList:o=[],setOrganizations:m,premiumUser:u}=e,[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(!1),[f,_]=(0,d.useState)(!1),[N,Z]=(0,d.useState)(null),[w,S]=(0,d.useState)(!1),[C]=A.Z.useForm(),[T,P]=(0,d.useState)({});(0,d.useEffect)(()=>{a&&lU(a,m)},[a]);let M=e=>{e&&(Z(e),_(!0))},D=async()=>{if(N&&a)try{await (0,j.organizationDeleteCall)(a,N),eo.Z.success("Organization deleted successfully"),_(!1),Z(null),lU(a,m)}catch(e){console.error("Error deleting organization:",e)}},R=async e=>{try{var s,t,l,r;if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),(e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0||e.allowed_mcp_servers_and_groups&&((null===(s=e.allowed_mcp_servers_and_groups.servers)||void 0===s?void 0:s.length)>0||(null===(t=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===t?void 0:t.length)>0))&&(e.object_permission={},e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission.vector_stores=e.allowed_vector_store_ids,delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups&&((null===(l=e.allowed_mcp_servers_and_groups.servers)||void 0===l?void 0:l.length)>0&&(e.object_permission.mcp_servers=e.allowed_mcp_servers_and_groups.servers),(null===(r=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===r?void 0:r.length)>0&&(e.object_permission.mcp_access_groups=e.allowed_mcp_servers_and_groups.accessGroups),delete e.allowed_mcp_servers_and_groups)),await (0,j.organizationCreateCall)(a,e),eo.Z.success("Organization created successfully"),S(!1),C.resetFields(),lU(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?(0,c.jsxs)("div",{className:"w-full mx-4 h-[75vh]",children:[(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[("Admin"===t||"Org Admin"===t)&&(0,c.jsx)(b.Z,{className:"w-fit",onClick:()=>S(!0),children:"+ Create New Organization"}),x?(0,c.jsx)(lz,{organizationId:x,onClose:()=>{h(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===t,userModels:l,editOrg:p}):(0,c.jsxs)(e1.Z,{className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsx)("div",{className:"flex",children:(0,c.jsx)(e0.Z,{children:"Your Organizations"})}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",r]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:i})]})]}),(0,c.jsx)(e5.Z,{children:(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(k.Z,{children:"Click on “Organization ID” to view organization details."}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Organization ID"}),(0,c.jsx)(sI.Z,{children:"Organization Name"}),(0,c.jsx)(sI.Z,{children:"Created"}),(0,c.jsx)(sI.Z,{children:"Spend (USD)"}),(0,c.jsx)(sI.Z,{children:"Budget (USD)"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"TPM / RPM Limits"}),(0,c.jsx)(sI.Z,{children:"Info"}),(0,c.jsx)(sI.Z,{children:"Actions"})]})}),(0,c.jsx)(sk.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,l,a,r,i,n,o,d,m;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.organization_id,children:(0,c.jsxs)(b.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:()=>h(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,c.jsx)(sS.Z,{children:e.organization_alias}),(0,c.jsx)(sS.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,c.jsx)(sS.Z,{children:eE(e.spend,4)}),(0,c.jsx)(sS.Z,{children:(null===(l=e.litellm_budget_table)||void 0===l?void 0:l.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:e.models.length>3?"px-0":"",children:(0,c.jsx)("div",{className:"flex flex-col",children:Array.isArray(e.models)?(0,c.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[e.models.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:T[e.organization_id||""]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{P(s=>({...s,[e.organization_id||""]:!s[e.organization_id||""]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.models.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),e.models.length>3&&!T[e.organization_id||""]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",e.models.length-3," ",e.models.length-3==1?"more model":"more models"]})}),T[e.organization_id||""]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:e.models.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:["TPM:"," ",(null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit)?null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit:"Unlimited",(0,c.jsx)("br",{}),"RPM:"," ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,c.jsx)(sS.Z,{children:"Admin"===t&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{h(e.organization_id),g(!0)}}),(0,c.jsx)(sZ.Z,{onClick:()=>M(e.organization_id),icon:W.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})})})]})})]})]})}),(0,c.jsx)(L.Z,{title:"Create Organization",visible:w,width:800,footer:null,onCancel:()=>{S(!1),C.resetFields()},children:(0,c.jsxs)(A.Z,{form:C,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,c.jsx)(sW.o,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),l&&l.length>0&&l.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this organization can access by default. Leave empty for access to all vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-4",help:"Select vector stores this organization can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>C.setFieldValue("allowed_vector_store_ids",e),value:C.getFieldValue("allowed_vector_store_ids"),accessToken:a||"",placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers and access groups this organization can access by default.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-4",help:"Select MCP servers and access groups this organization can access.",children:(0,c.jsx)(eO,{onChange:e=>C.setFieldValue("allowed_mcp_servers_and_groups",e),value:C.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:a||"",placeholder:"Select MCP servers and access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(b.Z,{type:"submit",children:"Create Organization"})})]})}),f?(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{_(!1),Z(null)},children:"Cancel"})]})]})]})}):(0,c.jsx)(c.Fragment,{})]}):(0,c.jsx)("div",{children:(0,c.jsxs)(k.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key"," ",(0,c.jsx)("a",{href:"https://www.litellm.ai/#pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lB=t(94789);let lV={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:""},lK={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 lG=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:t,handleAddSSOOk:l,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:i,handleInstructionsCancel:n,form:o,accessToken:m,ssoConfigured:u=!1}=e,[x,h]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(s&&m)try{let s=await (0,j.getSSOSettings)(m);if(console.log("Raw SSO data received:",s),s&&s.values){console.log("SSO values:",s.values),console.log("user_email from API:",s.values.user_email);let l=null;if(s.values.google_client_id)l="google";else if(s.values.microsoft_client_id)l="microsoft";else if(s.values.generic_client_id){var e,t;l=(null===(e=s.values.generic_authorization_endpoint)||void 0===e?void 0:e.includes("okta"))||(null===(t=s.values.generic_authorization_endpoint)||void 0===t?void 0:t.includes("auth0"))?"okta":"generic"}let a={sso_provider:l,proxy_base_url:s.values.proxy_base_url,user_email:s.values.user_email,...s.values};console.log("Setting form values:",a),o.resetFields(),setTimeout(()=>{o.setFieldsValue(a),console.log("Form values set, current form values:",o.getFieldsValue())},100)}}catch(e){console.error("Failed to load SSO settings:",e)}})()},[s,m,o]);let p=async e=>{if(!m){eo.Z.fromBackend("No access token available");return}try{await (0,j.updateSSOSettings)(m,e),r(e)}catch(e){console.error("Failed to save SSO settings:",e),eo.Z.fromBackend("Failed to save SSO settings")}},g=async()=>{if(!m){eo.Z.fromBackend("No access token available");return}try{await (0,j.updateSSOSettings)(m,{google_client_id:"",google_client_secret:"",microsoft_client_id:"",microsoft_client_secret:"",microsoft_tenant:"",generic_client_id:"",generic_client_secret:"",generic_authorization_endpoint:"",generic_token_endpoint:"",generic_userinfo_endpoint:"",proxy_base_url:"",user_email:"",sso_provider:""}),o.resetFields(),h(!1),l(),eo.Z.success("SSO settings cleared successfully")}catch(e){console.error("Failed to clear SSO settings:",e),eo.Z.fromBackend("Failed to clear SSO settings")}},f=e=>{let s=lK[e];return s?s.fields.map(e=>(0,c.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,c.jsx)(E.default.Password,{}):(0,c.jsx)(_.Z,{placeholder:e.placeholder})},e.name)):null};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(L.Z,{title:u?"Edit SSO Settings":"Add SSO",visible:s,width:800,footer:null,onOk:l,onCancel:a,children:(0,c.jsxs)(A.Z,{form:o,onFinish:p,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,c.jsx)(I.default,{children:Object.entries(lV).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[t&&(0,c.jsx)("img",{src:t,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,c.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,t=s("sso_provider");return t?f(t):null}}),(0,c.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,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,c.jsx)(_.Z,{})})]}),(0,c.jsxs)("div",{style:{textAlign:"right",marginTop:"10px",display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"8px"},children:[u&&(0,c.jsx)(P.ZP,{onClick:()=>h(!0),style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#5558eb",e.currentTarget.style.borderColor="#5558eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1",e.currentTarget.style.borderColor="#6366f1"},children:"Clear"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})]})]})}),(0,c.jsxs)(L.Z,{title:"Confirm Clear SSO Settings",visible:x,onOk:g,onCancel:()=>h(!1),okText:"Yes, Clear",cancelText:"Cancel",okButtonProps:{danger:!0,style:{backgroundColor:"#dc2626",borderColor:"#dc2626"}},children:[(0,c.jsx)("p",{children:"Are you sure you want to clear all SSO settings? This action cannot be undone."}),(0,c.jsx)("p",{children:"Users will no longer be able to login using SSO after this change."})]}),(0,c.jsxs)(L.Z,{title:"SSO Setup Instructions",visible:t,width:800,footer:null,onOk:i,onCancel:n,children:[(0,c.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{onClick:i,children:"Done"})})]})]})},lH=t(62272),lJ=t(92403),lY=t(29271),lW=t(34419),l$=e=>{let{accessToken:s,userID:t,proxySettings:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)("");(0,d.useEffect)(()=>{let e="";u(l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL?l.PROXY_BASE_URL:window.location.origin)},[l]);let x="".concat(m,"/scim/v2"),h=async e=>{if(!s||!t){eo.Z.fromBackend("You need to be logged in to create a SCIM token");return}try{i(!0);let l={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,j.keyCreateCall)(s,t,l);o(a),eo.Z.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),eo.Z.fromBackend("Failed to create SCIM token: "+(0,sx.O)(e))}finally{i(!1)}};return(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("div",{className:"flex items-center mb-4",children:(0,c.jsx)(S.Z,{children:"SCIM Configuration"})}),(0,c.jsx)(k.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,c.jsx)(lC.Z,{}),(0,c.jsxs)("div",{className:"space-y-8",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,c.jsxs)(S.Z,{className:"text-lg flex items-center",children:[(0,c.jsx)(lH.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,c.jsx)(k.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(_.Z,{value:x,disabled:!0,className:"flex-grow"}),(0,c.jsx)(C.CopyToClipboard,{text:x,onCopy:()=>eo.Z.success("URL copied to clipboard"),children:(0,c.jsxs)(b.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,c.jsx)(tR.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,c.jsxs)(S.Z,{className:"text-lg flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,c.jsx)(lB.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),n?(0,c.jsxs)(G.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,c.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,c.jsx)(lY.Z,{className:"h-5 w-5 mr-2"}),(0,c.jsx)(S.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,c.jsx)(k.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(_.Z,{value:n.key,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,c.jsx)(C.CopyToClipboard,{text:n.key,onCopy:()=>eo.Z.success("Token copied to clipboard"),children:(0,c.jsxs)(b.Z,{variant:"primary",className:"flex items-center",children:[(0,c.jsx)(tR.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,c.jsxs)(b.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,c.jsx)(lW.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,c.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,c.jsxs)(A.Z,{form:a,onFinish:h,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,c.jsx)(_.Z,{placeholder:"SCIM Access Token"})}),(0,c.jsx)(A.Z.Item,{children:(0,c.jsxs)(b.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lQ=e=>{let{accessToken:s,onSuccess:t}=e,[l]=A.Z.useForm(),[a,r]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(s)try{let e=await (0,j.getSSOSettings)(s);if(e&&e.values){let s=e.values.ui_access_mode,t={};s&&"object"==typeof s?t={ui_access_mode_type:s.type,restricted_sso_group:s.restricted_sso_group,sso_group_jwt_field:s.sso_group_jwt_field}:"string"==typeof s&&(t={ui_access_mode_type:s,restricted_sso_group:e.values.restricted_sso_group,sso_group_jwt_field:e.values.team_ids_jwt_field||e.values.sso_group_jwt_field}),l.setFieldsValue(t)}}catch(e){console.error("Failed to load UI access settings:",e)}})()},[s,l]);let i=async e=>{if(!s){eo.Z.fromBackend("No access token available");return}r(!0);try{let l;l="all_authenticated_users"===e.ui_access_mode_type?{ui_access_mode:"none"}:{ui_access_mode:{type:e.ui_access_mode_type,restricted_sso_group:e.restricted_sso_group,sso_group_jwt_field:e.sso_group_jwt_field}},await (0,j.updateSSOSettings)(s,l),t()}catch(e){console.error("Failed to save UI access settings:",e),eo.Z.fromBackend("Failed to save UI access settings")}finally{r(!1)}};return(0,c.jsxs)("div",{style:{padding:"16px"},children:[(0,c.jsx)("div",{style:{marginBottom:"16px"},children:(0,c.jsx)(k.Z,{style:{fontSize:"14px",color:"#6b7280"},children:"Configure who can access the UI interface and how group information is extracted from JWT tokens."})}),(0,c.jsxs)(A.Z,{form:l,onFinish:i,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"UI Access Mode",name:"ui_access_mode_type",tooltip:"Controls who can access the UI interface",children:(0,c.jsxs)(I.default,{placeholder:"Select access mode",children:[(0,c.jsx)(I.default.Option,{value:"all_authenticated_users",children:"All Authenticated Users"}),(0,c.jsx)(I.default.Option,{value:"restricted_sso_group",children:"Restricted SSO Group"})]})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.ui_access_mode_type!==s.ui_access_mode_type,children:e=>{let{getFieldValue:s}=e;return"restricted_sso_group"===s("ui_access_mode_type")?(0,c.jsx)(A.Z.Item,{label:"Restricted SSO Group",name:"restricted_sso_group",rules:[{required:!0,message:"Please enter the restricted SSO group"}],children:(0,c.jsx)(_.Z,{placeholder:"ui-access-group"})}):null}}),(0,c.jsx)(A.Z.Item,{label:"SSO Group JWT Field",name:"sso_group_jwt_field",tooltip:"JWT field name that contains team/group information. Use dot notation to access nested fields.",children:(0,c.jsx)(_.Z,{placeholder:"groups"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"16px"},children:(0,c.jsx)(P.ZP,{type:"primary",htmlType:"submit",loading:a,style:{backgroundColor:"#6366f1",borderColor:"#6366f1"},children:"Update UI Access Control"})})]})]})},lX=t(69870),l0=e=>{let{searchParams:s,accessToken:t,userID:l,showSSOBanner:a,premiumUser:r,proxySettings:i,userRole:n}=e,[o]=A.Z.useForm(),[u]=A.Z.useForm(),{Title:x,Paragraph:h}=en.default,[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(null),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(!1),[w,k]=(0,d.useState)(!1),[S,C]=(0,d.useState)(!1),[I,T]=(0,d.useState)(!1),[M,O]=(0,d.useState)(!1),[D,F]=(0,d.useState)(!1),[R,z]=(0,d.useState)(!1),[U,q]=(0,d.useState)(!1),[B,V]=(0,d.useState)(!1),[K,H]=(0,d.useState)(!1),[J,Y]=(0,d.useState)([]),[W,$]=(0,d.useState)(null),[Q,X]=(0,d.useState)(!1);(0,m.useRouter)();let[ee,es]=(0,d.useState)(null);console.log=function(){};let et=sb(),el="All IP Addresses Allowed",ea=et;ea+="/fallback/login";let er=async()=>{if(t&&r)try{let e=await (0,j.getSSOSettings)(t);if(console.log("SSO data:",e),e&&e.values){let s=e.values.google_client_id&&e.values.google_client_secret,t=e.values.microsoft_client_id&&e.values.microsoft_client_secret,l=e.values.generic_client_id&&e.values.generic_client_secret;X(s||t||l)}else X(!1)}catch(e){console.error("Error checking SSO configuration:",e),X(!1)}},ei=async()=>{try{if(!0!==r){eo.Z.fromBackend("This feature is only available for premium users. Please upgrade your account.");return}if(t){let e=await (0,j.getAllowedIPs)(t);Y(e&&e.length>0?e:[el])}else Y([el])}catch(e){console.error("Error fetching allowed IPs:",e),eo.Z.fromBackend("Failed to fetch allowed IPs ".concat(e)),Y([el])}finally{!0===r&&z(!0)}},ec=async e=>{try{if(t){await (0,j.addAllowedIP)(t,e.ip);let s=await (0,j.getAllowedIPs)(t);Y(s),eo.Z.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),eo.Z.fromBackend("Failed to add IP address ".concat(e))}finally{q(!1)}},ed=async e=>{$(e),V(!0)},em=async()=>{if(W&&t)try{await (0,j.deleteAllowedIP)(t,W);let e=await (0,j.getAllowedIPs)(t);Y(e.length>0?e:[el]),eo.Z.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),eo.Z.fromBackend("Failed to delete IP address ".concat(e))}finally{V(!1),$(null)}};(0,d.useEffect)(()=>{(async()=>{if(null!=t){let e=[],s=await (0,j.userGetAllUsersCall)(t,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let l=s.users;console.log("proxy viewers response: ".concat(l)),l.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(l));let a=(await (0,j.userGetAllUsersCall)(t,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),v(e),es(await (0,j.getPossibleUserRoles)(t))}})()},[t]),(0,d.useEffect)(()=>{er()},[t,r]);let eu=()=>{H(!1)};return console.log("admins: ".concat(null==f?void 0:f.length)),(0,c.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,c.jsx)(x,{level:4,children:"Admin Access "}),(0,c.jsx)(h,{children:"Go to 'Internal Users' page to add other admins."}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Security Settings"}),(0,c.jsx)(e0.Z,{children:"SCIM"}),(0,c.jsx)(e0.Z,{children:"Useful Links"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(x,{level:4,children:" ✨ Security Settings"}),(0,c.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem",marginLeft:"0.5rem"},children:[(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:()=>!0===r?O(!0):eo.Z.fromBackend("Only premium users can add SSO"),children:Q?"Edit SSO Settings":"Add SSO"})}),(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:ei,children:"Allowed IPs"})}),(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:()=>!0===r?H(!0):eo.Z.fromBackend("Only premium users can configure UI access control"),children:"UI Access Control"})})]})]}),(0,c.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,c.jsx)(lG,{isAddSSOModalVisible:M,isInstructionsModalVisible:D,handleAddSSOOk:()=>{O(!1),o.resetFields(),t&&r&&er()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{O(!1),F(!0)},handleInstructionsOk:()=>{F(!1),t&&r&&er()},handleInstructionsCancel:()=>{F(!1),t&&r&&er()},form:o,accessToken:t,ssoConfigured:Q}),(0,c.jsx)(L.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>z(!1),footer:[(0,c.jsx)(b.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,c.jsx)(b.Z,{onClick:()=>z(!1),children:"Close"},"close")],children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"IP Address"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Action"})]})}),(0,c.jsx)(sk.Z,{children:J.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e}),(0,c.jsx)(sS.Z,{className:"text-right",children:e!==el&&(0,c.jsx)(b.Z,{onClick:()=>ed(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,c.jsx)(L.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>q(!1),footer:null,children:(0,c.jsxs)(A.Z,{onFinish:ec,children:[(0,c.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,c.jsx)(E.default,{placeholder:"Enter IP address"})}),(0,c.jsx)(A.Z.Item,{children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,c.jsx)(L.Z,{title:"Confirm Delete",visible:B,onCancel:()=>V(!1),onOk:em,footer:[(0,c.jsx)(b.Z,{className:"mx-1",onClick:()=>em(),children:"Yes"},"delete"),(0,c.jsx)(b.Z,{onClick:()=>V(!1),children:"Close"},"close")],children:(0,c.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",W,"?"]})}),(0,c.jsx)(L.Z,{title:"UI Access Control Settings",visible:K,width:600,footer:null,onOk:eu,onCancel:()=>{H(!1)},children:(0,c.jsx)(lQ,{accessToken:t,onSuccess:()=>{eu(),eo.Z.success("UI Access Control settings updated successfully")}})})]}),(0,c.jsxs)(lB.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,c.jsxs)("a",{href:ea,target:"_blank",children:[(0,c.jsx)("b",{children:ea})," "]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l$,{accessToken:t,userID:l,proxySettings:i})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lX.Z,{accessToken:t,userRole:n||null})})]})]})]})};let{Title:l1}=en.default;var l2=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)([]);(0,d.useEffect)(()=>{i()},[s]);let i=async()=>{if(s){l(!0);try{let e=await (0,j.getEmailEventSettings)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),eo.Z.fromBackend(e)}finally{l(!1)}}},n=(e,s)=>{r(a.map(t=>t.event===e?{...t,enabled:s}:t))},o=async()=>{if(s)try{await (0,j.updateEmailEventSettings)(s,{settings:a}),eo.Z.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),eo.Z.fromBackend(e)}},m=async()=>{if(s)try{await (0,j.resetEmailEventSettings)(s),eo.Z.success("Email event settings reset to defaults"),i()}catch(e){console.error("Failed to reset email event settings:",e),eo.Z.fromBackend(e)}},u=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(l1,{level:4,children:"Email Notifications"}),(0,c.jsx)(k.Z,{children:"Select which events should trigger email notifications."}),(0,c.jsx)(K.Z,{}),t?(0,c.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,c.jsx)(lI.Z,{size:"large"})}):(0,c.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ts.Z,{checked:e.enabled,onChange:s=>n(e.event,s.target.checked)}),(0,c.jsxs)("div",{className:"ml-3",children:[(0,c.jsx)(k.Z,{children:e.event}),(0,c.jsx)("div",{className:"text-sm text-gray-500 block",children:u(e.event)})]})]},e.event))}),(0,c.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,c.jsx)(b.Z,{onClick:o,disabled:t,children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:m,variant:"secondary",disabled:t,children:"Reset to Defaults"})]})]})};let{Title:l4}=en.default;var l5=e=>{let{accessToken:s,premiumUser:t,alerts:l}=e,a=async()=>{if(!s)return;let e={};l.filter(e=>"email"===e.name).forEach(s=>{var t;Object.entries(null!==(t=s.variables)&&void 0!==t?t:{}).forEach(s=>{let[t,l]=s,a=document.querySelector('input[name="'.concat(t,'"]'));a&&a.value&&(e[t]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{await (0,j.setCallbacksCall)(s,{general_settings:{alerting:["email"]},environment_variables:e}),eo.Z.success("Email settings updated successfully")}catch(e){eo.Z.fromBackend(e)}};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mt-6 mb-6",children:(0,c.jsx)(l2,{accessToken:s})}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(l4,{level:4,children:"Email Server Settings"}),(0,c.jsxs)(k.Z,{children:[(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,c.jsx)("br",{})]}),(0,c.jsx)("div",{className:"flex w-full",children:l.filter(e=>"email"===e.name).map((e,s)=>{var l;return(0,c.jsx)(sS.Z,{children:(0,c.jsx)("ul",{children:(0,c.jsx)(y.Z,{numItems:2,children:Object.entries(null!==(l=e.variables)&&void 0!==l?l:{}).map(e=>{let[s,l]=e;return(0,c.jsxs)("li",{className:"mx-2 my-2",children:[!0!=t&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,c.jsxs)("div",{children:[(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,c.jsxs)(k.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,c.jsx)(_.Z,{name:s,defaultValue:l,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-2",children:s}),(0,c.jsx)(_.Z,{name:s,defaultValue:l,type:"password",style:{width:"400px"}})]}),(0,c.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,c.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,c.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,c.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:async()=>{if(s)try{await (0,j.serviceHealthCheck)(s,"email"),eo.Z.success("Email test triggered. Check your configured email inbox/logs.")}catch(e){eo.Z.fromBackend(e)}},className:"mx-2",children:"Test Email Alerts"})]})]})},l6=e=>{let{alertingSettings:s,handleInputChange:t,handleResetField:l,handleSubmit:a,premiumUser:r}=e,[i]=A.Z.useForm();return(0,c.jsxs)(A.Z,{form:i,onFinish:()=>{console.log("INSIDE ONFINISH");let e=i.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,t]=e;return"boolean"!=typeof t&&(""===t||null==t)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{align:"center",children:[(0,c.jsx)(k.Z,{children:e.field_name}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,c.jsx)(A.Z.Item,{name:e.field_name,children:(0,c.jsx)(sS.Z,{children:"Integer"===e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>t(e.field_name,s)}):"Boolean"===e.field_type?(0,c.jsx)(tB.Z,{checked:e.field_value,onChange:s=>t(e.field_name,s)}):(0,c.jsx)(E.default,{value:e.field_value,onChange:s=>t(e.field_name,s)})})}):(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{className:"flex items-center justify-center",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,c.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,c.jsx)(sS.Z,{children:"Integer"===e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>t(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,c.jsx)(tB.Z,{checked:e.field_value,onChange:s=>{t(e.field_name,s),i.setFieldsValue({[e.field_name]:s})}}):(0,c.jsx)(E.default,{value:e.field_value,onChange:s=>t(e.field_name,s)})})}),(0,c.jsx)(sS.Z,{children:!0==e.stored_in_db?(0,c.jsx)(eX.Z,{icon:eb.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(sZ.Z,{icon:W.Z,color:"red",onClick:()=>l(e.field_name,s),children:"Reset"})})]},s)),(0,c.jsx)("div",{children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l3=e=>{let{accessToken:s,premiumUser:t}=e,[l,a]=(0,d.useState)([]);return(0,d.useEffect)(()=>{s&&(0,j.alertingSettingsCall)(s).then(e=>{a(e)})},[s]),(0,c.jsx)(l6,{alertingSettings:l,handleInputChange:(e,s)=>{let t=l.map(t=>t.field_name===e?{...t,field_value:s}:t);console.log("updatedSettings: ".concat(JSON.stringify(t))),a(t)},handleResetField:(e,t)=>{if(s)try{let s=l.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let t={};l.forEach(e=>{t[e.field_name]=e.field_value});let a={...e,...t};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.updateConfigFieldSetting)(s,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.updateConfigFieldSetting)(s,"alerting",["slack"]):(0,j.updateConfigFieldSetting)(s,"alerting",[])),eo.Z.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:t})},l8=t(38994);let{Title:l7,Paragraph:l9}=en.default;var ae=e=>{let{accessToken:s,userRole:t,userID:l,premiumUser:a}=e,[r,n]=(0,d.useState)([]),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(!1),[h]=A.Z.useForm(),[p]=A.Z.useForm(),[g,f]=(0,d.useState)(null),[v,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)({}),[S,C]=(0,d.useState)([]),[T,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)([]),[F,R]=(0,d.useState)([]),[z,U]=(0,d.useState)(!1),[q,B]=(0,d.useState)(null),[V,K]=(0,d.useState)(!1),[H,J]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(z&&q){let e=Object.fromEntries(Object.entries(q.variables||{}).map(e=>{let[s,t]=e;return[s,null!=t?t:""]}));p.setFieldsValue(e)}},[z,q,p]);let Y=e=>{S.includes(e)?C(S.filter(s=>s!==e)):C([...S,e])},Q={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,d.useEffect)(()=>{s&&t&&l&&(0,j.getCallbacksCall)(s,l,t).then(e=>{n(e.callbacks),D(e.available_callbacks);let s=e.alerts;if(s&&s.length>0){let e=s[0],t=e.variables.SLACK_WEBHOOK_URL;C(e.active_alerts),N(t),w(e.alerts_to_webhook)}m(s)})},[s,t,l]);let X=e=>S&&S.includes(e),ee=async e=>{if(!s||!q)return;let a={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(a[s]=t)});let r={environment_variables:e,litellm_settings:{success_callback:[q.name]}};try{if(await (0,j.setCallbacksCall)(s,r),eo.Z.success("Callback updated successfully"),U(!1),p.resetFields(),B(null),l&&t){let e=await (0,j.getCallbacksCall)(s,l,t);n(e.callbacks)}}catch(e){eo.Z.fromBackend(e)}},es=async e=>{if(!s)return;let a=null==e?void 0:e.callback,r={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(r[s]=t)});try{await (0,j.setCallbacksCall)(s,{environment_variables:e,litellm_settings:{success_callback:[a]}}),eo.Z.success("Callback ".concat(a," added successfully")),M(!1),h.resetFields(),f(null),R([]);let r=await (0,j.getCallbacksCall)(s,l||"",t||"");n(r.callbacks)}catch(e){eo.Z.fromBackend(e)}},el=e=>{f(e.litellm_callback_name),e&&e.litellm_callback_params?R(e.litellm_callback_params):R([])},ea=async()=>{if(!s)return;let e={};Object.entries(Q).forEach(s=>{let[t,l]=s,a=document.querySelector('input[name="'.concat(t,'"]')),r=(null==a?void 0:a.value)||"";e[t]=r});try{await (0,j.setCallbacksCall)(s,{general_settings:{alert_to_webhook_url:e,alert_types:S}})}catch(e){eo.Z.fromBackend(e)}eo.Z.success("Alerts updated successfully")},er=e=>{J(e),K(!0)},en=async()=>{if(H&&s)try{if(await (0,j.deleteCallback)(s,H),eo.Z.success("Callback ".concat(H," deleted successfully")),l&&t){let e=await (0,j.getCallbacksCall)(s,l,t);n(e.callbacks)}K(!1),J(null)}catch(e){console.error("Failed to delete callback:",e),eo.Z.fromBackend(e)}};return s?(0,c.jsxs)("div",{className:"w-full mx-4",children:[(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Logging Callbacks"}),(0,c.jsx)(e0.Z,{value:"2",children:"Alerting Types"}),(0,c.jsx)(e0.Z,{value:"3",children:"Alerting Settings"}),(0,c.jsx)(e0.Z,{value:"4",children:"Email Alerts"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(l7,{level:4,children:"Active Logging Callbacks"}),(0,c.jsx)(y.Z,{numItems:2,children:(0,c.jsx)(G.Z,{className:"max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sI.Z,{children:"Callback Name"})})}),(0,c.jsx)(sk.Z,{children:r.map((e,t)=>(0,c.jsxs)(sA.Z,{className:"flex justify-between",children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.name})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"flex justify-between",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{B(e),U(!0)}}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>er(e.name),className:"text-red-500 hover:text-red-700 cursor-pointer"}),(0,c.jsx)(b.Z,{onClick:async()=>{try{await (0,j.serviceHealthCheck)(s,e.name),eo.Z.success("Health check triggered")}catch(e){eo.Z.fromBackend((0,sx.O)(e))}},className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},t))})]})})}),(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(k.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,c.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{}),(0,c.jsx)(sI.Z,{}),(0,c.jsx)(sI.Z,{children:"Slack Webhook URL"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(Q).map((e,s)=>{let[t,l]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:"region_outage_alerts"==t?a?(0,c.jsx)(tB.Z,{id:"switch",name:"switch",checked:X(t),onChange:()=>Y(t)}):(0,c.jsx)(b.Z,{className:"flex items-center justify-center",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,c.jsx)(tB.Z,{id:"switch",name:"switch",checked:X(t),onChange:()=>Y(t)})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:l})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(_.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:v})})]},s)})})]}),(0,c.jsx)(b.Z,{size:"xs",className:"mt-2",onClick:ea,children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:async()=>{try{await (0,j.serviceHealthCheck)(s,"slack"),eo.Z.success("Alert test triggered. Test request to slack made - check logs/alerts on slack to verify")}catch(e){eo.Z.fromBackend((0,sx.O)(e))}},className:"mx-2",children:"Test Alerts"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l3,{accessToken:s,premiumUser:a})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l5,{accessToken:s,premiumUser:a,alerts:o})})]})]})}),(0,c.jsxs)(L.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>{M(!1),f(null),R([])},footer:null,children:[(0,c.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:[" ","LiteLLM Docs: Logging"]}),(0,c.jsx)(A.Z,{form:h,onFinish:es,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(l8.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,c.jsx)(I.default,{onChange:e=>{let s=O[e];s&&el(s)},children:Object.entries(i).map(e=>{var s;let[t,l]=e;return(0,c.jsx)(ei.Z,{value:$[t],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(null===(s=et[l])||void 0===s?void 0:s.logo)?(0,c.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:(0,c.jsx)("img",{src:et[l].logo,alt:"".concat(t," logo"),className:"w-5 h-5",onError:e=>{e.currentTarget.style.display="none"}})}):(0,c.jsx)("div",{className:"w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",children:l.charAt(0).toUpperCase()}),(0,c.jsx)("span",{children:l})]})},l)})})}),F&&F.map(e=>(0,c.jsx)(l8.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,c.jsx)(E.default.Password,{})},e)),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,c.jsx)(L.Z,{visible:z,width:800,title:"Edit ".concat(null==q?void 0:q.name," Settings"),onCancel:()=>{U(!1),B(null)},footer:null,children:(0,c.jsxs)(A.Z,{form:p,onFinish:ee,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(c.Fragment,{children:q&&q.variables&&Object.entries(q.variables).map(e=>{let[s]=e;return(0,c.jsx)(l8.Z,{label:s,name:s,rules:[{required:!0,message:"Please enter the value for ".concat(s)}],children:(0,c.jsx)(E.default.Password,{})},s)})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,c.jsx)(L.Z,{title:"Confirm Delete",visible:V,onOk:en,onCancel:()=>{K(!1),J(null)},okText:"Delete",cancelText:"Cancel",okButtonProps:{danger:!0},children:(0,c.jsxs)("p",{children:["Are you sure you want to delete the callback - ",H,"? This action cannot be undone."]})})]}):null},as=t(54250),at=t(70450),al=e=>{let{models:s,accessToken:t,routerSettings:l,setRouterSettings:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(""),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{try{let e=await eU(t);console.log("Fetched models for fallbacks:",e),x(e)}catch(e){console.error("Error fetching model info for fallbacks:",e)}})()},[t]);let g=()=>{n(!1),r.resetFields(),p([]),m("")};return(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{className:"mx-auto",onClick:()=>n(!0),icon:()=>(0,c.jsx)("span",{className:"mr-1",children:"+"}),children:"Add Fallbacks"}),(0,c.jsx)(L.Z,{title:(0,c.jsx)("div",{className:"pb-4 border-b border-gray-100",children:(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Fallbacks"})}),open:i,width:900,footer:null,onOk:()=>{n(!1),r.resetFields(),p([]),m("")},onCancel:g,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsxs)("div",{className:"mt-6",children:[(0,c.jsx)("div",{className:"mb-6",children:(0,c.jsx)("p",{className:"text-gray-600",children:"Configure fallback models to improve reliability. When the primary model fails or is unavailable, requests will automatically route to the specified fallback models in order."})}),(0,c.jsxs)(A.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:i}=e,o=[...l.fallbacks||[],{[s]:i}],c={...l,fallbacks:o};console.log(c);try{(0,j.setCallbacksCall)(t,{router_settings:c}),a(c)}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}eo.Z.success("router settings updated successfully"),n(!1),r.resetFields(),p([]),m("")},layout:"vertical",className:"space-y-6",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Primary Model ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"model_name",rules:[{required:!0,message:"Please select the primary model that needs fallbacks"}],className:"!mb-0",children:[(0,c.jsx)(as.Z,{placeholder:"Select the model that needs fallback protection",value:o,onValueChange:e=>{m(e);let s=h.filter(s=>s!==e);p(s),r.setFieldValue("models",s),r.setFieldValue("model_name",e)},children:Array.from(new Set(u.map(e=>e.model_group))).map((e,s)=>(0,c.jsx)(at.Z,{value:e,children:e},s))}),(0,c.jsx)("p",{className:"text-sm text-gray-500 mt-1",children:"This is the primary model that users will request"})]}),(0,c.jsx)("div",{className:"border-t border-gray-200 my-6"}),(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Fallback Models (select multiple) ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"models",rules:[{required:!0,message:"Please select at least one fallback model"}],className:"!mb-0",children:[(0,c.jsxs)("div",{className:"space-y-3",children:[h.length>0&&(0,c.jsxs)("div",{className:"border border-gray-200 rounded-lg p-3 bg-gray-50",children:[(0,c.jsx)("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Fallback Order:"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:h.map((e,s)=>(0,c.jsxs)("div",{className:"flex items-center bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm",children:[(0,c.jsxs)("span",{className:"font-medium mr-2",children:[s+1,"."]}),(0,c.jsx)("span",{children:e}),(0,c.jsx)("button",{type:"button",onClick:()=>{let s=h.filter(s=>s!==e);p(s),r.setFieldValue("models",s)},className:"ml-2 text-blue-600 hover:text-blue-800",children:"\xd7"})]},e))})]}),(0,c.jsx)(as.Z,{placeholder:"Add a fallback model",value:"",onValueChange:e=>{if(e&&!h.includes(e)){let s=[...h,e];p(s),r.setFieldValue("models",s)}},children:Array.from(new Set(u.map(e=>e.model_group))).filter(e=>e!==o&&!h.includes(e)).sort().map(e=>(0,c.jsx)(at.Z,{value:e,children:e},e))})]}),(0,c.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:[(0,c.jsx)("strong",{children:"Order matters:"})," Models will be tried in the order shown above (1st, 2nd, 3rd, etc.)"]})]})]}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:g,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",type:"submit",children:"Add Fallbacks"})]})]})]})})]})},aa=t(26433);async function ar(e,s){console.log=function(){},console.log("isLocal:",!1);let t=window.location.origin,l=new aa.ZP.OpenAI({apiKey:s,baseURL:t,dangerouslyAllowBrowser:!0});try{let s=await l.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});eo.Z.success((0,c.jsxs)("span",{children:["Test model=",(0,c.jsx)("strong",{children:e}),", received model=",(0,c.jsx)("strong",{children:s.model}),". See"," ",(0,c.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e))}}let ai={ttl:3600,lowest_latency_buffer:0},an=e=>{let{selectedStrategy:s,strategyArgs:t,paramExplanation:l}=e;return(0,c.jsxs)(N.Z,{children:[(0,c.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,c.jsx)(Z.Z,{children:"latency-based-routing"==s?(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(t).map(e=>{let[s,t]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:s}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:l[s]})]}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(_.Z,{name:s,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},s)})})]})}):(0,c.jsx)(k.Z,{children:"No specific settings"})})]})};var ao=e=>{let{accessToken:s,userRole:t,userID:l,modelData:a}=e,[r,i]=(0,d.useState)({}),[n,o]=(0,d.useState)({}),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,d.useState)(null),[N,Z]=(0,d.useState)(null),[w,C]=(0,d.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,d.useEffect)(()=>{s&&t&&l&&((0,j.getCallbacksCall)(s,l,t).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,i(s)}),(0,j.getGeneralSettingsCall)(s).then(e=>{u(e)}))},[s,t,l]);let L=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let t=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),l={...r,fallbacks:t};try{await (0,j.setCallbacksCall)(s,{router_settings:l}),i(l),eo.Z.success("Router settings updated successfully")}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}},T=(e,s)=>{u(m.map(t=>t.field_name===e?{...t,field_value:s}:t))},P=(e,t)=>{if(!s)return;let l=m[t].field_value;if(null!=l&&void 0!=l)try{(0,j.updateConfigFieldSetting)(s,e,l);let t=m.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);u(t)}catch(e){}},E=(e,t)=>{if(s)try{(0,j.deleteConfigFieldSetting)(s,e);let t=m.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);u(t)}catch(e){}},M=e=>{if(!s)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[s,t]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var l;return[s,(null===(l=document.querySelector('input[name="'.concat(s,'"]')))||void 0===l?void 0:l.value)||t]}if("routing_strategy"==s)return[s,N];if("routing_strategy_args"==s&&"latency-based-routing"==N){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),t=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==t?void 0:t.value)&&(e.ttl=Number(t.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",t);try{(0,j.setCallbacksCall)(s,{router_settings:t})}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}eo.Z.success("router settings updated successfully")};return s?(0,c.jsx)("div",{className:"w-full mx-4",children:(0,c.jsxs)(e1.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Loadbalancing"}),(0,c.jsx)(e0.Z,{value:"2",children:"Fallbacks"}),(0,c.jsx)(e0.Z,{value:"3",children:"General"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,c.jsx)(S.Z,{children:"Router Settings"}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(r).filter(e=>{let[s,t]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,t]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:s}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[s]})]}),(0,c.jsx)(sS.Z,{children:"routing_strategy"==s?(0,c.jsxs)(eQ.Z,{defaultValue:t,className:"w-full max-w-md",onValueChange:Z,children:[(0,c.jsx)(ei.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,c.jsx)(ei.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,c.jsx)(ei.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,c.jsx)(_.Z,{name:s,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},s)})})]}),(0,c.jsx)(an,{selectedStrategy:N,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:ai,paramExplanation:I})]}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>M(r),children:"Save Changes"})})]})}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Model Name"}),(0,c.jsx)(sI.Z,{children:"Fallbacks"})]})}),(0,c.jsx)(sk.Z,{children:r.fallbacks&&r.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[l,a]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:l}),(0,c.jsx)(sS.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{onClick:()=>ar(l,s),children:"Test Fallback"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>L(l)})})]},t.toString()+l)}))})]}),(0,c.jsx)(al,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:i})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"}),(0,c.jsx)(sI.Z,{children:"Status"}),(0,c.jsx)(sI.Z,{children:"Action"})]})}),(0,c.jsx)(sk.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:e.field_name}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,c.jsx)(sS.Z,{children:"Integer"==e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>T(e.field_name,s)}):null}),(0,c.jsx)(sS.Z,{children:!0==e.stored_in_db?(0,c.jsx)(eX.Z,{icon:eb.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(b.Z,{onClick:()=>P(e.field_name,s),children:"Update"}),(0,c.jsx)(sZ.Z,{icon:W.Z,color:"red",onClick:()=>E(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ac=e=>{let{isModalVisible:s,accessToken:t,setIsModalVisible:l,setBudgetList:a}=e,[r]=A.Z.useForm(),i=async e=>{if(null!=t&&void 0!=t)try{eo.Z.info("Making API Call");let s=await (0,j.budgetCreateCall)(t,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),eo.Z.success("Budget Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};return(0,c.jsx)(L.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{l(!1),r.resetFields()},onCancel:()=>{l(!1),r.resetFields()},children:(0,c.jsxs)(A.Z,{form:r,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ad=e=>{let{isModalVisible:s,accessToken:t,setIsModalVisible:l,setBudgetList:a,existingBudget:r,handleUpdateCall:i}=e;console.log("existingBudget",r);let[n]=A.Z.useForm();(0,d.useEffect)(()=>{n.setFieldsValue(r)},[r,n]);let o=async e=>{if(null!=t&&void 0!=t)try{eo.Z.info("Making API Call"),l(!0);let s=await (0,j.budgetUpdateCall)(t,e);a(e=>e?[...e,s]:[s]),eo.Z.success("Budget Updated"),n.resetFields(),i()}catch(e){console.error("Error creating the key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};return(0,c.jsx)(L.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{l(!1),n.resetFields()},onCancel:()=>{l(!1),n.resetFields()},children:(0,c.jsxs)(A.Z,{form:n,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})},am=t(17906),au=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)(!1),[a,r]=(0,d.useState)(!1),[i,n]=(0,d.useState)(null),[o,m]=(0,d.useState)([]);(0,d.useEffect)(()=>{s&&(0,j.getBudgetList)(s).then(e=>{m(e)})},[s]);let u=async(e,t)=>{console.log("budget_id",e),null!=s&&(n(o.find(s=>s.budget_id===e)||null),r(!0))},x=async(e,t)=>{if(null==s)return;eo.Z.info("Request made"),await (0,j.budgetDeleteCall)(s,e);let l=[...o];l.splice(t,1),m(l),eo.Z.success("Budget Deleted.")},h=async()=>{null!=s&&(0,j.getBudgetList)(s).then(e=>{m(e)})};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)(b.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>l(!0),children:"+ Create Budget"}),(0,c.jsx)(ac,{accessToken:s,isModalVisible:t,setIsModalVisible:l,setBudgetList:m}),i&&(0,c.jsx)(ad,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:m,existingBudget:i,handleUpdateCall:h}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Create a budget to assign to customers."}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Budget ID"}),(0,c.jsx)(sI.Z,{children:"Max Budget"}),(0,c.jsx)(sI.Z,{children:"TPM"}),(0,c.jsx)(sI.Z,{children:"RPM"})]})}),(0,c.jsx)(sk.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.budget_id}),(0,c.jsx)(sS.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,c.jsx)(sS.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,c.jsx)(sS.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>u(e.budget_id,s)}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>x(e.budget_id,s)})]},s))})]})]}),(0,c.jsxs)("div",{className:"mt-5",children:[(0,c.jsx)(k.Z,{className:"text-base",children:"How to use budget id"}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Assign Budget to Customer"}),(0,c.jsx)(e0.Z,{children:"Test it (Curl)"}),(0,c.jsx)(e0.Z,{children:"Test it (OpenAI SDK)"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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)'})})]})]})]})]})},ax=t(77398),ah=t.n(ax);let ap=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"}},ag=e=>{let{utcTime:s}=e;return(0,c.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:ap(s)})},aj=(e,s)=>{var t,l;return(null===(l=e.metadata)||void 0===l?void 0:null===(t=l.mcp_tool_call_metadata)||void 0===t?void 0:t.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?(0,sU.dr)(s).logo:""},af=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,c.jsx)(()=>{let[e,t]=d.useState(s.getIsExpanded()),l=d.useCallback(()=>{t(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,c.jsx)("button",{onClick:l,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,c.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,c.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,c.jsx)(ag,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),t=e.row.original.onSessionClick;return(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==t?void 0:t(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,c.jsxs)("span",{children:["$",eE(e.getValue()||0,6)]})},{header:"Duration (s)",accessorKey:"duration",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),t=e.row.original.onKeyHashClick;return(0,c.jsx)(V.Z,{title:s,children:(0,c.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==t?void 0:t(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,t=s.custom_llm_provider,l=String(e.getValue()||"");return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,c.jsx)("img",{src:aj(s,t),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)(V.Z,{title:l,children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:l})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,c.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,c.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let t=Object.entries(s),l=t[0],a=t.slice(1);return(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,c.jsx)(V.Z,{title:(0,c.jsx)("div",{className:"flex flex-col gap-1",children:t.map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[s,": ",String(t)]},s)})}),children:(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l[0],": ",String(l[1]),a.length>0&&" +".concat(a.length)]})})})}}],av=e=>(0,c.jsx)(eX.Z,{color:"gray",className:"flex items-center gap-1",children:(0,c.jsx)("span",{className:"whitespace-nowrap text-xs",children:e})}),ay=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,c.jsx)(()=>{let[e,t]=d.useState(s.getIsExpanded()),l=d.useCallback(()=>{t(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,c.jsx)("button",{onClick:l,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,c.jsx)("svg",{className:"w-4 h-4 transform transition-transform ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,c.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Timestamp",accessorKey:"updated_at",cell:e=>(0,c.jsx)(ag,{utcTime:e.getValue()})},{header:"Table Name",accessorKey:"table_name",cell:e=>{let s=e.getValue(),t=s;switch(s){case"LiteLLM_VerificationToken":t="Keys";break;case"LiteLLM_TeamTable":t="Teams";break;case"LiteLLM_OrganizationTable":t="Organizations";break;case"LiteLLM_UserTable":t="Users";break;case"LiteLLM_ProxyModelTable":t="Models";break;default:t=s}return(0,c.jsx)("span",{children:t})}},{header:"Action",accessorKey:"action",cell:e=>(0,c.jsx)("span",{children:av(e.getValue())})},{header:"Changed By",accessorKey:"changed_by",cell:e=>{let s=e.row.original.changed_by,t=e.row.original.changed_by_api_key;return(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsx)("div",{className:"font-medium",children:s}),t&&(0,c.jsx)(V.Z,{title:t,children:(0,c.jsxs)("div",{className:"text-xs text-muted-foreground max-w-[15ch] truncate",children:[" ",t]})})]})}},{header:"Affected Item ID",accessorKey:"object_id",cell:e=>(0,c.jsx)(()=>{let s=e.getValue(),[t,l]=(0,d.useState)(!1);if(!s)return(0,c.jsx)(c.Fragment,{children:"-"});let a=async()=>{try{await navigator.clipboard.writeText(String(s)),l(!0),setTimeout(()=>l(!1),1500)}catch(e){console.error("Failed to copy object ID: ",e)}};return(0,c.jsx)(V.Z,{title:t?"Copied!":String(s),children:(0,c.jsx)("span",{className:"max-w-[20ch] truncate block cursor-pointer hover:text-blue-600",onClick:a,children:String(s)})})},{})}],ab=async(e,s,t,l)=>{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),l.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let l=await (0,j.uiSpendLogDetailsCall)(t,e.request_id,s);return console.log("Received details for",e.request_id,":",l?"success":"failed"),l},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}};function a_(e){let{row:s,hasMessages:t,hasResponse:l,hasError:a,errorInfo:r,getRawRequest:i,formattedResponse:n}=e,o=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0;{let s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.focus(),s.select();let t=document.execCommand("copy");if(document.body.removeChild(s),!t)throw Error("execCommand failed");return!0}}catch(e){return console.error("Copy failed:",e),!1}},d=async()=>{await o(JSON.stringify(i(),null,2))?eo.Z.success("Request copied to clipboard"):eo.Z.fromBackend("Failed to copy request")},m=async()=>{await o(JSON.stringify(n(),null,2))?eo.Z.success("Response copied to clipboard"):eo.Z.fromBackend("Failed to copy response")};return(0,c.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 w-full max-w-full overflow-hidden box-border",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,c.jsx)("button",{onClick:d,className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-96 w-full max-w-full box-border",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all w-full max-w-full overflow-hidden break-words",children:JSON.stringify(i(),null,2)})})]}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,c.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,c.jsx)("button",{onClick:m,className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!l,children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50 w-full max-w-full box-border",children:l?(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all w-full max-w-full overflow-hidden break-words",children:JSON.stringify(n(),null,2)}):(0,c.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let aN=e=>{var s;let{errorInfo:t}=e,[l,a]=d.useState({}),[r,i]=d.useState(!1),n=e=>{a(s=>({...s,[e]:!s[e]}))},o=t.traceback&&(s=t.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let t=e[1],l=e[2],a=t.split("/").pop()||t,r=e.index||0,i=s.indexOf('File "',r+1),n=i>-1?s.substring(r,i).trim():s.substring(r).trim(),o=n.split("\n"),c="";return o.length>1&&(c=o[o.length-1].trim()),{filePath:t,fileName:a,lineNumber:l,code:c,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"p-4 border-b",children:(0,c.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,c.jsx)("span",{className:"text-red-700",children:t.error_class||"Unknown Error"})]}),(0,c.jsxs)("div",{className:"flex mt-2",children:[(0,c.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,c.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:t.error_message||"Unknown error occurred"})]})]}),t.traceback&&(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,c.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsx)("button",{onClick:()=>{let e=!r;if(i(e),o.length>0){let s={};o.forEach((t,l)=>{s[l]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,c.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(t.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,c.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,c.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,c.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,c.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>n(s),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,c.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,c.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,c.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,c.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(l[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(l[s]||!1)&&e.code&&(0,c.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})]},s))})]})]})]})},aZ=e=>{let{show:s}=e;return s?(0,c.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,c.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,c.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,c.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,c.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,c.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,c.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,c.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,c.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,c.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var aw=t(35829);let ak=e=>{let{sessionId:s,logs:t,onBack:l}=e,[a,r]=(0,d.useState)(null),[i,n]=(0,d.useState)({}),o=t.reduce((e,s)=>e+(s.spend||0),0),m=t.reduce((e,s)=>e+(s.total_tokens||0),0),u=t.reduce((e,s)=>{var t,l;return e+((null===(l=s.metadata)||void 0===l?void 0:null===(t=l.additional_usage_values)||void 0===t?void 0:t.cache_read_input_tokens)||0)},0),x=t.reduce((e,s)=>{var t,l;return e+((null===(l=s.metadata)||void 0===l?void 0:null===(t=l.additional_usage_values)||void 0===t?void 0:t.cache_creation_input_tokens)||0)},0),h=m+u+x,p=t.length>0?new Date(t[0].startTime):new Date;(((t.length>0?new Date(t[t.length-1].endTime):new Date).getTime()-p.getTime())/1e3).toFixed(2),t.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0}));let g=async(e,s)=>{await eM(e)&&(n(e=>({...e,[s]:!0})),setTimeout(()=>{n(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:l,className:"mb-4",children:"Back to All Logs"}),(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:i["session-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>g(s,"session-id"),className:"left-2 z-10 transition-all duration-200 ".concat(i["session-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]}),(0,c.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(aw.Z,{children:t.length})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Cost"}),(0,c.jsxs)(aw.Z,{children:["$",eE(o,6)]})]}),(0,c.jsx)(V.Z,{title:(0,c.jsxs)("div",{className:"text-white min-w-[200px]",children:[(0,c.jsx)("div",{className:"text-lg font-medium mb-3",children:"Usage breakdown"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-medium mb-2",children:"Input usage:"}),(0,c.jsxs)("div",{className:"space-y-2 text-sm text-gray-300",children:[(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(t.reduce((e,s)=>e+(s.prompt_tokens||0),0))})]}),u>0&&(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input_cached_tokens:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(u)})]}),x>0&&(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input_cache_creation_tokens:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(x)})]})]})]}),(0,c.jsxs)("div",{className:"border-t border-gray-600 pt-3",children:[(0,c.jsx)("div",{className:"text-base font-medium mb-2",children:"Output usage:"}),(0,c.jsx)("div",{className:"space-y-2 text-sm text-gray-300",children:(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"output:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(t.reduce((e,s)=>e+(s.completion_tokens||0),0))})]})})]}),(0,c.jsx)("div",{className:"border-t border-gray-600 pt-3",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-base font-medium",children:"Total usage:"}),(0,c.jsx)("span",{className:"text-sm text-gray-300",children:eE(h)})]})})]})]}),placement:"top",overlayStyle:{minWidth:"300px"},children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)("span",{className:"text-gray-400 text-sm",children:"ⓘ"})]}),(0,c.jsx)(aw.Z,{children:eE(h)})]})})]}),(0,c.jsx)(S.Z,{children:"Session Logs"}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(lx,{columns:af,data:t,renderSubComponent:aq,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function aS(e){let{data:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)({});if(!s||0===s.length)return null;let i=e=>new Date(1e3*e).toLocaleString(),n=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let t="".concat(e,"-").concat(s);r(e=>({...e,[t]:!e[t]}))};return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>l(!t),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:t?"Click to collapse":"Click to expand"})]}),t&&(0,c.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,c.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,c.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,c.jsx)("span",{className:"font-mono",children:e.query})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,c.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,c.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:t}=(0,sU.dr)(e.custom_llm_provider);return(0,c.jsxs)(c.Fragment,{children:[s&&(0,c.jsx)("img",{src:s,alt:"".concat(t," logo"),className:"h-5 w-5 mr-2"}),t]})})()})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:i(e.start_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:i(e.end_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsx)("span",{children:n(e.start_time,e.end_time)})]})]})]})}),(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,c.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,t)=>{let l=a["".concat(s,"-").concat(t)]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,t),children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsxs)("span",{className:"font-medium mr-2",children:["Result ",t+1]}),(0,c.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,c.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),l&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,c.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,c.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},t)})})]},s))})]})}let aC=e=>e>=.8?"text-green-600":"text-yellow-600";var aI=e=>{let{entities:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)({}),i=e=>{r(s=>({...s,[e]:!s[e]}))};return s&&0!==s.length?(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>l(!t),children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.length,")"]})]}),t&&(0,c.jsx)("div",{className:"space-y-2",children:s.map((e,s)=>{let t=a[s]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>i(s),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,c.jsxs)("span",{className:"font-mono ".concat(aC(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,c.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),t&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,c.jsx)("span",{children:e.entity_type})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,c.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,c.jsx)("span",{className:aC(e.score),children:e.score.toFixed(2)})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,c.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,c.jsxs)("div",{className:"flex overflow-hidden",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,c.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,c.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]}):null};let aA=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"slate";return(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat({green:"bg-green-100 text-green-800",red:"bg-red-100 text-red-800",blue:"bg-blue-50 text-blue-700",slate:"bg-slate-100 text-slate-800",amber:"bg-amber-100 text-amber-800"}[s]),children:e})},aL=e=>e?aA("detected","red"):aA("not detected","slate"),aT=e=>{let{title:s,count:t,defaultOpen:l=!0,right:a,children:r}=e,[i,n]=(0,d.useState)(l);return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>n(e=>!e),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(i?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("h5",{className:"font-medium",children:[s," ","number"==typeof t&&(0,c.jsxs)("span",{className:"text-gray-500 font-normal",children:["(",t,")"]})]})]}),(0,c.jsx)("div",{children:a})]}),i&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:r})]})},aP=e=>{let{label:s,children:t,mono:l}=e;return(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:s}),(0,c.jsx)("span",{className:l?"font-mono text-sm break-all":"",children:t})]})},aE=()=>(0,c.jsx)("div",{className:"my-3 border-t"});var aM=e=>{var s,t,l,a,r,i,n,o,d,m;let{response:u}=e;if(!u)return null;let x=null!==(r=null!==(a=u.outputs)&&void 0!==a?a:u.output)&&void 0!==r?r:[],h="GUARDRAIL_INTERVENED"===u.action?"red":"green",p=(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(null===(s=u.guardrailCoverage)||void 0===s?void 0:s.textCharacters)&&aA("text guarded ".concat(null!==(i=u.guardrailCoverage.textCharacters.guarded)&&void 0!==i?i:0,"/").concat(null!==(n=u.guardrailCoverage.textCharacters.total)&&void 0!==n?n:0),"blue"),(null===(t=u.guardrailCoverage)||void 0===t?void 0:t.images)&&aA("images guarded ".concat(null!==(o=u.guardrailCoverage.images.guarded)&&void 0!==o?o:0,"/").concat(null!==(d=u.guardrailCoverage.images.total)&&void 0!==d?d:0),"blue")]}),g=u.usage&&(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(u.usage).map(e=>{let[s,t]=e;return"number"==typeof t?(0,c.jsxs)("span",{className:"px-2 py-1 bg-slate-100 text-slate-800 rounded-md text-xs font-medium",children:[s,": ",t]},s):null})});return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Action:",children:aA(null!==(m=u.action)&&void 0!==m?m:"N/A",h)}),u.actionReason&&(0,c.jsx)(aP,{label:"Action Reason:",children:u.actionReason}),u.blockedResponse&&(0,c.jsx)(aP,{label:"Blocked Response:",children:(0,c.jsx)("span",{className:"italic",children:u.blockedResponse})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Coverage:",children:p}),(0,c.jsx)(aP,{label:"Usage:",children:g})]})]}),x.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(aE,{}),(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Outputs"}),(0,c.jsx)("div",{className:"space-y-2",children:x.map((e,s)=>{var t;return(0,c.jsx)("div",{className:"p-3 bg-gray-50 rounded-md",children:(0,c.jsx)("div",{className:"text-sm whitespace-pre-wrap",children:null!==(t=e.text)&&void 0!==t?t:(0,c.jsx)("em",{children:"(non-text output)"})})},s)})})]})]}),(null===(l=u.assessments)||void 0===l?void 0:l.length)?(0,c.jsx)("div",{className:"space-y-3",children:u.assessments.map((e,s)=>{var t,l,a,r,i,n,o,d,m,u,x,h,p,g,j,f,v,y,b,_,N,Z,w,k;let S=(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.wordPolicy&&aA("word","slate"),e.contentPolicy&&aA("content","slate"),e.topicPolicy&&aA("topic","slate"),e.sensitiveInformationPolicy&&aA("sensitive-info","slate"),e.contextualGroundingPolicy&&aA("contextual-grounding","slate"),e.automatedReasoningPolicy&&aA("automated-reasoning","slate")]});return(0,c.jsxs)(aT,{title:"Assessment #".concat(s+1),defaultOpen:!0,right:(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.invocationMetrics)||void 0===t?void 0:t.guardrailProcessingLatency)!=null&&aA("".concat(e.invocationMetrics.guardrailProcessingLatency," ms"),"amber"),S]}),children:[e.wordPolicy&&(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Word Policy"}),(null!==(f=null===(l=e.wordPolicy.customWords)||void 0===l?void 0:l.length)&&void 0!==f?f:0)>0&&(0,c.jsx)(aT,{title:"Custom Words",defaultOpen:!0,children:(0,c.jsx)("div",{className:"space-y-2",children:e.wordPolicy.customWords.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-mono text-sm break-all",children:e.match})]}),aL(e.detected)]},s)})})}),(null!==(v=null===(a=e.wordPolicy.managedWordLists)||void 0===a?void 0:a.length)&&void 0!==v?v:0)>0&&(0,c.jsx)(aT,{title:"Managed Word Lists",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.wordPolicy.managedWordLists.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-mono text-sm break-all",children:e.match}),e.type&&aA(e.type,"slate")]}),aL(e.detected)]},s)})})})]}),(null===(i=e.contentPolicy)||void 0===i?void 0:null===(r=i.filters)||void 0===r?void 0:r.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Content Policy"}),(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)("table",{className:"min-w-full text-sm",children:[(0,c.jsx)("thead",{children:(0,c.jsxs)("tr",{className:"text-left text-gray-600",children:[(0,c.jsx)("th",{className:"py-1 pr-4",children:"Type"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Action"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Detected"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Strength"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Confidence"})]})}),(0,c.jsx)("tbody",{children:e.contentPolicy.filters.map((e,s)=>{var t,l,a,r;return(0,c.jsxs)("tr",{className:"border-t",children:[(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(t=e.type)&&void 0!==t?t:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aA(null!==(l=e.action)&&void 0!==l?l:"—",e.detected?"red":"slate")}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aL(e.detected)}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(a=e.filterStrength)&&void 0!==a?a:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(r=e.confidence)&&void 0!==r?r:"—"})]},s)})})]})})]}):null,(null===(o=e.contextualGroundingPolicy)||void 0===o?void 0:null===(n=o.filters)||void 0===n?void 0:n.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Contextual Grounding"}),(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)("table",{className:"min-w-full text-sm",children:[(0,c.jsx)("thead",{children:(0,c.jsxs)("tr",{className:"text-left text-gray-600",children:[(0,c.jsx)("th",{className:"py-1 pr-4",children:"Type"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Action"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Detected"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Score"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Threshold"})]})}),(0,c.jsx)("tbody",{children:e.contextualGroundingPolicy.filters.map((e,s)=>{var t,l,a,r;return(0,c.jsxs)("tr",{className:"border-t",children:[(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(t=e.type)&&void 0!==t?t:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aA(null!==(l=e.action)&&void 0!==l?l:"—",e.detected?"red":"slate")}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aL(e.detected)}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(a=e.score)&&void 0!==a?a:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(r=e.threshold)&&void 0!==r?r:"—"})]},s)})})]})})]}):null,e.sensitiveInformationPolicy&&(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Sensitive Information"}),(null!==(y=null===(d=e.sensitiveInformationPolicy.piiEntities)||void 0===d?void 0:d.length)&&void 0!==y?y:0)>0&&(0,c.jsx)(aT,{title:"PII Entities",defaultOpen:!0,children:(0,c.jsx)("div",{className:"space-y-2",children:e.sensitiveInformationPolicy.piiEntities.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),e.type&&aA(e.type,"slate"),(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.match})]}),aL(e.detected)]},s)})})}),(null!==(b=null===(m=e.sensitiveInformationPolicy.regexes)||void 0===m?void 0:m.length)&&void 0!==b?b:0)>0&&(0,c.jsx)(aT,{title:"Custom Regexes",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.sensitiveInformationPolicy.regexes.map((e,s)=>{var t,l;return(0,c.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-2 bg-gray-50 rounded gap-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-medium",children:null!==(l=e.name)&&void 0!==l?l:"regex"}),(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.regex})]}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aL(e.detected),e.match&&(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.match})]})]},s)})})})]}),(null===(x=e.topicPolicy)||void 0===x?void 0:null===(u=x.topics)||void 0===u?void 0:u.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Topic Policy"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:e.topicPolicy.topics.map((e,s)=>{var t,l;return(0,c.jsx)("div",{className:"px-3 py-1.5 bg-gray-50 rounded-md text-xs",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-medium",children:null!==(l=e.name)&&void 0!==l?l:"topic"}),e.type&&aA(e.type,"slate"),aL(e.detected)]})},s)})})]}):null,e.invocationMetrics&&(0,c.jsx)(aT,{title:"Invocation Metrics",defaultOpen:!1,children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Latency (ms)",children:null!==(_=e.invocationMetrics.guardrailProcessingLatency)&&void 0!==_?_:"—"}),(0,c.jsx)(aP,{label:"Coverage:",children:(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(null===(h=e.invocationMetrics.guardrailCoverage)||void 0===h?void 0:h.textCharacters)&&aA("text ".concat(null!==(N=e.invocationMetrics.guardrailCoverage.textCharacters.guarded)&&void 0!==N?N:0,"/").concat(null!==(Z=e.invocationMetrics.guardrailCoverage.textCharacters.total)&&void 0!==Z?Z:0),"blue"),(null===(p=e.invocationMetrics.guardrailCoverage)||void 0===p?void 0:p.images)&&aA("images ".concat(null!==(w=e.invocationMetrics.guardrailCoverage.images.guarded)&&void 0!==w?w:0,"/").concat(null!==(k=e.invocationMetrics.guardrailCoverage.images.total)&&void 0!==k?k:0),"blue")]})})]}),(0,c.jsx)("div",{className:"space-y-2",children:(0,c.jsx)(aP,{label:"Usage:",children:(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:e.invocationMetrics.usage&&Object.entries(e.invocationMetrics.usage).map(e=>{let[s,t]=e;return"number"==typeof t?(0,c.jsxs)("span",{className:"px-2 py-1 bg-slate-100 text-slate-800 rounded-md text-xs font-medium",children:[s,": ",t]},s):null})})})})]})}),(null===(j=e.automatedReasoningPolicy)||void 0===j?void 0:null===(g=j.findings)||void 0===g?void 0:g.length)?(0,c.jsx)(aT,{title:"Automated Reasoning Findings",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.automatedReasoningPolicy.findings.map((e,s)=>(0,c.jsx)("pre",{className:"bg-gray-50 rounded p-2 text-xs overflow-x-auto",children:JSON.stringify(e,null,2)},s))})}):null]},s)})}):null,(0,c.jsx)(aT,{title:"Raw Bedrock Guardrail Response",defaultOpen:!1,children:(0,c.jsx)("pre",{className:"bg-gray-50 rounded p-3 text-xs overflow-x-auto",children:JSON.stringify(u,null,2)})})]})},aO=e=>{var s,t;let{data:l}=e,[a,r]=(0,d.useState)(!0),i=null!==(t=l.guardrail_provider)&&void 0!==t?t:"presidio";if(!l)return null;let n="string"==typeof l.guardrail_status&&"success"===l.guardrail_status.toLowerCase(),o=n?null:"Guardrail failed to run.",m=l.masked_entity_count?Object.values(l.masked_entity_count).reduce((e,s)=>e+s,0):0,u=e=>new Date(1e3*e).toLocaleString();return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>r(!a),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,c.jsx)(V.Z,{title:o,placement:"top",arrow:!0,destroyTooltipOnHide:!0,children:(0,c.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat(n?"bg-green-100 text-green-800":"bg-red-100 text-red-800 cursor-help"),children:l.guardrail_status})}),m>0&&(0,c.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[m," masked ",1===m?"entity":"entities"]})]}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:a?"Click to collapse":"Click to expand"})]}),a&&(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,c.jsx)("span",{className:"font-mono",children:l.guardrail_name})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,c.jsx)("span",{className:"font-mono",children:l.guardrail_mode})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,c.jsx)(V.Z,{title:o,placement:"top",arrow:!0,destroyTooltipOnHide:!0,children:(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat(n?"bg-green-100 text-green-800":"bg-red-100 text-red-800 cursor-help"),children:l.guardrail_status})})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:u(l.start_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:u(l.end_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsxs)("span",{children:[l.duration.toFixed(4),"s"]})]})]})]}),l.masked_entity_count&&Object.keys(l.masked_entity_count).length>0&&(0,c.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(l.masked_entity_count).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",t]},s)})})]})]}),"presidio"===i&&(null===(s=l.guardrail_response)||void 0===s?void 0:s.length)>0&&(0,c.jsx)(aI,{entities:l.guardrail_response}),"bedrock"===i&&l.guardrail_response&&(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(aM,{response:l.guardrail_response})})]})]})};let aD={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",END_USER:"End User",STATUS:"Status",KEY_ALIAS:"Key Alias"},aF="".concat("../ui/assets/","audit-logs-preview.png");function aR(e){let{userID:s,userRole:t,token:l,accessToken:a,isActive:r,premiumUser:i,allTeams:n}=e,[o,m]=(0,d.useState)(ah()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),u=(0,d.useRef)(null),x=(0,d.useRef)(null),[h,p]=(0,d.useState)(1),[g]=(0,d.useState)(50),[f,v]=(0,d.useState)({}),[y,b]=(0,d.useState)(""),[_,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)(""),[S,C]=(0,d.useState)("all"),[I,A]=(0,d.useState)("all"),[L,T]=(0,d.useState)(!1),[P,E]=(0,d.useState)(!1),M=(0,sj.a)({queryKey:["all_audit_logs",a,l,t,s,o],queryFn:async()=>{if(!a||!l||!t||!s)return[];let e=ah()(o).utc().format("YYYY-MM-DD HH:mm:ss"),r=ah()().utc().format("YYYY-MM-DD HH:mm:ss"),i=[],n=1,c=1;do{let s=await (0,j.uiAuditLogsCall)(a,e,r,n,50);i=i.concat(s.audit_logs),c=s.total_pages,n++}while(n<=c);return i},enabled:!!a&&!!l&&!!t&&!!s&&r,refetchInterval:5e3,refetchIntervalInBackground:!0}),O=(0,d.useCallback)(async e=>{if(a)try{let s=(await (0,j.keyListCall)(a,null,null,e,null,null,1,10)).keys.find(s=>s.key_alias===e);s?N(s.token):N("")}catch(e){console.error("Error fetching key hash for alias:",e),N("")}},[a]);(0,d.useEffect)(()=>{if(!a)return;let e=!1,s=!1;f["Team ID"]?y!==f["Team ID"]&&(b(f["Team ID"]),e=!0):""!==y&&(b(""),e=!0),f["Key Hash"]?_!==f["Key Hash"]&&(N(f["Key Hash"]),s=!0):f["Key Alias"]?O(f["Key Alias"]):""!==_&&(N(""),s=!0),(e||s)&&p(1)},[f,a,O,y,_]),(0,d.useEffect)(()=>{p(1)},[y,_,o,Z,S,I]),(0,d.useEffect)(()=>{function e(e){u.current&&!u.current.contains(e.target)&&T(!1),x.current&&!x.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let D=(0,d.useMemo)(()=>M.data?M.data.filter(e=>{var s,t,l,a,r,i,n;let o=!0,c=!0,d=!0,m=!0,u=!0;if(y){let r="string"==typeof e.before_value?null===(s=JSON.parse(e.before_value))||void 0===s?void 0:s.team_id:null===(t=e.before_value)||void 0===t?void 0:t.team_id,i="string"==typeof e.updated_values?null===(l=JSON.parse(e.updated_values))||void 0===l?void 0:l.team_id:null===(a=e.updated_values)||void 0===a?void 0:a.team_id;o=r===y||i===y}if(_)try{let s="string"==typeof e.before_value?JSON.parse(e.before_value):e.before_value,t="string"==typeof e.updated_values?JSON.parse(e.updated_values):e.updated_values,l=null==s?void 0:s.token,a=null==t?void 0:t.token;c="string"==typeof l&&l.includes(_)||"string"==typeof a&&a.includes(_)}catch(e){c=!1}if(Z&&(d=null===(r=e.object_id)||void 0===r?void 0:r.toLowerCase().includes(Z.toLowerCase())),"all"!==S&&(m=(null===(i=e.action)||void 0===i?void 0:i.toLowerCase())===S.toLowerCase()),"all"!==I){let s="";switch(I){case"keys":s="litellm_verificationtoken";break;case"teams":s="litellm_teamtable";break;case"users":s="litellm_usertable";break;default:s=I}u=(null===(n=e.table_name)||void 0===n?void 0:n.toLowerCase())===s}return o&&c&&d&&m&&u}):[],[M.data,y,_,Z,S,I]),F=D.length,R=Math.ceil(F/g)||1,z=(0,d.useMemo)(()=>{let e=(h-1)*g,s=e+g;return D.slice(e,s)},[D,h,g]),U=!M.data||0===M.data.length,q=(0,d.useCallback)(e=>{let{row:s}=e;return(0,c.jsx)(e=>{let{rowData:s}=e,{before_value:t,updated_values:l,table_name:a,action:r}=s,i=(e,s)=>{if(!e||0===Object.keys(e).length)return(0,c.jsx)(k.Z,{children:"N/A"});if(s){let s=Object.keys(e),t=["token","spend","max_budget"];if(s.every(e=>t.includes(e))&&s.length>0)return(0,c.jsxs)("div",{children:[s.includes("token")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Token:"})," ",e.token||"N/A"]}),s.includes("spend")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Spend:"})," ",void 0!==e.spend?"$".concat(eE(e.spend,6)):"N/A"]}),s.includes("max_budget")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Max Budget:"})," ",void 0!==e.max_budget?"$".concat(eE(e.max_budget,6)):"N/A"]})]});if(e["No differing fields detected in 'before' state"]||e["No differing fields detected in 'updated' state"]||e["No fields changed"])return(0,c.jsx)(k.Z,{children:e[Object.keys(e)[0]]})}return(0,c.jsx)("pre",{className:"p-2 bg-gray-50 border rounded text-xs overflow-auto max-h-60",children:JSON.stringify(e,null,2)})},n=t,o=l;if(("updated"===r||"rotated"===r)&&t&&l&&("LiteLLM_TeamTable"===a||"LiteLLM_UserTable"===a||"LiteLLM_VerificationToken"===a)){let e={},s={};new Set([...Object.keys(t),...Object.keys(l)]).forEach(a=>{JSON.stringify(t[a])!==JSON.stringify(l[a])&&(t.hasOwnProperty(a)&&(e[a]=t[a]),l.hasOwnProperty(a)&&(s[a]=l[a]))}),Object.keys(t).forEach(a=>{l.hasOwnProperty(a)||e.hasOwnProperty(a)||(e[a]=t[a],s[a]=void 0)}),Object.keys(l).forEach(a=>{t.hasOwnProperty(a)||s.hasOwnProperty(a)||(s[a]=l[a],e[a]=void 0)}),n=Object.keys(e).length>0?e:{"No differing fields detected in 'before' state":"N/A"},o=Object.keys(s).length>0?s:{"No differing fields detected in 'updated' state":"N/A"},0===Object.keys(e).length&&0===Object.keys(s).length&&(n={"No fields changed":"N/A"},o={"No fields changed":"N/A"})}return(0,c.jsxs)("div",{className:"-mx-4 p-4 bg-slate-100 border-y border-slate-300 grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"font-semibold mb-2 text-sm text-slate-700",children:"Before Value:"}),i(n,"LiteLLM_VerificationToken"===a)]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"font-semibold mb-2 text-sm text-slate-700",children:"Updated Value:"}),i(o,"LiteLLM_VerificationToken"===a)]})]})},{rowData:s.original})},[]);if(!i)return(0,c.jsxs)("div",{style:{textAlign:"center",marginTop:"20px"},children:[(0,c.jsx)("h1",{style:{display:"block",marginBottom:"10px"},children:"✨ Enterprise Feature."}),(0,c.jsx)(k.Z,{style:{display:"block",marginBottom:"10px"},children:"This is a LiteLLM Enterprise feature, and requires a valid key to use."}),(0,c.jsx)(k.Z,{style:{display:"block",marginBottom:"20px",fontStyle:"italic"},children:"Here's a preview of what Audit Logs offer:"}),(0,c.jsx)("img",{src:aF,alt:"Audit Logs Preview",style:{maxWidth:"100%",maxHeight:"700px",borderRadius:"8px",boxShadow:"0 4px 8px rgba(0,0,0,0.1)",margin:"0 auto"},onError:e=>{console.error("Failed to load audit logs preview image"),e.target.style.display="none"}})]});let B=F>0?(h-1)*g+1:0,V=Math.min(h*g,F);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4"}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"border-b px-6 py-4",children:[(0,c.jsx)("h1",{className:"text-xl font-semibold py-4",children:"Audit Logs"}),(0,c.jsx)(e=>{let{show:s}=e;return s?(0,c.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start mb-6",children:[(0,c.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,c.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,c.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,c.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,c.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Audit Logs Not Available"}),(0,c.jsx)("p",{className:"text-sm text-blue-700 mt-1",children:"To enable audit logging, add the following configuration to your LiteLLM proxy configuration file:"}),(0,c.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"litellm_settings:\n store_audit_logs: true"}),(0,c.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change and proxy restart."})]})]}):null},{show:U}),(0,c.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,c.jsx)("div",{className:"flex flex-wrap items-center gap-3",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)("input",{type:"text",placeholder:"Search by Object ID...",value:Z,onChange:e=>w(e.target.value),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,c.jsxs)("button",{onClick:()=>{M.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,c.jsx)("svg",{className:"w-4 h-4 ".concat(M.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsx)("span",{children:"Refresh"})]})]})}),(0,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsxs)("div",{className:"relative",ref:u,children:[(0,c.jsx)("label",{htmlFor:"actionFilterDisplay",className:"mr-2 text-sm font-medium text-gray-700 sr-only",children:"Action:"}),(0,c.jsxs)("button",{id:"actionFilterDisplay",onClick:()=>T(!L),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 bg-white w-40 text-left justify-between",children:[(0,c.jsxs)("span",{children:["all"===S&&"All Actions","created"===S&&"Created","updated"===S&&"Updated","deleted"===S&&"Deleted","rotated"===S&&"Rotated"]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})]}),L&&(0,c.jsx)("div",{className:"absolute left-0 mt-2 w-40 bg-white rounded-lg shadow-lg border p-1 z-50",children:(0,c.jsx)("div",{className:"space-y-1",children:[{label:"All Actions",value:"all"},{label:"Created",value:"created"},{label:"Updated",value:"updated"},{label:"Deleted",value:"deleted"},{label:"Rotated",value:"rotated"}].map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(S===e.value?"bg-blue-50 text-blue-600 font-medium":"font-normal"),onClick:()=>{C(e.value),T(!1)},children:e.label},e.value))})})]}),(0,c.jsxs)("div",{className:"relative",ref:x,children:[(0,c.jsx)("label",{htmlFor:"tableFilterDisplay",className:"mr-2 text-sm font-medium text-gray-700 sr-only",children:"Table:"}),(0,c.jsxs)("button",{id:"tableFilterDisplay",onClick:()=>E(!P),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 bg-white w-40 text-left justify-between",children:[(0,c.jsxs)("span",{children:["all"===I&&"All Tables","keys"===I&&"Keys","teams"===I&&"Teams","users"===I&&"Users"]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})]}),P&&(0,c.jsx)("div",{className:"absolute left-0 mt-2 w-40 bg-white rounded-lg shadow-lg border p-1 z-50",children:(0,c.jsx)("div",{className:"space-y-1",children:[{label:"All Tables",value:"all"},{label:"Keys",value:"keys"},{label:"Teams",value:"teams"},{label:"Users",value:"users"}].map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I===e.value?"bg-blue-50 text-blue-600 font-medium":"font-normal"),onClick:()=>{A(e.value),E(!1)},children:e.label},e.value))})})]}),(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",M.isLoading?"...":B," ","-"," ",M.isLoading?"...":V," ","of"," ",M.isLoading?"...":F," ","results"]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",M.isLoading?"...":h," of"," ",M.isLoading?"...":R]}),(0,c.jsx)("button",{onClick:()=>p(e=>Math.max(1,e-1)),disabled:M.isLoading||1===h,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,c.jsx)("button",{onClick:()=>p(e=>Math.min(R,e+1)),disabled:M.isLoading||h===R,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})]}),(0,c.jsx)(lx,{columns:ay,data:z,renderSubComponent:q,getRowCanExpand:()=>!0})]})]})}let az=(e,s,t)=>{if(e)return"".concat(ah()(s).format("MMM D, h:mm A")," - ").concat(ah()(t).format("MMM D, h:mm A"));let l=ah()(),a=ah()(s),r=l.diff(a,"minutes");if(r>=0&&r<2)return"Last 1 Minute";if(r>=2&&r<16)return"Last 15 Minutes";if(r>=16&&r<61)return"Last Hour";let i=l.diff(a,"hours");return i>=1&&i<5?"Last 4 Hours":i>=5&&i<25?"Last 24 Hours":i>=25&&i<169?"Last 7 Days":"".concat(a.format("MMM D")," - ").concat(l.format("MMM D"))};function aU(e){var s,t,l;let{accessToken:a,token:r,userRole:i,userID:n,allTeams:o,premiumUser:m}=e,[u,x]=(0,d.useState)(""),[p,g]=(0,d.useState)(!1),[f,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(1),[_]=(0,d.useState)(50),N=(0,d.useRef)(null),Z=(0,d.useRef)(null),w=(0,d.useRef)(null),[k,S]=(0,d.useState)(ah()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[C,I]=(0,d.useState)(ah()().format("YYYY-MM-DDTHH:mm")),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(!1),[E,M]=(0,d.useState)(""),[O,D]=(0,d.useState)(""),[F,R]=(0,d.useState)(""),[z,U]=(0,d.useState)(""),[q,B]=(0,d.useState)(""),[V,K]=(0,d.useState)(null),[G,H]=(0,d.useState)(null),[J,Y]=(0,d.useState)(""),[W,$]=(0,d.useState)(""),[Q,X]=(0,d.useState)(i&&eI.lo.includes(i)),[ee,es]=(0,d.useState)("request logs"),[et,el]=(0,d.useState)(null),[ea,er]=(0,d.useState)(null),ei=(0,h.NL)(),[en,eo]=(0,d.useState)(()=>{let e=sessionStorage.getItem("isLiveTail");return null===e||JSON.parse(e)});(0,d.useEffect)(()=>{sessionStorage.setItem("isLiveTail",JSON.stringify(en))},[en]);let[ec,ed]=(0,d.useState)({value:24,unit:"hours"});(0,d.useEffect)(()=>{(async()=>{G&&a&&K({...(await (0,j.keyInfoV1Call)(a,G)).info,token:G,api_key:G})})()},[G,a]),(0,d.useEffect)(()=>{function e(e){N.current&&!N.current.contains(e.target)&&v(!1),Z.current&&!Z.current.contains(e.target)&&g(!1),w.current&&!w.current.contains(e.target)&&P(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,d.useEffect)(()=>{i&&eI.lo.includes(i)&&X(!0)},[i]);let em=(0,sj.a)({queryKey:["logs","table",y,_,k,C,F,z,Q?n:null,J,q],queryFn:async()=>{if(!a||!r||!i||!n)return{data:[],total:0,page:1,page_size:_,total_pages:0};let e=ah()(k).utc().format("YYYY-MM-DD HH:mm:ss"),s=A?ah()(C).utc().format("YYYY-MM-DD HH:mm:ss"):ah()().utc().format("YYYY-MM-DD HH:mm:ss"),t=await (0,j.uiSpendLogsCall)(a,z||void 0,F||void 0,void 0,e,s,y,_,Q?n:void 0,W,J,q);return await ab(t.data,e,a,ei),t.data=t.data.map(s=>{let t=ei.getQueryData(["logDetails",s.request_id,e]);return(null==t?void 0:t.messages)&&(null==t?void 0:t.response)&&(s.messages=t.messages,s.response=t.response),s}),t},enabled:!!a&&!!r&&!!i&&!!n&&"request logs"===ee,refetchInterval:!!en&&1===y&&15e3,refetchIntervalInBackground:!0}),{filters:eu,filteredLogs:ex,allTeams:eh,allKeyAliases:ep,handleFilterChange:eg,handleFilterReset:ej}=function(e){let{logs:s,accessToken:t,startTime:l,endTime:a,pageSize:r=25,isCustomDate:i,setCurrentPage:n,userID:o,userRole:c}=e,m=(0,d.useMemo)(()=>({[aD.TEAM_ID]:"",[aD.KEY_HASH]:"",[aD.REQUEST_ID]:"",[aD.MODEL]:"",[aD.USER_ID]:"",[aD.END_USER]:"",[aD.STATUS]:"",[aD.KEY_ALIAS]:""}),[]),[u,x]=(0,d.useState)(m),[h,p]=(0,d.useState)(s),g=(0,d.useRef)(0),f=(0,d.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!t)return;console.log("Filters being sent to API:",e);let n=Date.now();g.current=n;let o=ah()(l).utc().format("YYYY-MM-DD HH:mm:ss"),c=i?ah()(a).utc().format("YYYY-MM-DD HH:mm:ss"):ah()().utc().format("YYYY-MM-DD HH:mm:ss");try{let l=await (0,j.uiSpendLogsCall)(t,e[aD.KEY_HASH]||void 0,e[aD.TEAM_ID]||void 0,e[aD.REQUEST_ID]||void 0,o,c,s,r,e[aD.USER_ID]||void 0,e[aD.END_USER]||void 0,e[aD.STATUS]||void 0,e[aD.MODEL]||void 0,e[aD.KEY_ALIAS]||void 0);n===g.current&&l.data&&p(l)}catch(e){console.error("Error searching users:",e)}},[t,l,a,i,r]),v=(0,d.useMemo)(()=>eC()((e,s)=>f(e,s),300),[f]);(0,d.useEffect)(()=>()=>v.cancel(),[v]);let y=(0,sj.a)({queryKey:["allKeys"],queryFn:async()=>{if(!t)throw Error("Access token required");return await sf(t)},enabled:!!t}).data||[];(0,d.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}if(u[aD.KEY_ALIAS]||u[aD.KEY_HASH]||u[aD.REQUEST_ID]||u[aD.USER_ID]||u[aD.END_USER])return;let e=[...s.data];u[aD.TEAM_ID]&&(e=e.filter(e=>e.team_id===u[aD.TEAM_ID])),u[aD.STATUS]&&(e=e.filter(e=>"success"===u[aD.STATUS]?!e.status||"success"===e.status:e.status===u[aD.STATUS])),u[aD.MODEL]&&(e=e.filter(e=>e.model===u[aD.MODEL])),u[aD.KEY_HASH]&&(e=e.filter(e=>e.api_key===u[aD.KEY_HASH])),u[aD.END_USER]&&(e=e.filter(e=>e.end_user===u[aD.END_USER]));let t={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(t)!==JSON.stringify(h)&&p(t)},[s,u,h,t]);let{data:b}=(0,sj.a)({queryKey:["allTeamsForLogFilters",t],queryFn:async()=>t&&await sv(t)||[],enabled:!!t});return{filters:u,filteredLogs:h,allKeyAliases:y,allTeams:b,handleFilterChange:e=>{x(s=>{let t={...s,...e};for(let e of Object.keys(m))e in t||(t[e]=m[e]);return JSON.stringify(t)!==JSON.stringify(s)&&(n(1),v(t,1)),t})},handleFilterReset:()=>{x(m),v(m,1)}}}({logs:em.data||{data:[],total:0,page:1,page_size:_||10,total_pages:1},accessToken:a,startTime:k,endTime:C,pageSize:_,isCustomDate:A,setCurrentPage:b,userID:n,userRole:i}),ef=(0,d.useCallback)(async e=>{if(a)try{let s=(await (0,j.keyListCall)(a,null,null,e,null,null,y,_)).keys.find(s=>s.key_alias===e);s&&U(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,y,_]);(0,d.useEffect)(()=>{a&&(eu["Team ID"]?R(eu["Team ID"]):R(""),Y(eu.Status||""),B(eu.Model||""),$(eu["End User"]||""),eu["Key Hash"]?U(eu["Key Hash"]):eu["Key Alias"]?ef(eu["Key Alias"]):U(""))},[eu,a,ef]);let ev=(0,sj.a)({queryKey:["sessionLogs",ea],queryFn:async()=>{if(!a||!ea)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,j.sessionSpendLogsCall)(a,ea);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!ea});if((0,d.useEffect)(()=>{var e;(null===(e=em.data)||void 0===e?void 0:e.data)&&et&&!em.data.data.some(e=>e.request_id===et)&&el(null)},[null===(s=em.data)||void 0===s?void 0:s.data,et]),!a||!r||!i||!n)return null;let ey=ex.data.filter(e=>!u||e.request_id.includes(u)||e.model.includes(u)||e.user&&e.user.includes(u)).map(e=>({...e,duration:(Date.parse(e.endTime)-Date.parse(e.startTime))/1e3,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&er(e)}}))||[],eb=(null===(l=ev.data)||void 0===l?void 0:null===(t=l.data)||void 0===t?void 0:t.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],e_=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!1},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await sf(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"End User",label:"End User",isSearchable:!0,searchFn:async e=>{if(!a)return[];let s=await (0,j.allEndUsersCall)(a);return((null==s?void 0:s.end_users)||[]).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))}},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];if(ea&&ev.data)return(0,c.jsx)("div",{className:"w-full p-6",children:(0,c.jsx)(ak,{sessionId:ea,logs:ev.data.data,onBack:()=>er(null)})});let eN=[{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"}],eZ=eN.find(e=>e.value===ec.value&&e.unit===ec.unit),ew=A?az(A,k,C):null==eZ?void 0:eZ.label;return(0,c.jsx)("div",{className:"w-full max-w-screen p-6 overflow-x-hidden box-border",children:(0,c.jsxs)(e1.Z,{defaultIndex:0,onIndexChange:e=>es(0===e?"request logs":"audit logs"),children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Request Logs"}),(0,c.jsx)(e0.Z,{children:"Audit Logs"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,c.jsx)("h1",{className:"text-xl font-semibold",children:ea?(0,c.jsxs)(c.Fragment,{children:["Session: ",(0,c.jsx)("span",{className:"font-mono",children:ea}),(0,c.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>er(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&G&&V.api_key===G?(0,c.jsx)(sh,{keyId:G,keyData:V,accessToken:a,userID:n,userRole:i,teams:o,onClose:()=>H(null),premiumUser:m,backButtonText:"Back to Logs"}):ea?(0,c.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,c.jsx)(lx,{columns:af,data:eb,renderSubComponent:aq,getRowCanExpand:()=>!0})}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sg,{options:e_,onApplyFilters:eg,onResetFilters:ej}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full box-border",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4 w-full max-w-full box-border",children:(0,c.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0 w-full max-w-full box-border",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 w-full max-w-full box-border",children:[(0,c.jsxs)("div",{className:"relative w-64 min-w-0 flex-shrink-0",children:[(0,c.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:u,onChange:e=>x(e.target.value)}),(0,c.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,c.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,c.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-shrink",children:[(0,c.jsxs)("div",{className:"relative z-50",ref:w,children:[(0,c.jsxs)("button",{onClick:()=>P(!T),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),ew]}),T&&(0,c.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,c.jsxs)("div",{className:"space-y-1",children:[eN.map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ew===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{I(ah()().format("YYYY-MM-DDTHH:mm")),S(ah()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),ed({value:e.value,unit:e.unit}),L(!1),P(!1)},children:e.label},e.label)),(0,c.jsx)("div",{className:"border-t my-2"}),(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(A?"bg-blue-50 text-blue-600":""),onClick:()=>L(!A),children:"Custom Range"})]})})]}),(0,c.jsx)(()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{className:"text-sm font-medium text-gray-900",children:"Live Tail"}),(0,c.jsx)(tB.Z,{color:"green",checked:en,defaultChecked:!0,onChange:eo})]}),{}),(0,c.jsxs)("button",{onClick:()=>{em.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,c.jsx)("svg",{className:"w-4 h-4 ".concat(em.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsx)("span",{children:"Refresh"})]})]}),A&&(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{children:(0,c.jsx)("input",{type:"datetime-local",value:k,onChange:e=>{S(e.target.value),b(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,c.jsx)("span",{className:"text-gray-500",children:"to"}),(0,c.jsx)("div",{children:(0,c.jsx)("input",{type:"datetime-local",value:C,onChange:e=>{I(e.target.value),b(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,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700 whitespace-nowrap",children:["Showing ",em.isLoading?"...":ex?(y-1)*_+1:0," -"," ",em.isLoading?"...":ex?Math.min(y*_,ex.total):0," ","of ",em.isLoading?"...":ex?ex.total:0," results"]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700 min-w-[90px]",children:["Page ",em.isLoading?"...":y," of"," ",em.isLoading?"...":ex?ex.total_pages:1]}),(0,c.jsx)("button",{onClick:()=>b(e=>Math.max(1,e-1)),disabled:em.isLoading||1===y,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,c.jsx)("button",{onClick:()=>b(e=>Math.min(ex.total_pages||1,e+1)),disabled:em.isLoading||y===(ex.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"})]})]})]})}),en&&1===y&&(0,c.jsxs)("div",{className:"mb-4 px-4 py-2 bg-green-50 border border-greem-200 rounded-md flex items-center justify-between",children:[(0,c.jsx)("div",{className:"flex items-center gap-2",children:(0,c.jsx)("span",{className:"text-sm text-green-700",children:"Auto-refreshing every 15 seconds"})}),(0,c.jsx)("button",{onClick:()=>eo(!1),className:"text-sm text-green-600 hover:text-green-800",children:"Stop"})]}),(0,c.jsx)(lx,{columns:af,data:ey,renderSubComponent:aq,getRowCanExpand:()=>!0})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(aR,{userID:n,userRole:i,token:r,accessToken:a,isActive:"audit logs"===ee,premiumUser:m,allTeams:o})})]})]})})}function aq(e){var s,t,l,a,r,i,n,o;let{row:d}=e,m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},u=d.original.metadata||{},x="failure"===u.status,h=x?u.error_information:null,p=d.original.messages&&(Array.isArray(d.original.messages)?d.original.messages.length>0:Object.keys(d.original.messages).length>0),g=d.original.response&&Object.keys(m(d.original.response)).length>0,j=u.vector_store_request_metadata&&Array.isArray(u.vector_store_request_metadata)&&u.vector_store_request_metadata.length>0,f=d.original.metadata&&d.original.metadata.guardrail_information,v=f&&(null===(o=d.original.metadata)||void 0===o?void 0:o.guardrail_information.masked_entity_count)?Object.values(d.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,c.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6 w-full max-w-full overflow-hidden box-border",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsx)("div",{className:"p-4 border-b",children:(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 p-4 w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,c.jsx)("span",{className:"font-mono text-sm",children:d.original.request_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,c.jsx)("span",{children:d.original.model})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,c.jsx)("span",{children:d.original.model_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,c.jsx)("span",{children:d.original.call_type})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,c.jsx)("span",{children:d.original.custom_llm_provider||"-"})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,c.jsx)(V.Z,{title:d.original.api_base||"-",children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:d.original.api_base||"-"})})]}),(null==d?void 0:null===(s=d.original)||void 0===s?void 0:s.requester_ip_address)&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,c.jsx)("span",{children:null==d?void 0:null===(t=d.original)||void 0===t?void 0:t.requester_ip_address})]}),f&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-mono",children:d.original.metadata.guardrail_information.guardrail_name}),v>0&&(0,c.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[v," masked"]})]})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,c.jsxs)("span",{children:[d.original.total_tokens," (",d.original.prompt_tokens," prompt tokens +"," ",d.original.completion_tokens," completion tokens)"]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Read Tokens:"}),(0,c.jsx)("span",{children:eE((null===(a=d.original.metadata)||void 0===a?void 0:null===(l=a.additional_usage_values)||void 0===l?void 0:l.cache_read_input_tokens)||0)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Creation Tokens:"}),(0,c.jsx)("span",{children:eE(null===(r=d.original.metadata)||void 0===r?void 0:r.additional_usage_values.cache_creation_input_tokens)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,c.jsxs)("span",{children:["$",eE(d.original.spend||0,6)]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,c.jsx)("span",{children:d.original.cache_hit})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=d.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=d.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:d.original.startTime})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:d.original.endTime})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsxs)("span",{children:[d.original.duration," s."]})]})]})]})]}),(0,c.jsx)(aZ,{show:!p&&!g}),(0,c.jsx)("div",{className:"w-full max-w-full overflow-hidden",children:(0,c.jsx)(a_,{row:d,hasMessages:p,hasResponse:g,hasError:x,errorInfo:h,getRawRequest:()=>{var e;return(null===(e=d.original)||void 0===e?void 0:e.proxy_server_request)?m(d.original.proxy_server_request):m(d.original.messages)},formattedResponse:()=>x&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:m(d.original.response)})}),f&&(0,c.jsx)(aO,{data:d.original.metadata.guardrail_information}),j&&(0,c.jsx)(aS,{data:u.vector_store_request_metadata}),x&&h&&(0,c.jsx)(aN,{errorInfo:h}),d.original.request_tags&&Object.keys(d.original.request_tags).length>0&&(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,c.jsx)("div",{className:"p-4",children:(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(d.original.request_tags).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(t)]},s)})})})]}),d.original.metadata&&Object.keys(d.original.metadata).length>0&&(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,c.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(d.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d.original.metadata,null,2)})})]})]})}var aB=t(36172),aV=t(14042),aK=t(49634);let aG=[{label:"Today",shortLabel:"today",getValue:()=>({from:ah()().startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Last 7 days",shortLabel:"7d",getValue:()=>({from:ah()().subtract(7,"days").startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Last 30 days",shortLabel:"30d",getValue:()=>({from:ah()().subtract(30,"days").startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Month to date",shortLabel:"MTD",getValue:()=>({from:ah()().startOf("month").toDate(),to:ah()().endOf("day").toDate()})},{label:"Year to date",shortLabel:"YTD",getValue:()=>({from:ah()().startOf("year").toDate(),to:ah()().endOf("day").toDate()})}];var aH=e=>{let{value:s,onValueChange:t,label:l="Select Time Range",showTimeRange:a=!0}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(s),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(""),[p,g]=(0,d.useState)(""),j=(0,d.useRef)(null),f=(0,d.useCallback)(e=>{if(!e.from||!e.to)return null;for(let s of aG){let t=s.getValue(),l=ah()(e.from).isSame(ah()(t.from),"day"),a=ah()(e.to).isSame(ah()(t.to),"day");if(l&&a)return s.shortLabel}return null},[]);(0,d.useEffect)(()=>{u(f(s))},[s,f]);let v=(0,d.useCallback)(()=>{if(!x||!p)return{isValid:!0,error:""};let e=ah()(x,"YYYY-MM-DD"),s=ah()(p,"YYYY-MM-DD");return e.isValid()&&s.isValid()?s.isBefore(e)?{isValid:!1,error:"End date cannot be before start date"}:{isValid:!0,error:""}:{isValid:!1,error:"Invalid date format"}},[x,p])();(0,d.useEffect)(()=>{s.from&&h(ah()(s.from).format("YYYY-MM-DD")),s.to&&g(ah()(s.to).format("YYYY-MM-DD")),o(s)},[s]),(0,d.useEffect)(()=>{let e=e=>{j.current&&!j.current.contains(e.target)&&i(!1)};return r&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]);let y=(0,d.useCallback)((e,s)=>{if(!e||!s)return"Select date range";let t=e=>ah()(e).format("D MMM, HH:mm");return"".concat(t(e)," - ").concat(t(s))},[]),_=(0,d.useCallback)(e=>{let s;if(!e.from)return e;let t={...e},l=new Date(e.from);return s=new Date(e.to?e.to:e.from),l.toDateString(),s.toDateString(),l.setHours(0,0,0,0),s.setHours(23,59,59,999),t.from=l,t.to=s,t},[]),N=e=>{let{from:s,to:t}=e.getValue();o({from:s,to:t}),u(e.shortLabel),h(ah()(s).format("YYYY-MM-DD")),g(ah()(t).format("YYYY-MM-DD"))},Z=(0,d.useCallback)(()=>{try{if(x&&p&&v.isValid){let e=ah()(x,"YYYY-MM-DD").startOf("day"),s=ah()(p,"YYYY-MM-DD").endOf("day");if(e.isValid()&&s.isValid()){let t={from:e.toDate(),to:s.toDate()};o(t);let l=f(t);u(l)}}}catch(e){console.warn("Invalid date format:",e)}},[x,p,v.isValid,f]);return(0,d.useEffect)(()=>{Z()},[Z]),(0,c.jsxs)("div",{children:[l&&(0,c.jsx)(k.Z,{className:"mb-2",children:l}),(0,c.jsxs)("div",{className:"relative",ref:j,children:[(0,c.jsx)("div",{className:"w-[300px] px-3 py-2 text-sm border border-gray-300 rounded-md bg-white cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500",onClick:()=>i(!r),children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(t2.Z,{className:"text-gray-600"}),(0,c.jsx)("span",{className:"text-gray-900",children:y(s.from,s.to)})]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-400 transition-transform ".concat(r?"rotate-180":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})}),r&&(0,c.jsx)("div",{className:"absolute top-full left-0 z-[9999] min-w-[600px] mt-1 bg-white border border-gray-200 rounded-lg shadow-xl",children:(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsxs)("div",{className:"w-1/2 border-r border-gray-200",children:[(0,c.jsx)("div",{className:"p-3 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-sm font-semibold text-gray-900",children:"Relative time (today, 7d, 30d, MTD, YTD)"})}),(0,c.jsx)("div",{className:"h-[350px] overflow-y-auto",children:aG.map(e=>{let s=m===e.shortLabel;return(0,c.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer border-b border-gray-100 transition-colors ".concat(s?"bg-blue-50 hover:bg-blue-100 border-blue-200":"hover:bg-gray-50"),onClick:()=>N(e),children:[(0,c.jsx)("span",{className:"text-sm ".concat(s?"text-blue-700 font-medium":"text-gray-700"),children:e.label}),(0,c.jsx)("span",{className:"text-xs px-2 py-1 rounded ".concat(s?"text-blue-700 bg-blue-100":"text-gray-500 bg-gray-100"),children:e.shortLabel})]},e.label)})})]}),(0,c.jsxs)("div",{className:"w-1/2 relative",children:[(0,c.jsx)("div",{className:"p-3.5 border-b border-gray-200",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(aK.Z,{className:"text-gray-600"}),(0,c.jsx)("span",{className:"text-sm font-semibold text-gray-900",children:"Start and end dates"})]})}),(0,c.jsxs)("div",{className:"p-6 space-y-6 pb-20",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"text-sm text-gray-700 mb-1 block",children:"Start date"}),(0,c.jsx)("input",{type:"date",value:x,onChange:e=>h(e.target.value),className:"w-65 px-3 py-2 text-sm border rounded-md cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 ".concat(v.isValid?"border-gray-300":"border-red-300 focus:border-red-500 focus:ring-red-200")})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"text-sm text-gray-700 mb-1 block",children:"End date"}),(0,c.jsx)("input",{type:"date",value:p,onChange:e=>g(e.target.value),className:"w-65 px-3 py-2 text-sm border rounded-md cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 ".concat(v.isValid?"border-gray-300":"border-red-300 focus:border-red-500 focus:ring-red-200")})]}),!v.isValid&&v.error&&(0,c.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,c.jsx)("span",{className:"text-sm text-red-700 font-medium",children:v.error})]})}),n.from&&n.to&&v.isValid&&(0,c.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md",children:[(0,c.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Preview:"}),(0,c.jsx)("div",{className:"text-sm text-blue-800",children:y(n.from,n.to)})]})]}),(0,c.jsx)("div",{className:"absolute bottom-4 right-4",children:(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{o(s),s.from&&h(ah()(s.from).format("YYYY-MM-DD")),s.to&&g(ah()(s.to).format("YYYY-MM-DD")),u(f(s)),i(!1)},children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>{n.from&&n.to&&v.isValid&&(t(n),requestIdleCallback(()=>{t(_(n))},{timeout:100}),i(!1))},disabled:!n.from||!n.to||!v.isValid,children:"Apply"})]})})]})]})})]}),a&&s.from&&s.to&&(0,c.jsxs)(k.Z,{className:"mt-2 text-xs text-gray-500",children:[ah()(s.from).format("MMM D, YYYY [at] HH:mm:ss")," -"," ",ah()(s.to).format("MMM D, YYYY [at] HH:mm:ss")]})]})},aJ=e=>{let{userID:s,userRole:t,accessToken:l,userSpend:a,userMaxBudget:r,selectedTeam:i}=e;console.log("userSpend: ".concat(a));let[n,o]=(0,d.useState)(null!==a?a:0),[m,u]=(0,d.useState)(i?Number(eE(i.max_budget,4)):null);(0,d.useEffect)(()=>{if(i){if("Default Team"===i.team_alias)u(r);else{let e=!1;if(i.team_memberships)for(let t of i.team_memberships)t.user_id===s&&"max_budget"in t.litellm_budget_table&&null!==t.litellm_budget_table.max_budget&&(u(t.litellm_budget_table.max_budget),e=!0);e||u(i.max_budget)}}},[i,r]);let[x,h]=(0,d.useState)([]);(0,d.useEffect)(()=>{let e=async()=>{if(!l||!s||!t)return};(async()=>{try{if(null===s||null===t)return;if(null!==l){let e=(await (0,j.modelAvailableCall)(l,s,t)).data.map(e=>e.id);console.log("available_model_names:",e),h(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,l,s]),(0,d.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];i&&i.models&&(p=i.models),p&&p.includes("all-proxy-models")?(console.log("user models:",x),p=x):p&&p.includes("all-team-models")?p=i.models:p&&0===p.length&&(p=x);let g=null!==m?"$".concat(eE(Number(m),4)," limit"):"No limit",f=void 0!==n?eE(n,4):null;return console.log("spend in view user spend: ".concat(n)),(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,c.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",f]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,c.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:g})]})]})})};let aY=e=>{let{key:s,info:t}=e;return{token:s,...t}};var aW=e=>{let{topKeys:s,accessToken:t,userID:l,userRole:a,teams:r,premiumUser:i}=e,[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(void 0),[p,g]=(0,d.useState)("table"),f=async e=>{if(t)try{let s=await (0,j.keyInfoV1Call)(t,e.api_key),l=aY(s);h(l),u(e.api_key),o(!0)}catch(e){console.error("Error fetching key info:",e)}},v=()=>{o(!1),u(null),h(void 0)};d.useEffect(()=>{let e=e=>{"Escape"===e.key&&n&&v()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]);let y=s.map(e=>({...e,display_key_alias:e.key_alias&&e.key_alias.length>10?"".concat(e.key_alias.slice(0,10),"..."):e.key_alias||"-"}));return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>g("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===p?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,c.jsx)("button",{onClick:()=>g("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===p?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===p?(0,c.jsx)("div",{className:"relative",children:(0,c.jsx)(s3.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:y,index:"display_key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:120,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(eE(e,2)):"No Key Alias",onValueChange:e=>f(e),showTooltip:!0,customTooltip:e=>{var s,t;let l=null===(t=e.payload)||void 0===t?void 0:null===(s=t[0])||void 0===s?void 0:s.payload;return(0,c.jsx)("div",{className:"relative z-50 p-3 bg-black/90 shadow-lg rounded-lg text-white max-w-xs",children:(0,c.jsxs)("div",{className:"space-y-1.5",children:[(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Key Alias: "}),(0,c.jsx)("span",{className:"font-mono text-gray-100 break-all",children:null==l?void 0:l.key_alias})]}),(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Key ID: "}),(0,c.jsx)("span",{className:"font-mono text-gray-100 break-all",children:null==l?void 0:l.api_key})]}),(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,c.jsxs)("span",{className:"text-white font-medium",children:["$",eE(null==l?void 0:l.spend,2)]})]})]})})}})}):(0,c.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,c.jsx)(lx,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.getValue(),children:(0,c.jsx)(b.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.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(eE(e.getValue(),2))}],data:s,renderSubComponent:()=>(0,c.jsx)(c.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),n&&m&&x&&(console.log("Rendering modal with:",{isModalOpen:n,selectedKey:m,keyData:x}),(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&v()},children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,c.jsx)("button",{onClick:v,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,c.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,c.jsx)("div",{className:"p-6 h-full",children:(0,c.jsx)(sh,{keyId:m,onClose:v,keyData:x,accessToken:t,userID:l,userRole:a,teams:r,premiumUser:i})})]})}))]})};function a$(e){return e>=1e6?(e/1e6).toFixed(2)+"M":e>=1e3?e/1e3+"k":e.toString()}function aQ(e){return 0===e?"$0":e>=1e6?"$"+e/1e6+"M":e>=1e3?"$"+e/1e3+"k":"$"+e}let aX={blue:"#3b82f6",cyan:"#06b6d4",indigo:"#6366f1",green:"#22c55e",red:"#ef4444",purple:"#8b5cf6"},a0=e=>{let{active:s,payload:t,label:l}=e;if(s&&t&&t.length){let e=e=>e.replace("metrics.","").replace(/_/g," ").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),s=(e,s)=>{let t=s.substring(s.indexOf(".")+1);if(e.metrics&&t in e.metrics)return e.metrics[t]};return(0,c.jsxs)("div",{className:"w-56 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[(0,c.jsx)("p",{className:"text-tremor-content-strong",children:l}),t.map(t=>{var l;let a=null===(l=t.dataKey)||void 0===l?void 0:l.toString();if(!a||!t.payload)return null;let r=s(t.payload,a),i=a.includes("spend"),n=void 0!==r?i?"$".concat(r.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})):r.toLocaleString():"N/A",o=aX[t.color]||t.color;return(0,c.jsxs)("div",{className:"flex items-center justify-between space-x-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full ring-2 ring-white drop-shadow-md",style:{backgroundColor:o}}),(0,c.jsx)("p",{className:"font-medium text-tremor-content dark:text-dark-tremor-content",children:e(a)})]}),(0,c.jsx)("p",{className:"font-medium text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis",children:n})]},a)})]})}return null},a1=e=>{let{categories:s,colors:t}=e,l=e=>e.replace("metrics.","").replace(/_/g," ").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ");return(0,c.jsx)("div",{className:"flex items-center justify-end space-x-4",children:s.map((e,s)=>{let a=aX[t[s]]||t[s];return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full ring-4 ring-white",style:{backgroundColor:a}}),(0,c.jsx)("p",{className:"text-sm text-tremor-content dark:text-dark-tremor-content",children:l(e)})]},e)})})},a2=e=>{var s,t;let{modelName:l,metrics:a}=e;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(S.Z,{children:a.total_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Successful Requests"}),(0,c.jsx)(S.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)(S.Z,{children:a.total_tokens.toLocaleString()}),(0,c.jsxs)(k.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," ","avg per successful request"]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Spend"}),(0,c.jsxs)(S.Z,{children:["$",eE(a.total_spend,2)]}),(0,c.jsxs)(k.Z,{children:["$",eE(a.total_spend/a.total_successful_requests,3)," ","per successful request"]})]})]}),a.top_api_keys&&a.top_api_keys.length>0&&(0,c.jsxs)(G.Z,{className:"mt-4",children:[(0,c.jsx)(S.Z,{children:"Top API Keys by Spend"}),(0,c.jsx)("div",{className:"mt-3",children:(0,c.jsx)("div",{className:"grid grid-cols-1 gap-2",children:a.top_api_keys.map((e,s)=>(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 bg-gray-50 rounded-lg",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:e.key_alias||"".concat(e.api_key.substring(0,10),"...")}),e.team_id&&(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500",children:["Team: ",e.team_id]})]}),(0,c.jsxs)("div",{className:"text-right",children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["$",eE(e.spend,2)]}),(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500",children:[e.requests.toLocaleString()," requests | ",e.tokens.toLocaleString()," tokens"]})]})]},e.api_key))})})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(a1,{categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Requests per day"}),(0,c.jsx)(a1,{categories:["metrics.api_requests"],colors:["blue"]})]}),(0,c.jsx)(s3.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Spend per day"}),(0,c.jsx)(a1,{categories:["metrics.spend"],colors:["green"]})]}),(0,c.jsx)(s3.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(eE(e,2))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Success vs Failed Requests"}),(0,c.jsx)(a1,{categories:["metrics.successful_requests","metrics.failed_requests"],colors:["green","red"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["green","red"],valueFormatter:a$,stack:!0,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Prompt Caching Metrics"}),(0,c.jsx)(a1,{categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"]})]}),(0,c.jsxs)("div",{className:"mb-2",children:[(0,c.jsxs)(k.Z,{children:["Cache Read:"," ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," ","tokens"]}),(0,c.jsxs)(k.Z,{children:["Cache Creation:"," ",(null===(t=a.total_cache_creation_input_tokens)||void 0===t?void 0:t.toLocaleString())||0," ","tokens"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]})]})]})},a4=e=>{let{modelMetrics:s}=e,t=Object.keys(s).sort((e,t)=>""===e?1:""===t?-1:s[t].total_spend-s[e].total_spend),l={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{l.total_requests+=e.total_requests,l.total_successful_requests+=e.total_successful_requests,l.total_tokens+=e.total_tokens,l.total_spend+=e.total_spend,l.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,l.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{l.daily_data[e.date]||(l.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),l.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,l.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,l.daily_data[e.date].total_tokens+=e.metrics.total_tokens,l.daily_data[e.date].api_requests+=e.metrics.api_requests,l.daily_data[e.date].spend+=e.metrics.spend,l.daily_data[e.date].successful_requests+=e.metrics.successful_requests,l.daily_data[e.date].failed_requests+=e.metrics.failed_requests,l.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,l.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(l.daily_data).map(e=>{let[s,t]=e;return{date:s,metrics:t}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,c.jsxs)("div",{className:"space-y-8",children:[(0,c.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,c.jsx)(S.Z,{children:"Overall Usage"}),(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(S.Z,{children:l.total_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Successful Requests"}),(0,c.jsx)(S.Z,{children:l.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)(S.Z,{children:l.total_tokens.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Spend"}),(0,c.jsxs)(S.Z,{children:["$",eE(l.total_spend,2)]})]})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Total Tokens Over Time"}),(0,c.jsx)(a1,{categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests Over Time"}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0,customTooltip:a0,showLegend:!1})]})]})]}),(0,c.jsx)(t_.default,{defaultActiveKey:t[0],children:t.map(e=>(0,c.jsx)(t_.default.Panel,{header:(0,c.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,c.jsx)(S.Z,{children:s[e].label||"Unknown Item"}),(0,c.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,c.jsxs)("span",{children:["$",eE(s[e].total_spend,2)]}),(0,c.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," ","requests"]})]})]}),children:(0,c.jsx)(a2,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},a5=(e,s)=>{let t=e.metadata.key_alias||"key-hash-".concat(s),l=e.metadata.team_id;return l?"".concat(t," (team_id: ").concat(l,")"):t},a6=(e,s)=>{let t={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(l=>{let[a,r]=l;t[a]||(t[a]={label:"api_keys"===s?a5(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,top_api_keys:[],daily_data:[]}),t[a].total_requests+=r.metrics.api_requests,t[a].prompt_tokens+=r.metrics.prompt_tokens,t[a].completion_tokens+=r.metrics.completion_tokens,t[a].total_tokens+=r.metrics.total_tokens,t[a].total_spend+=r.metrics.spend,t[a].total_successful_requests+=r.metrics.successful_requests,t[a].total_failed_requests+=r.metrics.failed_requests,t[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,t[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,t[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),"api_keys"!==s&&Object.entries(t).forEach(l=>{let[a,r]=l,i={};e.results.forEach(e=>{var t;let l=null===(t=e.breakdown[s])||void 0===t?void 0:t[a];l&&"api_key_breakdown"in l&&Object.entries(l.api_key_breakdown||{}).forEach(e=>{let[s,t]=e;i[s]||(i[s]={api_key:s,key_alias:t.metadata.key_alias,team_id:t.metadata.team_id,spend:0,requests:0,tokens:0}),i[s].spend+=t.metrics.spend,i[s].requests+=t.metrics.api_requests,i[s].tokens+=t.metrics.total_tokens})}),t[a].top_api_keys=Object.values(i).sort((e,s)=>s.spend-e.spend).slice(0,5)}),Object.values(t).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),t};var a3=e=>{let{accessToken:s,selectedTags:t,formatAbbreviatedNumber:l}=e,[a,r]=(0,d.useState)({results:[],total_count:0,page:1,page_size:50,total_pages:0}),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(1),u=async()=>{if(s){n(!0);try{let e=await (0,j.perUserAnalyticsCall)(s,o,50,t.length>0?t:void 0);r(e)}catch(e){console.error("Failed to fetch per-user data:",e)}finally{n(!1)}}};return(0,d.useEffect)(()=>{u()},[s,t,o]),(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"Per User Usage"}),(0,c.jsx)(sz.Z,{children:"Individual developer usage metrics"}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"User Details"}),(0,c.jsx)(e0.Z,{children:"Usage Distribution"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"User Email"}),(0,c.jsx)(sI.Z,{children:"User Agent"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Success Generations"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Total Tokens"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Failed Requests"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Total Cost"})]})}),(0,c.jsx)(sk.Z,{children:a.results.slice(0,10).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-medium",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.user_email||"N/A"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.user_agent||"Unknown"})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.successful_requests)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.total_tokens)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.failed_requests)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsxs)(k.Z,{children:["$",l(e.spend,4)]})})]},s))})]}),a.results.length>10&&(0,c.jsxs)("div",{className:"mt-4 flex justify-between items-center",children:[(0,c.jsxs)(k.Z,{className:"text-sm text-gray-500",children:["Showing 10 of ",a.total_count," results"]}),(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:()=>{o>1&&m(o-1)},disabled:1===o,children:"Previous"}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:()=>{o=a.total_pages,children:"Next"})]})]})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsx)(S.Z,{className:"text-lg",children:"User Usage Distribution"}),(0,c.jsx)(sz.Z,{children:"Number of users by successful request frequency"})]}),(0,c.jsx)(s3.Z,{data:(()=>{let e=new Map;a.results.forEach(s=>{let t=s.user_agent||"Unknown";e.set(t,(e.get(t)||0)+1)});let s=Array.from(e.entries()).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).slice(0,8).map(e=>{let[s]=e;return s}),t={"1-9 requests":{range:[1,9],agents:{}},"10-99 requests":{range:[10,99],agents:{}},"100-999 requests":{range:[100,999],agents:{}},"1K-9.9K requests":{range:[1e3,9999],agents:{}},"10K-99.9K requests":{range:[1e4,99999],agents:{}},"100K+ requests":{range:[1e5,1/0],agents:{}}};return a.results.forEach(e=>{let l=e.successful_requests,a=e.user_agent||"Unknown";s.includes(a)&&Object.entries(t).forEach(e=>{let[s,t]=e;l>=t.range[0]&&l<=t.range[1]&&(t.agents[a]||(t.agents[a]=0),t.agents[a]++)})}),Object.entries(t).map(e=>{let[t,l]=e,a={category:t};return s.forEach(e=>{a[e]=l.agents[e]||0}),a})})(),index:"category",categories:(()=>{let e=new Map;return a.results.forEach(s=>{let t=s.user_agent||"Unknown";e.set(t,(e.get(t)||0)+1)}),Array.from(e.entries()).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).slice(0,8).map(e=>{let[s]=e;return s})})(),colors:["blue","green","orange","red","purple","yellow","pink","indigo"],valueFormatter:e=>"".concat(e," users"),yAxisWidth:80,showLegend:!0,stack:!0})]})]})]})]})},a8=t(49096),a7=t(53335);let{cva:a9,cx:re,compose:rs}=(0,a8.ZD)({hooks:{onComplete:e=>(0,a7.m6)(e)}});function rt(e){var s,t;let{className:l="",...a}=e,r=(0,d.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),t=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&t&&(s.currentTime=t.currentTime)},t=[r],(0,d.useLayoutEffect)(s,t),(0,c.jsxs)("svg",{"data-spinner-id":r,className:re("pointer-events-none size-12 animate-spin text-current",l),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,c.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,c.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rl=e=>{let{isDateChanging:s=!1}=e;return(0,c.jsx)("div",{className:"flex items-center justify-center h-40",children:(0,c.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,c.jsx)(rt,{className:"size-5"}),(0,c.jsxs)("div",{className:"flex flex-col",children:[(0,c.jsx)("span",{className:"text-gray-600 text-sm font-medium",children:s?"Processing date selection...":"Loading chart data..."}),(0,c.jsx)("span",{className:"text-gray-400 text-xs mt-1",children:s?"This will only take a moment":"Fetching your data"})]})]})})};var ra=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)({results:[]}),[r,i]=(0,d.useState)({results:[]}),[n,o]=(0,d.useState)({results:[]}),[m,u]=(0,d.useState)({results:[]}),[x,h]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)([]),[b,_]=(0,d.useState)([]),[N,Z]=(0,d.useState)(!1),[w,C]=(0,d.useState)(!1),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(!1),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)(!1),F=new Date,R=async()=>{if(s){Z(!0);try{let e=await (0,j.tagDistinctCall)(s);v(e.results.map(e=>e.tag))}catch(e){console.error("Failed to fetch available tags:",e)}finally{Z(!1)}}},z=async()=>{if(s){C(!0);try{let e=await (0,j.tagDauCall)(s,F,p||void 0,b.length>0?b:void 0);a(e)}catch(e){console.error("Failed to fetch DAU data:",e)}finally{C(!1)}}},U=async()=>{if(s){L(!0);try{let e=await (0,j.tagWauCall)(s,F,p||void 0,b.length>0?b:void 0);i(e)}catch(e){console.error("Failed to fetch WAU data:",e)}finally{L(!1)}}},q=async()=>{if(s){P(!0);try{let e=await (0,j.tagMauCall)(s,F,p||void 0,b.length>0?b:void 0);o(e)}catch(e){console.error("Failed to fetch MAU data:",e)}finally{P(!1)}}},B=async()=>{if(s&&x.from&&x.to){M(!0);try{let e=await (0,j.userAgentSummaryCall)(s,x.from,x.to,b.length>0?b:void 0);u(e)}catch(e){console.error("Failed to fetch user agent summary data:",e)}finally{M(!1),D(!1)}}};(0,d.useEffect)(()=>{R()},[s]),(0,d.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>{z(),U(),q()},50);return()=>clearTimeout(e)},[s,p,b]),(0,d.useEffect)(()=>{if(!x.from||!x.to)return;let e=setTimeout(()=>{B()},50);return()=>clearTimeout(e)},[s,x,b]);let K=e=>e.startsWith("User-Agent: ")?e.replace("User-Agent: ",""):e,H=e=>e.length>15?e.substring(0,15)+"...":e,J=e=>Object.entries(e.reduce((e,s)=>(e[s.tag]=(e[s.tag]||0)+s.active_users,e),{})).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).map(e=>{let[s]=e;return s}),Y=J(l.results).slice(0,10),W=J(r.results).slice(0,10),$=J(n.results).slice(0,10),Q=(()=>{let e=[],s=new Date;for(let t=6;t>=0;t--){let l=new Date(s);l.setDate(l.getDate()-t);let a={date:l.toISOString().split("T")[0]};Y.forEach(e=>{a[K(e)]=0}),e.push(a)}return l.results.forEach(s=>{let t=K(s.tag),l=e.find(e=>e.date===s.date);l&&(l[t]=s.active_users)}),e})(),X=(()=>{let e=[];for(let s=1;s<=7;s++){let t={week:"Week ".concat(s)};W.forEach(e=>{t[K(e)]=0}),e.push(t)}return r.results.forEach(s=>{let t=K(s.tag),l=s.date.match(/Week (\d+)/);if(l){let a="Week ".concat(l[1]),r=e.find(e=>e.week===a);r&&(r[t]=s.active_users)}}),e})(),ee=(()=>{let e=[];for(let s=1;s<=7;s++){let t={month:"Month ".concat(s)};$.forEach(e=>{t[K(e)]=0}),e.push(t)}return n.results.forEach(s=>{let t=K(s.tag),l=s.date.match(/Month (\d+)/);if(l){let a="Month ".concat(l[1]),r=e.find(e=>e.month===a);r&&(r[t]=s.active_users)}}),e})(),es=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e>=1e8||e>=1e7||e>=1e6?(e/1e6).toFixed(s)+"M":e>=1e4?(e/1e3).toFixed(s)+"K":e>=1e3?(e/1e3).toFixed(s)+"K":e.toFixed(s)};return(0,c.jsxs)("div",{className:"space-y-6 mt-6",children:[(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-start",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Summary by User Agent"}),(0,c.jsx)(sz.Z,{children:"Performance metrics for different user agents"})]}),(0,c.jsxs)("div",{className:"w-96",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium block mb-2",children:"Filter by User Agents"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"All User Agents",value:b,onChange:_,style:{width:"100%"},showSearch:!0,allowClear:!0,loading:N,optionFilterProp:"label",className:"rounded-md",maxTagCount:"responsive",children:f.map(e=>{let s=K(e),t=s.length>50?"".concat(s.substring(0,50),"..."):s;return(0,c.jsx)(I.default.Option,{value:e,label:t,title:s,children:t},e)})})]})]}),(0,c.jsx)(aH,{value:x,onValueChange:e=>{D(!0),M(!0),h(e)}}),E?(0,c.jsx)(rl,{isDateChanging:O}):(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4",children:[(m.results||[]).slice(0,4).map((e,s)=>{let t=K(e.tag),l=H(t);return(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(V.Z,{title:t,placement:"top",children:(0,c.jsx)(S.Z,{className:"truncate",children:l})}),(0,c.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Success Requests"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:es(e.successful_requests)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Tokens"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:es(e.total_tokens)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Cost"}),(0,c.jsxs)(aw.Z,{className:"text-lg",children:["$",es(e.total_spend,4)]})]})]})]},s)}),Array.from({length:Math.max(0,4-(m.results||[]).length)}).map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"No Data"}),(0,c.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Success Requests"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Tokens"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Cost"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]})]})]},"empty-".concat(s)))]})]})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"DAU/WAU/MAU"}),(0,c.jsx)(e0.Z,{children:"Per User Usage (Last 30 Days)"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"DAU, WAU & MAU per Agent"}),(0,c.jsx)(sz.Z,{children:"Active users across different time periods"})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"DAU"}),(0,c.jsx)(e0.Z,{children:"WAU"}),(0,c.jsx)(e0.Z,{children:"MAU"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Daily Active Users - Last 7 Days"})}),w?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:Q,index:"date",categories:Y.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Weekly Active Users - Last 7 Weeks"})}),A?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:X,index:"week",categories:W.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Monthly Active Users - Last 7 Months"})}),T?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:ee,index:"month",categories:$.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a3,{accessToken:s,selectedTags:b,formatAbbreviatedNumber:es})})]})]})})]})},rr=e=>{let{accessToken:s,entityType:t,entityId:l,userID:a,userRole:r,entityList:i,premiumUser:n}=e,[o,m]=(0,d.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),u=a6(o,"models"),x=a6(o,"api_keys"),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)({from:new Date(Date.now()-24192e5),to:new Date}),b=async()=>{if(!s||!g.from||!g.to)return;let e=new Date(g.from),l=new Date(g.to);if("tag"===t)m(await (0,j.tagDailyActivityCall)(s,e,l,1,h.length>0?h:null));else if("team"===t)m(await (0,j.teamDailyActivityCall)(s,e,l,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,d.useEffect)(()=>{b()},[s,g,l,h]);let _=()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={provider:t,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[t].spend+=l.metrics.spend,e[t].requests+=l.metrics.api_requests,e[t].successful_requests+=l.metrics.successful_requests,e[t].failed_requests+=l.metrics.failed_requests,e[t].tokens+=l.metrics.total_tokens}catch(e){console.error("Error processing provider ".concat(t,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},N=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),Z=()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:l.metadata.team_alias||t,id:t}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.total_tokens+=l.metrics.total_tokens})}),N(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,c.jsxs)("div",{style:{width:"100%"},children:[(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(aH,{value:g,onValueChange:f})}),i&&i.length>0&&(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(k.Z,{children:["Filter by ","tag"===t?"Tags":"Teams"]}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===t?"tags":"teams"," to filter..."),value:h,onChange:p,options:(()=>{if(i)return i})(),className:"mt-2",allowClear:!0})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Model Activity"}),(0,c.jsx)(e0.Z,{children:"Key Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full",children:[(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["tag"===t?"Tag":"Team"," Spend Overview"]}),(0,c.jsxs)(y.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Spend"}),(0,c.jsxs)(k.Z,{className:"text-2xl font-bold mt-2",children:["$",eE(o.metadata.total_spend,2)]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:o.metadata.total_api_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Successful Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:o.metadata.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Failed Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:o.metadata.total_failed_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:o.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend"}),(0,c.jsx)(s3.Z,{data:[...o.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let a=s[0].payload,r=Object.keys(a.breakdown.entities||{}).length;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:a.date}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",eE(a.metrics.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["tag"===t?"Total Tags":"Total Teams",": ",r]}),(0,c.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,c.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===t?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).sort((e,s)=>{let[,t]=e,[,l]=s,a=t.metrics.spend;return l.metrics.spend-a}).slice(0,5).map(e=>{let[s,t]=e;return(0,c.jsxs)("p",{className:"text-sm text-gray-600",children:[t.metadata.team_alias||s,": $",eE(t.metrics.spend,2)]},s)}),r>5&&(0,c.jsxs)("p",{className:"text-sm text-gray-500 italic",children:["...and ",r-5," more"]})]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,c.jsxs)(S.Z,{children:["Spend Per ","tag"===t?"Tag":"Team"]}),(0,c.jsx)(sz.Z,{className:"text-xs",children:"Showing Top 5 by Spend"}),(0,c.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,c.jsxs)("span",{children:["Get Started by Tracking cost per ",t," "]}),(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#spend-tracking",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-6",children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(s3.Z,{className:"mt-4 h-52",data:Z().slice(0,5).map(e=>({...e,metadata:{...e.metadata,alias_display:e.metadata.alias&&e.metadata.alias.length>15?"".concat(e.metadata.alias.slice(0,15),"..."):e.metadata.alias}})),index:"metadata.alias_display",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,layout:"vertical",showLegend:!1,yAxisWidth:150,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.metadata.alias}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.metrics.spend,4)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Requests:"," ",l.metrics.api_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-green-600",children:["Successful:"," ",l.metrics.successful_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-red-600",children:["Failed:"," ",l.metrics.failed_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens:"," ",l.metrics.total_tokens.toLocaleString()]})]})}})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)("div",{className:"h-52 overflow-y-auto",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"tag"===t?"Tag":"Team"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:Z().filter(e=>e.metrics.spend>0).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.metadata.alias}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.metrics.spend,4)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})})]})]})})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:(()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:l.metadata.key_alias,team_id:l.metadata.team_id||null}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{api_key:s,key_alias:t.metadata.key_alias||"-",spend:t.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null,premiumUser:n})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Top Models"}),(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:(()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[t].spend+=l.metrics.spend}catch(e){console.error("Error adding spend for ".concat(t,": ").concat(e,", got metrics: ").concat(JSON.stringify(l)))}e[t].requests+=l.metrics.api_requests,e[t].successful_requests+=l.metrics.successful_requests,e[t].failed_requests+=l.metrics.failed_requests,e[t].tokens+=l.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,...t}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"display_key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(eE(e,2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsx)(S.Z,{children:"Provider Usage"}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",data:_(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(eE(e,2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:_().map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[e.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(e.provider).logo,alt:"".concat(e.provider," logo"),className:"w-4 h-4",onError:s=>{let t=s.target,l=t.parentElement;if(l){var a;let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=(null===(a=e.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e.provider})]})}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.spend,2)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:u})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:x})})]})]})]})},ri=e=>{let{isOpen:s,onClose:t,accessToken:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)("cloudzero"),[p,g]=(0,d.useState)(!1);(0,d.useEffect)(()=>{s&&l&&j()},[s,l]);let j=async()=>{u(!0);try{let e=await fetch("/cloudzero/settings",{method:"GET",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(e.ok){let s=await e.json();o(s),a.setFieldsValue({connection_id:s.connection_id})}else if(404!==e.status){let s=await e.json();eo.Z.fromBackend("Failed to load existing settings: ".concat(s.error||"Unknown error"))}}catch(e){console.error("Error loading CloudZero settings:",e),eo.Z.fromBackend("Failed to load existing settings")}finally{u(!1)}},f=async e=>{if(!l){eo.Z.fromBackend("No access token available");return}i(!0);try{let s={...e,timezone:"UTC"},t=await fetch(n?"/cloudzero/settings":"/cloudzero/init",{method:n?"PUT":"POST",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify(s)}),a=await t.json();if(t.ok)return eo.Z.success(a.message||"CloudZero settings saved successfully"),o({api_key_masked:e.api_key.substring(0,4)+"****"+e.api_key.slice(-4),connection_id:e.connection_id,status:"configured"}),!0;return eo.Z.fromBackend(a.error||"Failed to save CloudZero settings"),!1}catch(e){return console.error("Error saving CloudZero settings:",e),eo.Z.fromBackend("Failed to save CloudZero settings"),!1}finally{i(!1)}},v=async()=>{if(!l){eo.Z.fromBackend("No access token available");return}g(!0);try{let e=await fetch("/cloudzero/export",{method:"POST",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({limit:1e5,operation:"replace_hourly"})}),s=await e.json();e.ok?(eo.Z.success(s.message||"Export to CloudZero completed successfully"),t()):eo.Z.fromBackend(s.error||"Failed to export to CloudZero")}catch(e){console.error("Error exporting to CloudZero:",e),eo.Z.fromBackend("Failed to export to CloudZero")}finally{g(!1)}},y=async()=>{g(!0);try{eo.Z.info("CSV export functionality coming soon!"),t()}catch(e){console.error("Error exporting CSV:",e),eo.Z.fromBackend("Failed to export CSV")}finally{g(!1)}},N=async()=>{if("cloudzero"===x){if(!n){let e=await a.validateFields();if(!await f(e))return}await v()}else await y()},Z=()=>{a.resetFields(),h("cloudzero"),o(null),t()},w=[{value:"cloudzero",label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("img",{src:"/cloudzero.png",alt:"CloudZero",className:"w-5 h-5",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)("span",{children:"Export to CloudZero"})]})},{value:"csv",label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,c.jsx)("span",{children:"Export to CSV"})]})}];return(0,c.jsx)(L.Z,{title:"Export Data",open:s,onCancel:Z,footer:null,width:600,destroyOnClose:!0,children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium mb-2 block",children:"Export Destination"}),(0,c.jsx)(I.default,{value:x,onChange:h,options:w,className:"w-full",size:"large"})]}),"cloudzero"===x&&(0,c.jsx)("div",{children:m?(0,c.jsx)("div",{className:"flex justify-center py-8",children:(0,c.jsx)(lI.Z,{size:"large"})}):(0,c.jsxs)(c.Fragment,{children:[n&&(0,c.jsx)(lB.Z,{title:"Existing CloudZero Configuration",icon:()=>(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),color:"green",className:"mb-4",children:(0,c.jsxs)(k.Z,{children:["API Key: ",n.api_key_masked,(0,c.jsx)("br",{}),"Connection ID: ",n.connection_id]})}),!n&&(0,c.jsxs)(A.Z,{form:a,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"CloudZero API Key",name:"api_key",rules:[{required:!0,message:"Please enter your CloudZero API key"}],children:(0,c.jsx)(_.Z,{type:"password",placeholder:"Enter your CloudZero API key"})}),(0,c.jsx)(A.Z.Item,{label:"Connection ID",name:"connection_id",rules:[{required:!0,message:"Please enter the CloudZero connection ID"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter CloudZero connection ID"})})]})]})}),"csv"===x&&(0,c.jsx)(lB.Z,{title:"CSV Export",icon:()=>(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),color:"blue",children:(0,c.jsx)(k.Z,{children:"Export your usage data as a CSV file for analysis in spreadsheet applications."})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 pt-4",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:Z,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:N,loading:r||p,disabled:r||p,children:"cloudzero"===x?"Export to CloudZero":"Export CSV"})]})]})})},rn=e=>{var s,t,l,a,r,i,n,o,m,u;let{accessToken:x,userRole:h,userID:p,teams:g,premiumUser:f}=e,[b,_]=(0,d.useState)({results:[],metadata:{}}),[N,Z]=(0,d.useState)(!1),[w,C]=(0,d.useState)(!1),I=(0,d.useMemo)(()=>new Date(Date.now()-6048e5),[]),A=(0,d.useMemo)(()=>new Date,[]),[L,T]=(0,d.useState)({from:I,to:A}),[P,E]=(0,d.useState)([]),[M,O]=(0,d.useState)("groups"),[D,F]=(0,d.useState)(!1),R=async()=>{x&&E(Object.values(await (0,j.tagListCall)(x)).map(e=>({label:e.name,value:e.name})))};(0,d.useEffect)(()=>{R()},[x]);let z=(null===(s=b.metadata)||void 0===s?void 0:s.total_spend)||0,U=()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{provider:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}})},q=(0,d.useCallback)(async()=>{if(!x||!L.from||!L.to)return;Z(!0);let e=new Date(L.from),s=new Date(L.to);try{try{let t=await (0,j.userDailyActivityAggregatedCall)(x,e,s);_(t);return}catch(e){}let t=await (0,j.userDailyActivityCall)(x,e,s);if(t.metadata.total_pages<=1){_(t);return}let l=[...t.results],a={...t.metadata};for(let r=2;r<=t.metadata.total_pages;r++){let t=await (0,j.userDailyActivityCall)(x,e,s,r);l.push(...t.results),t.metadata&&(a.total_spend+=t.metadata.total_spend||0,a.total_api_requests+=t.metadata.total_api_requests||0,a.total_successful_requests+=t.metadata.total_successful_requests||0,a.total_failed_requests+=t.metadata.total_failed_requests||0,a.total_tokens+=t.metadata.total_tokens||0)}_({results:l,metadata:a})}catch(e){console.error("Error fetching user spend data:",e)}finally{Z(!1),C(!1)}},[x,L.from,L.to]),B=(0,d.useCallback)(e=>{C(!0),Z(!0),T(e)},[]);(0,d.useEffect)(()=>{if(!L.from||!L.to)return;let e=setTimeout(()=>{q()},50);return()=>clearTimeout(e)},[q]);let V=a6(b,"models"),K=a6(b,"api_keys"),H=a6(b,"mcp_servers");return(0,c.jsxs)("div",{style:{width:"100%"},className:"p-8 relative",children:[(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"Global Usage"}):(0,c.jsx)(e0.Z,{children:"Your Usage"}),(0,c.jsx)(e0.Z,{children:"Team Usage"}),eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"Tag Usage"}):(0,c.jsx)(c.Fragment,{}),eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"User Agent Activity"}):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(y.Z,{numItems:2,className:"gap-10 w-1/2 mb-4",children:(0,c.jsx)(v.Z,{children:(0,c.jsx)(aH,{value:L,onValueChange:B})})}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Model Activity"}),(0,c.jsx)(e0.Z,{children:"Key Activity"}),(0,c.jsx)(e0.Z,{children:"MCP Server Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(k.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,c.jsx)(aJ,{userID:p,userRole:h,accessToken:x,userSpend:z,selectedTeam:null,userMaxBudget:null})]}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Usage Metrics"}),(0,c.jsxs)(y.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:(null===(l=b.metadata)||void 0===l?void 0:null===(t=l.total_api_requests)||void 0===t?void 0:t.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Successful Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=b.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Failed Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(n=b.metadata)||void 0===n?void 0:null===(i=n.total_failed_requests)||void 0===i?void 0:i.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:(null===(m=b.metadata)||void 0===m?void 0:null===(o=m.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Average Cost per Request"}),(0,c.jsxs)(k.Z,{className:"text-2xl font-bold mt-2",children:["$",eE((z||0)/((null===(u=b.metadata)||void 0===u?void 0:u.total_api_requests)||1),4)]})]})]})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend"}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsx)(s3.Z,{data:[...b.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.date}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.metrics.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Requests: ",l.metrics.api_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Successful: ",l.metrics.successful_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Failed: ",l.metrics.failed_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",l.metrics.total_tokens]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:l.metadata.key_alias,team_id:null}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{api_key:s,key_alias:t.metadata.key_alias||"-",spend:t.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:x,userID:p,userRole:h,teams:null,premiumUser:f})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"groups"===M?"Top Public Model Names":"Top Litellm Models"}),(0,c.jsxs)("div",{className:"flex bg-gray-100 rounded-lg p-1",children:[(0,c.jsx)("button",{className:"px-3 py-1 text-sm rounded-md transition-colors ".concat("groups"===M?"bg-white shadow-sm text-gray-900":"text-gray-600 hover:text-gray-900"),onClick:()=>O("groups"),children:"Public Model Name"}),(0,c.jsx)("button",{className:"px-3 py-1 text-sm rounded-md transition-colors ".concat("individual"===M?"bg-white shadow-sm text-gray-900":"text-gray-600 hover:text-gray-900"),onClick:()=>O("individual"),children:"Litellm Model Name"})]})]}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:"groups"===M?(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.model_groups||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})():(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:aQ,layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.key}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",l.requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-green-600",children:["Successful: ",l.successful_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-red-600",children:["Failed: ",l.failed_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",l.tokens.toLocaleString()]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(S.Z,{children:"Spend by Provider"})}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",data:U(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(eE(e,2)),colors:["cyan"]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:U().filter(e=>e.spend>0).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[e.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(e.provider).logo,alt:"".concat(e.provider," logo"),className:"w-4 h-4",onError:s=>{let t=s.target,l=t.parentElement;if(l){var a;let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=(null===(a=e.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e.provider})]})}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.spend,2)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:V})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:K})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:H})})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(rr,{accessToken:x,entityType:"team",userID:p,userRole:h,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null,premiumUser:f})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(rr,{accessToken:x,entityType:"tag",userID:p,userRole:h,entityList:P,premiumUser:f})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(ra,{accessToken:x,userRole:h})})]})]}),(0,c.jsx)(ri,{isOpen:D,onClose:()=>F(!1),accessToken:x})]})},ro=e=>{let{proxySettings:s}=e,t="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(t=s.PROXY_BASE_URL),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,c.jsx)(k.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,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"OpenAI Python SDK"}),(0,c.jsx)(e0.Z,{children:"LlamaIndex"}),(0,c.jsx)(e0.Z,{children:"Langchain Py"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(am.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(t,'" # 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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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(t,'", # 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(t,'",\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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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(t,'",\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 ')})})]})]})]})})})},rc=t(243),rd=t(93837);async function rm(e,s,t,l,a,r,i,n,o,c,d,m,u,x){console.log=function(){},console.log("isLocal:",!1);let h=(0,j.getProxyBaseUrl)(),p={};a&&a.length>0&&(p["x-litellm-tags"]=a.join(","));let g=new aa.ZP.OpenAI({apiKey:l,baseURL:h,dangerouslyAllowBrowser:!0,defaultHeaders:p});try{let a;let p=Date.now(),j=!1,k=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"".concat(h,"/mcp"),require_approval:"never",allowed_tools:u,headers:{"x-litellm-api-key":"Bearer ".concat(l)}}]:void 0;for await(let l of(await g.chat.completions.create({model:t,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:c,messages:e,...d?{vector_store_ids:d}:{},...m?{guardrails:m}:{},...k?{tools:k,tool_choice:"auto"}:{}},{signal:r}))){var f,v,y,b,_,N,Z,w;console.log("Stream chunk:",l);let e=null===(f=l.choices[0])||void 0===f?void 0:f.delta;if(console.log("Delta content:",null===(y=l.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!j&&((null===(_=l.choices[0])||void 0===_?void 0:null===(b=_.delta)||void 0===b?void 0:b.content)||e&&e.reasoning_content)&&(j=!0,a=Date.now()-p,console.log("First token received! Time:",a,"ms"),n?(console.log("Calling onTimingData with:",a),n(a)):console.log("onTimingData callback is not defined!")),null===(Z=l.choices[0])||void 0===Z?void 0:null===(N=Z.delta)||void 0===N?void 0:N.content){let e=l.choices[0].delta.content;s(e,l.model)}if(e&&e.image&&x&&(console.log("Image generated:",e.image),x(e.image.url,l.model)),e&&e.reasoning_content){let s=e.reasoning_content;i&&i(s)}if(l.usage&&o){console.log("Usage data found:",l.usage);let e={completionTokens:l.usage.completion_tokens,promptTokens:l.usage.prompt_tokens,totalTokens:l.usage.total_tokens};(null===(w=l.usage.completion_tokens_details)||void 0===w?void 0:w.reasoning_tokens)&&(e.reasoningTokens=l.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function ru(e,s,t,l,a,r){console.log=function(){},console.log("isLocal:",!1);let i=(0,j.getProxyBaseUrl)(),n=new aa.ZP.OpenAI({apiKey:l,baseURL:i,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let l=await n.images.generate({model:t,prompt:e},{signal:r});if(console.log(l.data),l.data&&l.data[0]){if(l.data[0].url)s(l.data[0].url,t);else if(l.data[0].b64_json){let e=l.data[0].b64_json;s("data:image/png;base64,".concat(e),t)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):eo.Z.fromBackend("Error occurred while generating image. Please try again. Error: ".concat(e)),e}}async function rx(e,s,t,l,a,r,i){console.log=function(){},console.log("isLocal:",!1);let n=(0,j.getProxyBaseUrl)(),o=new aa.ZP.OpenAI({apiKey:a,baseURL:n,dangerouslyAllowBrowser:!0,defaultHeaders:r&&r.length>0?{"x-litellm-tags":r.join(",")}:void 0});try{let a=Array.isArray(e)?e:[e],r=[];for(let e=0;e1&&eo.Z.success("Successfully processed ".concat(r.length," images"))}catch(e){if(console.error("Error making image edit request:",e),null==i?void 0:i.aborted)console.log("Image edits request was cancelled");else{var c;let s="Failed to edit image(s)";(null==e?void 0:null===(c=e.error)||void 0===c?void 0:c.message)?s=e.error.message:(null==e?void 0:e.message)&&(s=e.message),eo.Z.fromBackend("Image edit failed: ".concat(s))}throw e}}async function rh(e,s,t,l){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,c=arguments.length>9?arguments[9]:void 0,d=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0,u=arguments.length>12?arguments[12]:void 0,x=arguments.length>13?arguments[13]:void 0,h=arguments.length>14?arguments[14]:void 0,p=arguments.length>15?arguments[15]:void 0;if(!l)throw Error("API key is required");console.log=function(){};let g=(0,j.getProxyBaseUrl)(),f={};a&&a.length>0&&(f["x-litellm-tags"]=a.join(","));let v=new aa.ZP.OpenAI({apiKey:l,baseURL:g,dangerouslyAllowBrowser:!0,defaultHeaders:f});try{let l=Date.now(),a=!1,g=e.map(e=>(Array.isArray(e.content),{role:e.role,content:e.content,type:"message"})),j=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"litellm_proxy/mcp",require_approval:"never",allowed_tools:u}]:void 0,f=await v.responses.create({model:t,input:g,stream:!0,litellm_trace_id:c,...x?{previous_response_id:x}:{},...d?{vector_store_ids:d}:{},...m?{guardrails:m}:{},...j?{tools:j,tool_choice:"required"}:{}},{signal:r}),S="";for await(let e of f)if(console.log("Response event:",e),"object"==typeof e&&null!==e){var y,b,_,N,Z,w,k;if(((null===(y=e.type)||void 0===y?void 0:y.startsWith("response.mcp_"))||"response.output_item.done"===e.type&&((null===(b=e.item)||void 0===b?void 0:b.type)==="mcp_list_tools"||(null===(_=e.item)||void 0===_?void 0:_.type)==="mcp_call"))&&(console.log("MCP event received:",e),p)){let s={type:e.type,sequence_number:e.sequence_number,output_index:e.output_index,item_id:e.item_id||(null===(w=e.item)||void 0===w?void 0:w.id),item:e.item,delta:e.delta,arguments:e.arguments,timestamp:Date.now()};p(s)}if("response.output_item.done"===e.type&&(null===(N=e.item)||void 0===N?void 0:N.type)==="mcp_call"&&(null===(Z=e.item)||void 0===Z?void 0:Z.name)&&(S=e.item.name,console.log("MCP tool used:",S)),"response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,t),!a)){a=!0;let e=Date.now()-l;console.log("First token received! Time:",e,"ms"),n&&n(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&i&&i(s)}if("response.completed"===e.type&&"response"in e){let s=e.response,t=s.usage;if(console.log("Usage data:",t),console.log("Response completed event:",s),s.id&&h&&(console.log("Response ID for session management:",s.id),h(s.id)),t&&o){console.log("Usage data:",t);let e={completionTokens:t.output_tokens,promptTokens:t.input_tokens,totalTokens:t.total_tokens};(null===(k=t.completion_tokens_details)||void 0===k?void 0:k.reasoning_tokens)&&(e.reasoningTokens=t.completion_tokens_details.reasoning_tokens),o(e,S)}}}return f}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e)),e}}var rp=t(85498);async function rg(e,s,t,l){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,c=arguments.length>9?arguments[9]:void 0,d=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0,u=arguments.length>12?arguments[12]:void 0;if(!l)throw Error("API key is required");console.log=function(){};let x=(0,j.getProxyBaseUrl)(),h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let p=new rp.ZP({apiKey:l,baseURL:x,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let a=Date.now(),h=!1,g=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"".concat(x,"/mcp"),require_approval:"never",allowed_tools:u,headers:{"x-litellm-api-key":"Bearer ".concat(l)}}]:void 0,j={model:t,messages:e.map(e=>({role:e.role,content:e.content})),stream:!0,max_tokens:1024,litellm_trace_id:c};for await(let e of(d&&(j.vector_store_ids=d),m&&(j.guardrails=m),g&&(j.tools=g,j.tool_choice="auto"),p.messages.stream(j,{signal:r}))){if(console.log("Stream event:",e),"content_block_delta"===e.type){let l=e.delta;if(!h){h=!0;let e=Date.now()-a;console.log("First token received! Time:",e,"ms"),n&&n(e)}"text_delta"===l.type?s("assistant",l.text,t):"reasoning_delta"===l.type&&i&&i(l.text)}if("message_delta"===e.type&&e.usage&&o){let s=e.usage;console.log("Usage data found:",s);let t={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.input_tokens+s.output_tokens};o(t)}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Anthropic messages request was cancelled"):eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e)),e}}async function rj(e){try{return(await (0,j.mcpToolsCall)(e)).tools||[]}catch(e){return console.error("Error fetching MCP tools:",e),[]}}var rf=t(49817),rv=t(94263),ry=e=>{let{endpointType:s,onEndpointChange:t,className:l}=e,a=[{value:rf.KP.CHAT,label:"/v1/chat/completions"},{value:rf.KP.RESPONSES,label:"/v1/responses"},{value:rf.KP.ANTHROPIC_MESSAGES,label:"/v1/messages"},{value:rf.KP.IMAGE,label:"/v1/images/generations"},{value:rf.KP.IMAGE_EDITS,label:"/v1/images/edits"}];return(0,c.jsxs)("div",{className:l,children:[(0,c.jsx)(k.Z,{children:"Endpoint Type:"}),(0,c.jsx)(I.default,{showSearch:!0,value:s,style:{width:"100%"},onChange:t,options:a,className:"rounded-md"})]})},rb=e=>{let{onChange:s,value:t,className:l,accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,j.tagListCall)(a);console.log("List tags response:",e),i(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:t,loading:n,className:l,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},r_=t(88658),rN=t(83322),rZ=e=>{let{reasoningContent:s}=e,[t,l]=(0,d.useState)(!0);return s?(0,c.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,c.jsxs)(P.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>l(!t),icon:(0,c.jsx)(rN.Z,{}),children:[t?"Hide reasoning":"Show reasoning",t?(0,c.jsx)(tZ.Z,{className:"ml-1"}):(0,c.jsx)(la.Z,{className:"ml-1"})]}),t&&(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,c.jsx)(rc.U,{components:{code(e){let{node:s,inline:t,className:l,children:a,...r}=e,i=/language-(\w+)/.exec(l||"");return!t&&i?(0,c.jsx)(am.Z,{style:rv.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,c.jsx)("code",{className:"".concat(l," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},rw=t(71282),rk=t(11741),rS=t(16601),rC=t(58630),rI=e=>{let{timeToFirstToken:s,usage:t,toolName:l}=e;return s||t?(0,c.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,c.jsx)(V.Z,{title:"Time to first token",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(t2.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==t?void 0:t.promptTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Prompt tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rw.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["In: ",t.promptTokens]})]})}),(null==t?void 0:t.completionTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Completion tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rk.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Out: ",t.completionTokens]})]})}),(null==t?void 0:t.reasoningTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Reasoning tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rN.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Reasoning: ",t.reasoningTokens]})]})}),(null==t?void 0:t.totalTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Total tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rS.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Total: ",t.totalTokens]})]})}),l&&(0,c.jsx)(V.Z,{title:"Tool used",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Tool: ",l]})]})})]}):null},rA=t(53508);let{Dragger:rL}=ed.default;var rT=e=>{let{responsesUploadedImage:s,responsesImagePreviewUrl:t,onImageUpload:l,onRemoveImage:a}=e;return(0,c.jsx)(c.Fragment,{children:!s&&(0,c.jsx)(rL,{beforeUpload:l,accept:"image/*,.pdf",showUploadList:!1,className:"inline-block",style:{padding:0,border:"none",background:"none"},children:(0,c.jsx)(V.Z,{title:"Attach image or PDF",children:(0,c.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-md transition-colors",children:(0,c.jsx)(rA.Z,{style:{fontSize:"16px"}})})})})})};let rP=e=>new Promise((s,t)=>{let l=new FileReader;l.onload=()=>{s(l.result.split(",")[1])},l.onerror=t,l.readAsDataURL(e)}),rE=async(e,s)=>{let t=await rP(s),l=s.type||(s.name.toLowerCase().endsWith(".pdf")?"application/pdf":"image/jpeg");return{role:"user",content:[{type:"input_text",text:e},{type:"input_image",image_url:"data:".concat(l,";base64,").concat(t)}]}},rM=(e,s,t,l)=>{let a="";s&&l&&(a=l.toLowerCase().endsWith(".pdf")?"[PDF attached]":"[Image attached]");let r={role:"user",content:s?"".concat(e," ").concat(a):e};return s&&t&&(r.imagePreviewUrl=t),r},rO=e=>"user"===e.role&&"string"==typeof e.content&&(e.content.includes("[Image attached]")||e.content.includes("[PDF attached]"))&&!!e.imagePreviewUrl;var rD=t(50010),rF=e=>{let{message:s}=e;if(!rO(s))return null;let t="string"==typeof s.content&&s.content.includes("[PDF attached]");return(0,c.jsx)("div",{className:"mb-2",children:t?(0,c.jsx)("div",{className:"w-64 h-32 rounded-md border border-gray-200 bg-red-50 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"48px",color:"#dc2626"}})}):(0,c.jsx)("img",{src:s.imagePreviewUrl,alt:"User uploaded image",className:"max-w-64 rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"200px"}})})};let{Dragger:rR}=ed.default;var rz=e=>{let{chatUploadedImage:s,chatImagePreviewUrl:t,onImageUpload:l,onRemoveImage:a}=e;return(0,c.jsx)(c.Fragment,{children:!s&&(0,c.jsx)(rR,{beforeUpload:l,accept:"image/*,.pdf",showUploadList:!1,className:"inline-block",style:{padding:0,border:"none",background:"none"},children:(0,c.jsx)(V.Z,{title:"Attach image or PDF",children:(0,c.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-md transition-colors",children:(0,c.jsx)(rA.Z,{style:{fontSize:"16px"}})})})})})};let rU=e=>new Promise((s,t)=>{let l=new FileReader;l.onload=()=>{s(l.result)},l.onerror=t,l.readAsDataURL(e)}),rq=async(e,s)=>({role:"user",content:[{type:"text",text:e},{type:"image_url",image_url:{url:await rU(s)}}]}),rB=(e,s,t,l)=>{let a="";s&&l&&(a=l.toLowerCase().endsWith(".pdf")?"[PDF attached]":"[Image attached]");let r={role:"user",content:s?"".concat(e," ").concat(a):e};return s&&t&&(r.imagePreviewUrl=t),r},rV=e=>"user"===e.role&&"string"==typeof e.content&&(e.content.includes("[Image attached]")||e.content.includes("[PDF attached]"))&&!!e.imagePreviewUrl;var rK=e=>{let{message:s}=e;if(!rV(s))return null;let t="string"==typeof s.content&&s.content.includes("[PDF attached]");return(0,c.jsx)("div",{className:"mb-2",children:t?(0,c.jsx)("div",{className:"w-64 h-32 rounded-md border border-gray-200 bg-red-50 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"48px",color:"#dc2626"}})}):(0,c.jsx)("img",{src:s.imagePreviewUrl,alt:"User uploaded image",className:"max-w-64 rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"200px"}})})},rG=e=>{let{endpointType:s,responsesSessionId:t,useApiSessionManagement:l,onToggleSessionManagement:a}=e;return s!==rf.KP.RESPONSES?null:(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Session Management"}),(0,c.jsx)(V.Z,{title:"Choose between LiteLLM API session management (using previous_response_id) or UI-based session management (using chat history)",children:(0,c.jsx)(B.Z,{className:"text-gray-400",style:{fontSize:"12px"}})})]}),(0,c.jsx)(tj.Z,{checked:l,onChange:a,checkedChildren:"API",unCheckedChildren:"UI",size:"small"})]}),(0,c.jsxs)("div",{className:"text-xs p-2 rounded-md ".concat(t?"bg-green-50 text-green-700 border border-green-200":"bg-blue-50 text-blue-700 border border-blue-200"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1",children:[(0,c.jsx)(B.Z,{style:{fontSize:"12px"}}),(()=>{if(!t)return l?"API Session: Ready":"UI Session: Ready";let e=l?"Response ID":"UI Session",s=t.slice(0,10);return"".concat(e,": ").concat(s,"...")})()]}),t&&(0,c.jsx)(V.Z,{title:(0,c.jsxs)("div",{className:"text-xs",children:[(0,c.jsx)("div",{className:"mb-1",children:"Copy response ID to continue session:"}),(0,c.jsx)("div",{className:"bg-gray-800 text-gray-100 p-2 rounded font-mono text-xs whitespace-pre-wrap",children:'curl -X POST "your-proxy-url/v1/responses" \\\n -H "Authorization: Bearer your-api-key" \\\n -H "Content-Type: application/json" \\\n -d \'{\n "model": "your-model",\n "input": [{"role": "user", "content": "your message", "type": "message"}],\n "previous_response_id": "'.concat(t,'",\n "stream": true\n }\'')})]}),overlayStyle:{maxWidth:"500px"},children:(0,c.jsx)("button",{onClick:()=>{t&&(navigator.clipboard.writeText(t),eo.Z.success("Response ID copied to clipboard!"))},className:"ml-2 p-1 hover:bg-green-100 rounded transition-colors",children:(0,c.jsx)(tR.Z,{style:{fontSize:"12px"}})})})]}),(0,c.jsx)("div",{className:"text-xs opacity-75 mt-1",children:t?l?"LiteLLM API session active - context maintained server-side":"UI session active - context maintained client-side":l?"LiteLLM will manage session using previous_response_id":"UI will manage session using chat history"})]})]})};let{Text:rH}=en.default,{Panel:rJ}=t_.default;var rY=e=>{var s,t;let{events:l,className:a}=e;if(console.log("MCPEventsDisplay: Received events:",l),!l||0===l.length)return console.log("MCPEventsDisplay: No events, returning null"),null;let r=l.find(e=>{var s;return"response.output_item.done"===e.type&&(null===(s=e.item)||void 0===s?void 0:s.type)==="mcp_list_tools"&&e.item.tools&&e.item.tools.length>0}),i=l.filter(e=>{var s;return"response.output_item.done"===e.type&&(null===(s=e.item)||void 0===s?void 0:s.type)==="mcp_call"});return(console.log("MCPEventsDisplay: toolsEvent:",r),console.log("MCPEventsDisplay: mcpCallEvents:",i),r||0!==i.length)?(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 "+"mcp-events-display ".concat(a||""),children:[(0,c.jsx)(tF(),{id:"92ff055d899e6f71",children:'.openai-mcp-tools.jsx-92ff055d899e6f71{position:relative;margin:0;padding:0}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse.jsx-92ff055d899e6f71{background:transparent!important;border:none!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-item.jsx-92ff055d899e6f71{border:none!important;background:transparent!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-header.jsx-92ff055d899e6f71{padding:0 0 0 20px!important;background:transparent!important;border:none!important;font-size:14px!important;color:#9ca3af!important;font-weight:400!important;line-height:20px!important;min-height:20px!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-header.jsx-92ff055d899e6f71:hover{background:transparent!important;color:#6b7280!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-content.jsx-92ff055d899e6f71{border:none!important;background:transparent!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-content-box.jsx-92ff055d899e6f71{padding:4px 0 0 20px!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-expand-icon.jsx-92ff055d899e6f71{position:absolute!important;left:2px!important;top:2px!important;color:#9ca3af!important;font-size:10px!important;width:16px!important;height:16px!important;display:-webkit-box!important;display:-webkit-flex!important;display:-moz-box!important;display:-ms-flexbox!important;display:flex!important;-webkit-box-align:center!important;-webkit-align-items:center!important;-moz-box-align:center!important;-ms-flex-align:center!important;align-items:center!important;-webkit-box-pack:center!important;-webkit-justify-content:center!important;-moz-box-pack:center!important;-ms-flex-pack:center!important;justify-content:center!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-expand-icon.jsx-92ff055d899e6f71:hover{color:#6b7280!important}.openai-vertical-line.jsx-92ff055d899e6f71{position:absolute;left:9px;top:18px;bottom:0;width:.5px;background-color:#f3f4f6;opacity:.8}.tool-item.jsx-92ff055d899e6f71{font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:13px;color:#4b5563;line-height:18px;padding:0;margin:0;background:white;position:relative;z-index:1}.mcp-section.jsx-92ff055d899e6f71{margin-bottom:12px;background:white;position:relative;z-index:1}.mcp-section.jsx-92ff055d899e6f71:last-child{margin-bottom:0}.mcp-section-header.jsx-92ff055d899e6f71{font-size:13px;color:#6b7280;font-weight:500;margin-bottom:4px}.mcp-code-block.jsx-92ff055d899e6f71{background:#f9fafb;border:1px solid#f3f4f6;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;padding:8px;font-size:12px}.mcp-json.jsx-92ff055d899e6f71{font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace;color:#374151;margin:0;white-space:pre-wrap;word-wrap:break-word}.mcp-approved.jsx-92ff055d899e6f71{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-moz-box-align:center;-ms-flex-align:center;align-items:center;font-size:13px;color:#6b7280}.mcp-checkmark.jsx-92ff055d899e6f71{color:#10b981;margin-right:6px;font-weight:bold}.mcp-response-content.jsx-92ff055d899e6f71{font-size:13px;color:#374151;line-height:1.5;white-space:pre-wrap;font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace}'}),(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 openai-mcp-tools",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 openai-vertical-line"}),(0,c.jsxs)(t_.default,{ghost:!0,size:"small",expandIconPosition:"start",defaultActiveKey:r?["list-tools"]:i.map((e,s)=>"mcp-call-".concat(s)),children:[r&&(0,c.jsx)(rJ,{header:"List tools",children:(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71",children:null===(t=r.item)||void 0===t?void 0:null===(s=t.tools)||void 0===s?void 0:s.map((e,s)=>(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 tool-item",children:e.name},s))})},"list-tools"),i.map((e,s)=>{var t,l,a;return(0,c.jsx)(rJ,{header:(null===(t=e.item)||void 0===t?void 0:t.name)||"Tool call",children:(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71",children:[(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section-header",children:"Request"}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-code-block",children:(null===(l=e.item)||void 0===l?void 0:l.arguments)&&(0,c.jsx)("pre",{className:"jsx-92ff055d899e6f71 mcp-json",children:(()=>{try{return JSON.stringify(JSON.parse(e.item.arguments),null,2)}catch(s){return e.item.arguments}})()})})]}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-approved",children:[(0,c.jsx)("span",{className:"jsx-92ff055d899e6f71 mcp-checkmark",children:"✓"})," Approved"]})}),(null===(a=e.item)||void 0===a?void 0:a.output)&&(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section-header",children:"Response"}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-response-content",children:e.item.output})]})]})},"mcp-call-".concat(s))})]})]})]}):(console.log("MCPEventsDisplay: No valid events found, returning null"),null)},rW=t(61935),r$=t(71891),rQ=t(44625),rX=t(57400),r0=t(26430),r1=t(11894),r2=t(15883),r4=t(99890),r5=t(79276);let{TextArea:r6}=E.default,{Dragger:r3}=ed.default;var r8=e=>{let{accessToken:s,token:t,userRole:l,userID:a,disabledPersonalKeyCreation:r}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedMCPTools");try{let s=e?JSON.parse(e):[];return Array.isArray(s)?s:s?[s]:[]}catch(e){return console.error("Error parsing selectedMCPTools from sessionStorage",e),[]}}),[h,p]=(0,d.useState)(!1),[g,j]=(0,d.useState)(()=>{let e=sessionStorage.getItem("apiKeySource");if(e)try{return JSON.parse(e)}catch(e){console.error("Error parsing apiKeySource from sessionStorage",e)}return r?"custom":"session"}),[f,v]=(0,d.useState)(()=>sessionStorage.getItem("apiKey")||""),[y,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)(()=>{try{let e=sessionStorage.getItem("chatHistory");return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing chatHistory from sessionStorage",e),[]}}),[C,A]=(0,d.useState)(()=>sessionStorage.getItem("selectedModel")||void 0),[T,E]=(0,d.useState)(!1),[M,O]=(0,d.useState)([]),D=(0,d.useRef)(null),[F,R]=(0,d.useState)(()=>sessionStorage.getItem("endpointType")||rf.KP.CHAT),[z,q]=(0,d.useState)(!1),K=(0,d.useRef)(null),[H,J]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedTags");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedTags from sessionStorage",e),[]}}),[Y,W]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedVectorStores");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedVectorStores from sessionStorage",e),[]}}),[$,Q]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedGuardrails");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedGuardrails from sessionStorage",e),[]}}),[X,ee]=(0,d.useState)(()=>sessionStorage.getItem("messageTraceId")||null),[es,et]=(0,d.useState)(()=>sessionStorage.getItem("responsesSessionId")||null),[el,ea]=(0,d.useState)(()=>{let e=sessionStorage.getItem("useApiSessionManagement");return!e||JSON.parse(e)}),[er,ei]=(0,d.useState)([]),[ec,ed]=(0,d.useState)([]),[em,eu]=(0,d.useState)(null),[ex,eh]=(0,d.useState)(null),[eg,ej]=(0,d.useState)(null),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(!1),[e_,eN]=(0,d.useState)(""),[eZ,ew]=(0,d.useState)("openai"),[ek,eS]=(0,d.useState)([]),eC=(0,d.useRef)(null),eI=async()=>{let e="session"===g?s:f;if(e){p(!0);try{let s=await rj(e);m(s)}catch(e){console.error("Error fetching MCP tools:",e)}finally{p(!1)}}};(0,d.useEffect)(()=>{i&&eI()},[i,s,f,g]),(0,d.useEffect)(()=>{ey&&eN((0,r_.L)({apiKeySource:g,accessToken:s,apiKey:f,inputMessage:y,chatHistory:Z,selectedTags:H,selectedVectorStores:Y,selectedGuardrails:$,selectedMCPTools:u,endpointType:F,selectedModel:C,selectedSdk:eZ}))},[ey,eZ,g,s,f,y,Z,H,Y,$,u,F,C]),(0,d.useEffect)(()=>{let e=setTimeout(()=>{sessionStorage.setItem("chatHistory",JSON.stringify(Z))},500);return()=>{clearTimeout(e)}},[Z]),(0,d.useEffect)(()=>{sessionStorage.setItem("apiKeySource",JSON.stringify(g)),sessionStorage.setItem("apiKey",f),sessionStorage.setItem("endpointType",F),sessionStorage.setItem("selectedTags",JSON.stringify(H)),sessionStorage.setItem("selectedVectorStores",JSON.stringify(Y)),sessionStorage.setItem("selectedGuardrails",JSON.stringify($)),sessionStorage.setItem("selectedMCPTools",JSON.stringify(u)),C?sessionStorage.setItem("selectedModel",C):sessionStorage.removeItem("selectedModel"),X?sessionStorage.setItem("messageTraceId",X):sessionStorage.removeItem("messageTraceId"),es?sessionStorage.setItem("responsesSessionId",es):sessionStorage.removeItem("responsesSessionId"),sessionStorage.setItem("useApiSessionManagement",JSON.stringify(el))},[g,f,C,F,H,Y,$,X,es,el,u]),(0,d.useEffect)(()=>{let e="session"===g?s:f;if(!e||!t||!l||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,t,l,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await eU(e);console.log("Fetched models:",s),s.length>0&&(O(s),C||A(s[0].model_group))}catch(e){console.error("Error fetching model info:",e)}})(),eI()},[s,a,l,g,f,t]),(0,d.useEffect)(()=>{eC.current&&setTimeout(()=>{var e;null===(e=eC.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[Z]);let eA=(e,s,t)=>{console.log("updateTextUI called with:",e,s,t),w(l=>{let a=l[l.length-1];if(!a||a.role!==e||a.isImage)return[...l,{role:e,content:s,model:t}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:t};return[...l.slice(0,-1),e]}})},eL=e=>{w(s=>{let t=s[s.length-1];return t&&"assistant"===t.role&&!t.isImage?[...s.slice(0,s.length-1),{...t,reasoningContent:(t.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},eT=e=>{console.log("updateTimingData called with:",e),w(s=>{let t=s[s.length-1];if(console.log("Current last message:",t),t&&"assistant"===t.role){console.log("Updating assistant message with timeToFirstToken:",e);let l=[...s.slice(0,s.length-1),{...t,timeToFirstToken:e}];return console.log("Updated chat history:",l),l}return t&&"user"===t.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},eP=(e,s)=>{console.log("Received usage data:",e),w(t=>{let l=t[t.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let a={...l,usage:e,toolName:s};return console.log("Updated message:",a),[...t.slice(0,t.length-1),a]}return t})},eE=e=>{console.log("Received response ID for session management:",e),el&&et(e)},eM=e=>{console.log("ChatUI: Received MCP event:",e),eS(s=>{if(s.some(s=>s.item_id===e.item_id&&s.type===e.type&&s.sequence_number===e.sequence_number))return console.log("ChatUI: Duplicate MCP event, skipping"),s;let t=[...s,e];return console.log("ChatUI: Updated MCP events:",t),t})},eO=(e,s)=>{w(t=>[...t,{role:"assistant",content:e,model:s,isImage:!0}])},eD=(e,s)=>{w(t=>{let l=t[t.length-1];if(!l||"assistant"!==l.role||l.isImage)return[...t,{role:"assistant",content:"",model:s,image:{url:e,detail:"auto"}}];{var a;let r={...l,image:{url:e,detail:"auto"},model:null!==(a=l.model)&&void 0!==a?a:s};return[...t.slice(0,-1),r]}})},eF=e=>{ei(s=>[...s,e]);let s=URL.createObjectURL(e);return ed(e=>[...e,s]),!1},eR=e=>{ec[e]&&URL.revokeObjectURL(ec[e]),ei(s=>s.filter((s,t)=>t!==e)),ed(s=>s.filter((s,t)=>t!==e))},eq=()=>{ec.forEach(e=>{URL.revokeObjectURL(e)}),ei([]),ed([])},eB=()=>{ex&&URL.revokeObjectURL(ex),eu(null),eh(null)},eV=()=>{ef&&URL.revokeObjectURL(ef),ej(null),ev(null)},eK=async()=>{let e;if(""===y.trim())return;if(F===rf.KP.IMAGE_EDITS&&0===er.length){eo.Z.fromBackend("Please upload at least one image for editing");return}if(!t||!l||!a)return;let r="session"===g?s:f;if(!r){eo.Z.fromBackend("Please provide an API key or select Current UI Session");return}K.current=new AbortController;let i=K.current.signal;if(F===rf.KP.RESPONSES&&em)try{e=await rE(y,em)}catch(e){eo.Z.fromBackend("Failed to process image. Please try again.");return}else if(F===rf.KP.CHAT&&eg)try{e=await rq(y,eg)}catch(e){eo.Z.fromBackend("Failed to process image. Please try again.");return}else e={role:"user",content:y};let n=X||(0,rd.Z)();X||ee(n),w([...Z,F===rf.KP.RESPONSES&&em?rM(y,!0,ex||void 0,em.name):F===rf.KP.CHAT&&eg?rB(y,!0,ef||void 0,eg.name):rM(y,!1)]),eS([]),q(!0);try{if(C){if(F===rf.KP.CHAT){let s=[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:"string"==typeof t?t:""}}),e];await rm(s,(e,s)=>eA("assistant",e,s),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u,eD)}else if(F===rf.KP.IMAGE)await ru(y,(e,s)=>eO(e,s),C,r,H,i);else if(F===rf.KP.IMAGE_EDITS)er.length>0&&await rx(1===er.length?er[0]:er,y,(e,s)=>eO(e,s),C,r,H,i);else if(F===rf.KP.RESPONSES){let s;s=el&&es?[e]:[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:t}}),e],await rh(s,(e,s,t)=>eA(e,s,t),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u,el?es:null,eE,eM)}else if(F===rf.KP.ANTHROPIC_MESSAGES){let s=[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:t}}),e];await rg(s,(e,s,t)=>eA(e,s,t),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u)}}}catch(e){i.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),eA("assistant","Error fetching response:"+e))}finally{q(!1),K.current=null,F===rf.KP.IMAGE_EDITS&&eq(),F===rf.KP.RESPONSES&&em&&eB(),F===rf.KP.CHAT&&eg&&eV()}N("")};if(l&&"Admin Viewer"===l){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let eG=(0,c.jsx)(rW.Z,{style:{fontSize:24},spin:!0});return(0,c.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,c.jsx)(G.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,c.jsxs)("div",{className:"flex h-[80vh] w-full gap-4",children:[(0,c.jsxs)("div",{className:"w-1/4 p-4 bg-gray-50 overflow-y-auto",children:[(0,c.jsx)(S.Z,{className:"text-xl font-semibold mb-6 mt-2",children:"Configurations"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"mr-2"})," API Key Source"]}),(0,c.jsx)(I.default,{disabled:r,value:g,style:{width:"100%"},onChange:e=>{j(e)},options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===g&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:v,value:f,icon:lJ.Z})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(ez.Z,{className:"mr-2"})," Select Model"]}),(0,c.jsx)(I.default,{value:C,placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),A(e),E("custom"===e)},options:[...Array.from(new Set(M.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),T&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{A(e)},500)}})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(lt.Z,{className:"mr-2"})," Endpoint Type"]}),(0,c.jsx)(ry,{endpointType:F,onEndpointChange:e=>{R(e)},className:"mb-4"}),(0,c.jsx)(rG,{endpointType:F,responsesSessionId:es,useApiSessionManagement:el,onToggleSessionManagement:e=>{ea(e),e||et(null)}})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(r$.Z,{className:"mr-2"})," Tags"]}),(0,c.jsx)(rb,{value:H,onChange:J,className:"mb-4",accessToken:s||""})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2"})," MCP Tool",(0,c.jsx)(V.Z,{className:"ml-1",title:"Select MCP tools to use in your conversation, only available for /v1/responses endpoint",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select MCP tools",value:u,onChange:e=>x(e),loading:h,className:"mb-4",allowClear:!0,optionLabelProp:"label",disabled:F!==rf.KP.RESPONSES,maxTagCount:"responsive",children:Array.isArray(o)&&o.map(e=>(0,c.jsx)(I.default.Option,{value:e.name,label:(0,c.jsx)("div",{className:"font-medium",children:e.name}),children:(0,c.jsxs)("div",{className:"flex flex-col py-1",children:[(0,c.jsx)("span",{className:"font-medium",children:e.name}),(0,c.jsx)("span",{className:"text-xs text-gray-500 mt-1",children:e.description})]})},e.name))})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rQ.Z,{className:"mr-2"})," Vector Store",(0,c.jsx)(V.Z,{className:"ml-1",title:(0,c.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,c.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(U,{value:Y,onChange:W,className:"mb-4",accessToken:s||""})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rX.Z,{className:"mr-2"})," Guardrails",(0,c.jsx)(V.Z,{className:"ml-1",title:(0,c.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,c.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(st,{value:$,onChange:Q,className:"mb-4",accessToken:s||""})]})]})]}),(0,c.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,c.jsxs)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:[(0,c.jsx)(S.Z,{className:"text-xl font-semibold mb-0",children:"Test Key"}),(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{onClick:()=>{w([]),ee(null),et(null),eS([]),eq(),eB(),eV(),sessionStorage.removeItem("chatHistory"),sessionStorage.removeItem("messageTraceId"),sessionStorage.removeItem("responsesSessionId"),eo.Z.success("Chat history cleared.")},className:"bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300",icon:r0.Z,children:"Clear Chat"}),(0,c.jsx)(b.Z,{onClick:()=>eb(!0),className:"bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300",icon:r1.Z,children:"Get Code"})]})]}),(0,c.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===Z.length&&(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(ez.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(k.Z,{children:"Start a conversation or generate an image"})]}),Z.map((e,s)=>(0,c.jsx)("div",{children:(0,c.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,c.jsx)(r2.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,c.jsx)(ez.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,c.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,c.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,c.jsx)(rZ,{reasoningContent:e.reasoningContent}),"assistant"===e.role&&s===Z.length-1&&ek.length>0&&F===rf.KP.RESPONSES&&(0,c.jsx)("div",{className:"mb-3",children:(0,c.jsx)(rY,{events:ek})}),(0,c.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,c.jsx)("img",{src:"string"==typeof e.content?e.content:"",alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,c.jsxs)(c.Fragment,{children:[F===rf.KP.RESPONSES&&(0,c.jsx)(rF,{message:e}),F===rf.KP.CHAT&&(0,c.jsx)(rK,{message:e}),(0,c.jsx)(rc.U,{components:{code(e){let{node:s,inline:t,className:l,children:a,...r}=e,i=/language-(\w+)/.exec(l||"");return!t&&i?(0,c.jsx)(am.Z,{style:rv.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,c.jsx)("code",{className:"".concat(l," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...t}=e;return(0,c.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...t})}},children:"string"==typeof e.content?e.content:""}),e.image&&(0,c.jsx)("div",{className:"mt-3",children:(0,c.jsx)("img",{src:e.image.url,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}})})]}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,c.jsx)(rI,{timeToFirstToken:e.timeToFirstToken,usage:e.usage,toolName:e.toolName})]})]})})},s)),z&&ek.length>0&&F===rf.KP.RESPONSES&&Z.length>0&&"user"===Z[Z.length-1].role&&(0,c.jsx)("div",{className:"text-left mb-4",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"#ffffff",border:"1px solid #f0f0f0",textAlign:"left"},children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"#f5f5f5"},children:(0,c.jsx)(ez.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,c.jsx)("strong",{className:"text-sm capitalize",children:"Assistant"})]}),(0,c.jsx)(rY,{events:ek})]})}),z&&(0,c.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,c.jsx)(lI.Z,{indicator:eG})}),(0,c.jsx)("div",{ref:eC,style:{height:"1px"}})]}),(0,c.jsxs)("div",{className:"p-4 border-t border-gray-200 bg-white",children:[F===rf.KP.IMAGE_EDITS&&(0,c.jsx)("div",{className:"mb-4",children:0===er.length?(0,c.jsxs)(r3,{beforeUpload:eF,accept:"image/*",showUploadList:!1,className:"border-dashed border-2 border-gray-300 rounded-lg p-4",children:[(0,c.jsx)("p",{className:"ant-upload-drag-icon",children:(0,c.jsx)(r4.Z,{style:{fontSize:"24px",color:"#666"}})}),(0,c.jsx)("p",{className:"ant-upload-text text-sm",children:"Click or drag images to upload"}),(0,c.jsx)("p",{className:"ant-upload-hint text-xs text-gray-500",children:"Support for PNG, JPG, JPEG formats. Multiple images supported."})]}):(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[er.map((e,s)=>(0,c.jsxs)("div",{className:"relative inline-block",children:[(0,c.jsx)("img",{src:ec[s]||"",alt:"Upload preview ".concat(s+1),className:"max-w-32 max-h-32 rounded-md border border-gray-200 object-cover"}),(0,c.jsx)("button",{className:"absolute top-1 right-1 bg-white shadow-sm border border-gray-200 rounded px-1 py-1 text-red-500 hover:bg-red-50 text-xs",onClick:()=>eR(s),children:(0,c.jsx)(ep.Z,{})})]},s)),(0,c.jsxs)("div",{className:"flex items-center justify-center w-32 h-32 border-2 border-dashed border-gray-300 rounded-md hover:border-gray-400 cursor-pointer",onClick:()=>{var e;return null===(e=document.getElementById("additional-image-upload"))||void 0===e?void 0:e.click()},children:[(0,c.jsxs)("div",{className:"text-center",children:[(0,c.jsx)(r4.Z,{style:{fontSize:"24px",color:"#666"}}),(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Add more"})]}),(0,c.jsx)("input",{id:"additional-image-upload",type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{Array.from(e.target.files||[]).forEach(e=>eF(e))}})]})]})}),F===rf.KP.RESPONSES&&em&&(0,c.jsx)("div",{className:"mb-2",children:(0,c.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"relative inline-block",children:em.name.toLowerCase().endsWith(".pdf")?(0,c.jsx)("div",{className:"w-10 h-10 rounded-md bg-red-500 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"16px",color:"white"}})}):(0,c.jsx)("img",{src:ex||"",alt:"Upload preview",className:"w-10 h-10 rounded-md border border-gray-200 object-cover"})}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-900 truncate",children:em.name}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:em.name.toLowerCase().endsWith(".pdf")?"PDF":"Image"})]}),(0,c.jsx)("button",{className:"flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-600 hover:bg-gray-200 rounded-full transition-colors",onClick:eB,children:(0,c.jsx)(ep.Z,{style:{fontSize:"12px"}})})]})}),F===rf.KP.CHAT&&eg&&(0,c.jsx)("div",{className:"mb-2",children:(0,c.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"relative inline-block",children:eg.name.toLowerCase().endsWith(".pdf")?(0,c.jsx)("div",{className:"w-10 h-10 rounded-md bg-red-500 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"16px",color:"white"}})}):(0,c.jsx)("img",{src:ef||"",alt:"Upload preview",className:"w-10 h-10 rounded-md border border-gray-200 object-cover"})}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-900 truncate",children:eg.name}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:eg.name.toLowerCase().endsWith(".pdf")?"PDF":"Image"})]}),(0,c.jsx)("button",{className:"flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-600 hover:bg-gray-200 rounded-full transition-colors",onClick:eV,children:(0,c.jsx)(ep.Z,{style:{fontSize:"12px"}})})]})}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsxs)("div",{className:"flex items-center flex-1 bg-white border border-gray-300 rounded-xl px-3 py-1 min-h-[44px]",children:[(0,c.jsxs)("div",{className:"flex-shrink-0 mr-2",children:[F===rf.KP.RESPONSES&&!em&&(0,c.jsx)(rT,{responsesUploadedImage:em,responsesImagePreviewUrl:ex,onImageUpload:e=>(eu(e),eh(URL.createObjectURL(e)),!1),onRemoveImage:eB}),F===rf.KP.CHAT&&!eg&&(0,c.jsx)(rz,{chatUploadedImage:eg,chatImagePreviewUrl:ef,onImageUpload:e=>(ej(e),ev(URL.createObjectURL(e)),!1),onRemoveImage:eV})]}),(0,c.jsx)(r6,{value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),eK())},placeholder:F===rf.KP.CHAT||F===rf.KP.RESPONSES||F===rf.KP.ANTHROPIC_MESSAGES?"Type your message... (Shift+Enter for new line)":F===rf.KP.IMAGE_EDITS?"Describe how you want to edit the image...":"Describe the image you want to generate...",disabled:z,className:"flex-1",autoSize:{minRows:1,maxRows:4},style:{resize:"none",border:"none",boxShadow:"none",background:"transparent",padding:"4px 0",fontSize:"14px",lineHeight:"20px"}}),(0,c.jsx)(b.Z,{onClick:eK,disabled:z||!y.trim(),className:"flex-shrink-0 ml-2 !w-8 !h-8 !min-w-8 !p-0 !rounded-full !bg-blue-600 hover:!bg-blue-700 disabled:!bg-gray-300 !border-none !text-white disabled:!text-gray-500 !flex !items-center !justify-center",children:(0,c.jsx)(r5.Z,{style:{fontSize:"14px"}})})]}),z&&(0,c.jsx)(b.Z,{onClick:()=>{K.current&&(K.current.abort(),K.current=null,q(!1),eo.Z.info("Request cancelled"))},className:"bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ep.Z,children:"Cancel"})]})]})]})]})}),(0,c.jsxs)(L.Z,{title:"Generated Code",visible:ey,onCancel:()=>eb(!1),footer:null,width:800,children:[(0,c.jsxs)("div",{className:"flex justify-between items-end my-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium block mb-1 text-gray-700",children:"SDK Type"}),(0,c.jsx)(I.default,{value:eZ,onChange:e=>ew(e),style:{width:150},options:[{value:"openai",label:"OpenAI SDK"},{value:"azure",label:"Azure SDK"}]})]}),(0,c.jsx)(P.ZP,{onClick:()=>{navigator.clipboard.writeText(e_),eo.Z.success("Copied to clipboard!")},children:"Copy to Clipboard"})]}),(0,c.jsx)(am.Z,{language:"python",style:rv.Z,wrapLines:!0,wrapLongLines:!0,className:"rounded-md",customStyle:{maxHeight:"60vh",overflowY:"auto"},children:e_})]}),"custom"===g&&(0,c.jsx)(L.Z,{title:"Select MCP Tool",visible:i,onCancel:()=>n(!1),onOk:()=>{n(!1),eo.Z.success("MCP tool selection updated")},width:800,children:h?(0,c.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,c.jsx)(lI.Z,{indicator:(0,c.jsx)(rW.Z,{style:{fontSize:24},spin:!0})})}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(k.Z,{className:"text-gray-600 block mb-4",children:"Select the MCP tools you want to use in your conversation."}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select MCP tools",value:u,onChange:e=>x(e),optionLabelProp:"label",allowClear:!0,maxTagCount:"responsive",children:o.map(e=>(0,c.jsx)(I.default.Option,{value:e.name,label:(0,c.jsx)("div",{className:"font-medium",children:e.name}),children:(0,c.jsxs)("div",{className:"flex flex-col py-1",children:[(0,c.jsx)("span",{className:"font-medium",children:e.name}),(0,c.jsx)("span",{className:"text-xs text-gray-500 mt-1",children:e.description})]})},e.name))})]})})]})},r7=t(19226),r9=t(45937),ie=t(28595),is=t(68208),it=t(9775),il=t(41361),ia=t(37527),ir=t(88009),ii=t(48231),io=t(41169),ic=t(55322),id=t(11429),im=t(70525),iu=t(95805),ix=t(51817),ih=t(21047);t(22135),t(40875);var ip=t(49663);let ig=function(){for(var e=arguments.length,s=Array(e),t=0;t{(async()=>{if(s){u(!0),h(null);try{let e=await (0,j.getRemainingUsers)(s);o(e)}catch(e){console.error("Failed to fetch usage data:",e),h("Failed to load usage data")}finally{u(!1)}}})()},[s]);let{isOverLimit:p,isNearLimit:g,usagePercentage:f,userMetrics:v,teamMetrics:y}=(e=>{if(!e)return{isOverLimit:!1,isNearLimit:!1,usagePercentage:0,userMetrics:{isOverLimit:!1,isNearLimit:!1,usagePercentage:0},teamMetrics:{isOverLimit:!1,isNearLimit:!1,usagePercentage:0}};let s=!!e.total_users_remaining&&e.total_users_remaining<=0,t=!!e.total_users_remaining&&e.total_users_remaining<=5&&e.total_users_remaining>0,l=e.total_users?e.total_users_used/e.total_users*100:0,a=!!e.total_teams_remaining&&e.total_teams_remaining<=0,r=!!e.total_teams_remaining&&e.total_teams_remaining<=5&&e.total_teams_remaining>0,i=e.total_teams?e.total_teams_used/e.total_teams*100:0,n=s||a;return{isOverLimit:n,isNearLimit:(t||r)&&!n,usagePercentage:Math.max(l,i),userMetrics:{isOverLimit:s,isNearLimit:t,usagePercentage:l},teamMetrics:{isOverLimit:a,isNearLimit:r,usagePercentage:i}}})(n),b=()=>p?"red":g?"yellow":"green",_=()=>p?"Over Limit":g?"Near Limit":"Active",N=()=>p?(0,c.jsx)(lD.Z,{className:"h-3 w-3"}):g?(0,c.jsx)(im.Z,{className:"h-3 w-3"}):null;return s&&((null==n?void 0:n.total_users)!==null||(null==n?void 0:n.total_teams)!==null)?(0,c.jsx)("div",{className:"fixed bottom-4 left-4 z-50",style:{width:"".concat(Math.min(t,220),"px")},children:(0,c.jsx)(()=>{if(r){let e=p||g;return(0,c.jsx)("button",{onClick:()=>i(!1),className:ig("bg-white border border-gray-200 rounded-lg shadow-sm p-3 hover:shadow-md transition-all w-full",e&&p&&"border-red-200 bg-red-50",e&&g&&"border-yellow-200 bg-yellow-50"),title:"Show usage details",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(iu.Z,{className:"h-4 w-4 flex-shrink-0"}),e&&(0,c.jsx)("span",{className:"flex-shrink-0",children:N()}),(0,c.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium truncate",children:[n&&null!==n.total_users&&(0,c.jsxs)("span",{className:"flex-shrink-0",children:["U: ",n.total_users_used,"/",n.total_users]}),n&&null!==n.total_teams&&(0,c.jsxs)("span",{className:"flex-shrink-0",children:["T: ",n.total_teams_used,"/",n.total_teams]}),!n||null===n.total_users&&null===n.total_teams&&(0,c.jsx)("span",{className:"truncate",children:"Usage"})]})]})})}return m?(0,c.jsx)("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 w-full",children:(0,c.jsxs)("div",{className:"flex items-center justify-center gap-2 py-2",children:[(0,c.jsx)(ix.Z,{className:"h-4 w-4 animate-spin"}),(0,c.jsx)("span",{className:"text-sm text-gray-500 truncate",children:"Loading..."})]})}):x||!n?(0,c.jsx)("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 group w-full",children:(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex-1 min-w-0",children:(0,c.jsx)("span",{className:"text-sm text-gray-500 truncate block",children:x||"No data"})}),(0,c.jsx)("button",{onClick:()=>i(!0),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-gray-100 rounded transition-all flex-shrink-0",title:"Minimize",children:(0,c.jsx)(ih.Z,{className:"h-3 w-3 text-gray-400"})})]})}):(0,c.jsxs)("div",{className:ig("bg-white border rounded-lg shadow-sm p-3 transition-all duration-200 group w-full",p&&"border-red-200 bg-red-50",g&&"border-yellow-200 bg-yellow-50"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,c.jsx)(iu.Z,{className:"h-4 w-4 flex-shrink-0"}),(0,c.jsx)("span",{className:"font-medium text-sm truncate",children:"Usage"}),(p||g)&&(0,c.jsx)(eX.Z,{color:b(),className:"text-xs px-1.5 py-0.5 flex-shrink-0",children:_()})]}),(0,c.jsx)("button",{onClick:()=>i(!0),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-gray-100 rounded transition-all flex-shrink-0",title:"Minimize",children:(0,c.jsx)(ih.Z,{className:"h-3 w-3 text-gray-400"})})]}),(0,c.jsxs)("div",{className:"space-y-3 text-sm",children:[null!==n.total_users&&(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-600 mb-1",children:[(0,c.jsx)(iu.Z,{className:"h-3 w-3"}),(0,c.jsx)("span",{className:"font-medium",children:"Users"})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Used:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[n.total_users_used,"/",n.total_users]})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Remaining:"}),(0,c.jsx)("span",{className:ig("font-medium text-right",v.isOverLimit&&"text-red-600",v.isNearLimit&&"text-yellow-600"),children:n.total_users_remaining})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Usage:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[Math.round(v.usagePercentage),"%"]})]}),(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,c.jsx)("div",{className:ig("h-2 rounded-full transition-all duration-300",v.isOverLimit&&"bg-red-500",v.isNearLimit&&"bg-yellow-500",!v.isOverLimit&&!v.isNearLimit&&"bg-green-500"),style:{width:"".concat(Math.min(v.usagePercentage,100),"%")}})})]}),null!==n.total_teams&&(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-600 mb-1",children:[(0,c.jsx)(ip.Z,{className:"h-3 w-3"}),(0,c.jsx)("span",{className:"font-medium",children:"Teams"})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Used:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[n.total_teams_used,"/",n.total_teams]})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Remaining:"}),(0,c.jsx)("span",{className:ig("font-medium text-right",y.isOverLimit&&"text-red-600",y.isNearLimit&&"text-yellow-600"),children:n.total_teams_remaining})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Usage:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[Math.round(y.usagePercentage),"%"]})]}),(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,c.jsx)("div",{className:ig("h-2 rounded-full transition-all duration-300",y.isOverLimit&&"bg-red-500",y.isNearLimit&&"bg-yellow-500",!y.isOverLimit&&!y.isNearLimit&&"bg-green-500"),style:{width:"".concat(Math.min(y.usagePercentage,100),"%")}})})]})]})]})},{})}):null}var iv=t(13959);let{Sider:iy}=r7.default;var ib=e=>{let{accessToken:s,setPage:t,userRole:l,defaultSelectedKey:a,collapsed:r=!1}=e,i=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,c.jsx)(lJ.Z,{style:{fontSize:"18px"}})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,c.jsx)(ie.Z,{style:{fontSize:"18px"}}),roles:eI.LQ},{key:"2",page:"models",label:"Models + Endpoints",icon:(0,c.jsx)(is.Z,{style:{fontSize:"18px"}}),roles:eI.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,c.jsx)(it.Z,{style:{fontSize:"18px"}}),roles:[...eI.ZL,...eI.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,c.jsx)(il.Z,{style:{fontSize:"18px"}})},{key:"17",page:"organizations",label:"Organizations",icon:(0,c.jsx)(ia.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,c.jsx)(r2.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,c.jsx)(lt.Z,{style:{fontSize:"18px"}})},{key:"16",page:"model-hub-table",label:"Model Hub",icon:(0,c.jsx)(ir.Z,{style:{fontSize:"18px"}})},{key:"15",page:"logs",label:"Logs",icon:(0,c.jsx)(ii.Z,{style:{fontSize:"18px"}})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,c.jsx)(rX.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"26",page:"tools",label:"Tools",icon:(0,c.jsx)(rC.Z,{style:{fontSize:"18px"}}),children:[{key:"18",page:"mcp-servers",label:"MCP Servers",icon:(0,c.jsx)(rC.Z,{style:{fontSize:"18px"}})},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,c.jsx)(rQ.Z,{style:{fontSize:"18px"}}),roles:eI.ZL}]},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,c.jsx)(io.Z,{style:{fontSize:"18px"}}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,c.jsx)(rQ.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"25",page:"prompts",label:"Prompts",icon:(0,c.jsx)(eh.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,c.jsx)(ia.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,c.jsx)(lt.Z,{style:{fontSize:"18px"}}),roles:[...eI.ZL,...eI.lo]},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,c.jsx)(r$.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,c.jsx)(it.Z,{style:{fontSize:"18px"}})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"14",page:"ui-theme",label:"UI Theme",icon:(0,c.jsx)(id.Z,{style:{fontSize:"18px"}}),roles:eI.ZL}]}],n=(e=>{let s=i.find(s=>s.page===e);if(s)return s.key;for(let s of i)if(s.children){let t=s.children.find(s=>s.page===e);if(t)return t.key}return"1"})(a),o=i.filter(e=>{let s=!e.roles||e.roles.includes(l);return console.log("Menu item ".concat(e.label,": roles=").concat(e.roles,", userRole=").concat(l,", hasAccess=").concat(s)),!!s&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0)});return(0,c.jsx)(r7.default,{style:{minHeight:"100vh"},children:(0,c.jsxs)(iy,{theme:"light",width:220,collapsed:r,collapsedWidth:80,collapsible:!0,trigger:null,style:{transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",position:"relative"},children:[(0,c.jsx)(iv.ZP,{theme:{components:{Menu:{iconSize:18,fontSize:14}}},children:(0,c.jsx)(r9.Z,{mode:"inline",selectedKeys:[n],defaultOpenKeys:r?[]:["llm-tools"],inlineCollapsed:r,className:"custom-sidebar-menu",style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:o.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())),t(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())),t(e.page)}}})})}),(0,eI.tY)(l)&&!r&&(0,c.jsx)(ij,{accessToken:s,width:220})]})})},i_=t(96889),iN=t(92414),iZ=t(46030);console.log("process.env.NODE_ENV","production");let iw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ik=e=>{let{accessToken:s,token:t,userRole:l,userID:a,keys:r,premiumUser:i}=e,n=new Date,[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)([]),[_,N]=(0,d.useState)([]),[Z,w]=(0,d.useState)([]),[C,I]=(0,d.useState)([]),[A,L]=(0,d.useState)([]),[T,P]=(0,d.useState)([]),[E,M]=(0,d.useState)([]),[O,D]=(0,d.useState)({}),[F,R]=(0,d.useState)([]),[z,U]=(0,d.useState)(""),[q,B]=(0,d.useState)(["all-tags"]),[V,K]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,d.useState)(null),[Y,W]=(0,d.useState)(0),$=new Date(n.getFullYear(),n.getMonth(),1),Q=new Date(n.getFullYear(),n.getMonth()+1,0),X=er($),ee=er(Q);function es(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",i);let et=async()=>{if(s)try{let e=await (0,j.getProxyUISettings)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,d.useEffect)(()=>{ea(V.from,V.to)},[V,q]);let el=async(e,t,l)=>{if(!e||!t||!s)return;console.log("uiSelectedKey",l);let a=await (0,j.adminTopEndUsersCall)(s,l,e.toISOString(),t.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,t)=>{if(!e||!t||!s)return;let l=await et();null!=l&&l.DISABLE_EXPENSIVE_DB_QUERIES||(w((await (0,j.tagsSpendLogsCall)(s,e.toISOString(),t.toISOString(),0===q.length?void 0:q)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),t=e.getMonth()+1,l=e.getDate();return"".concat(s,"-").concat(t<10?"0"+t:t,"-").concat(l<10?"0"+l:l)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(ee));let en=async(e,s,t)=>{try{let t=await e();s(t)}catch(e){console.error(t,e)}},eo=(e,s,t,l)=>{let a=[],r=new Date(s),i=e=>{if(e.includes("-"))return e;{let[s,t]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(t)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let s=i(e.date);return[s,{...e,date:s}]}));for(;r<=t;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let s={date:e,api_requests:0,total_tokens:0};l.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},ec=async()=>{if(s)try{let e=await (0,j.adminSpendLogsCall)(s),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=eo(e,l,a,[]),i=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>en(()=>s&&t?(0,j.adminspendByProvider)(s,t,X,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),em=async()=>{s&&await en(async()=>(await (0,j.adminTopKeysCall)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),x,"Error fetching top keys")},eu=async()=>{s&&await en(async()=>(await (0,j.adminTopModelsCall)(s)).map(e=>({key:e.model,spend:eE(e.total_spend,2)})),p,"Error fetching top models")},ex=async()=>{s&&await en(async()=>{let e=await (0,j.teamSpendLogsCall)(s),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0);return N(eo(e.daily_spend,l,a,e.teams)),L(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:eE(e.total_spend||0,2)}))},P,"Error fetching team spend")},eh=()=>{s&&en(async()=>(await (0,j.allTagNamesCall)(s)).tag_names,I,"Error fetching tag names")},ep=()=>{s&&en(()=>{var e,t;return(0,j.tagsSpendLogsCall)(s,null===(e=V.from)||void 0===e?void 0:e.toISOString(),null===(t=V.to)||void 0===t?void 0:t.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},eg=()=>{s&&en(()=>(0,j.adminTopEndUsersCall)(s,null,void 0,void 0),f,"Error fetching top end users")},ej=async()=>{if(s)try{let e=await (0,j.adminGlobalActivity)(s,X,ee),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=eo(e.daily_data||[],l,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ef=async()=>{if(s)try{let e=await (0,j.adminGlobalActivityPerModel)(s,X,ee),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=e.map(e=>({...e,daily_data:eo(e.daily_data||[],l,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,d.useEffect)(()=>{(async()=>{if(s&&t&&l&&a){let e=await et();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),ec(),ed(),em(),eu(),ej(),ef(),iw(l)&&(ex(),eh(),ep(),eg()))}})()},[s,t,l,a,X,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,c.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,c.jsxs)(k.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,c.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,c.jsx)(b.Z,{className:"mt-4",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,c.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mt-2",children:[(0,c.jsx)(e0.Z,{children:"All Up"}),iw(l)?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(e0.Z,{children:"Team Based Usage"}),(0,c.jsx)(e0.Z,{children:"Customer Usage"}),(0,c.jsx)(e0.Z,{children:"Tag Based Usage"})]}):(0,c.jsx)(c.Fragment,{children:(0,c.jsx)("div",{})})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(k.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,c.jsx)(aJ,{userID:a,userRole:l,accessToken:s,userSpend:Y,selectedTeam:null,userMaxBudget:null})]}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Monthly Spend"}),(0,c.jsx)(s3.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(eE(e,2)),yAxisWidth:100,tickGap:5})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:u,accessToken:s,userID:a,userRole:l,teams:null,premiumUser:i})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top Models"}),(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(eE(e,2))})]})}),(0,c.jsx)(v.Z,{numColSpan:1}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{className:"mb-2",children:[(0,c.jsx)(S.Z,{children:"Spend by Provider"}),(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(eE(e,2))})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"})]})}),(0,c.jsx)(sk.Z,{children:E.map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.provider}),(0,c.jsx)(sS.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":eE(e.spend,2)})]},e.provider))})]})})]})})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"All Up"}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",es(O.sum_api_requests)]}),(0,c.jsx)(s6.Z,{className:"h-40",data:O.daily_data,valueFormatter:es,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",es(O.sum_total_tokens)]}),(0,c.jsx)(s3.Z,{className:"h-40",data:O.daily_data,valueFormatter:es,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,c.jsx)(c.Fragment,{children:F.map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.model}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",es(e.sum_api_requests)]}),(0,c.jsx)(s6.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:es,onValueChange:e=>console.log(e)})]}),(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",es(e.sum_total_tokens)]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:es,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(G.Z,{className:"mb-2",children:[(0,c.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,c.jsx)(i_.Z,{data:T})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,c.jsx)(s3.Z,{className:"h-72",data:_,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,c.jsx)(v.Z,{numColSpan:2})]})}),(0,c.jsxs)(e4.Z,{children:[(0,c.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,c.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:V,onValueChange:e=>{K(e),el(e.from,e.to,null)}})}),(0,c.jsxs)(v.Z,{children:[(0,c.jsx)(k.Z,{children:"Select Key"}),(0,c.jsxs)(eQ.Z,{defaultValue:"all-keys",children:[(0,c.jsx)(ei.Z,{value:"all-keys",onClick:()=>{el(V.from,V.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,c.jsx)(ei.Z,{value:String(s),onClick:()=>{el(V.from,V.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,c.jsx)(G.Z,{className:"mt-4",children:(0,c.jsxs)(sw.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Customer"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{children:"Total Events"})]})}),(0,c.jsx)(sk.Z,{children:null==g?void 0:g.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.end_user}),(0,c.jsx)(sS.Z,{children:eE(e.total_spend,2)}),(0,c.jsx)(sS.Z,{children:e.total_count})]},s))})]})})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(s5,{className:"mb-4",value:V,onValueChange:e=>{K(e),ea(e.from,e.to)}})}),(0,c.jsx)(v.Z,{children:i?(0,c.jsx)("div",{children:(0,c.jsxs)(iN.Z,{value:q,onValueChange:e=>B(e),children:[(0,c.jsx)(iZ.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,s)=>(0,c.jsx)(iZ.Z,{value:String(e),children:e},e))]})}):(0,c.jsx)("div",{children:(0,c.jsxs)(iN.Z,{value:q,onValueChange:e=>B(e),children:[(0,c.jsx)(iZ.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,s)=>(0,c.jsxs)(ei.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Spend Per Tag"}),(0,c.jsxs)(k.Z,{children:["Get Started by Tracking cost per tag ",(0,c.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,c.jsx)(s3.Z,{className:"h-72",data:Z,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,c.jsx)(v.Z,{numColSpan:2})]})]})]})]})})},iS=t(51853);let iC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,c.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,c.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,c.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,c.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},iI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},iA=e=>{let{label:s,value:t}=e,[l,a]=d.useState(!1),[r,i]=d.useState(!1),n=(null==t?void 0:t.toString())||"N/A",o=n.length>50?n.substring(0,50)+"...":n;return(0,c.jsx)("tr",{className:"hover:bg-gray-50",children:(0,c.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,c.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,c.jsxs)("div",{className:"flex items-center flex-1",children:[(0,c.jsx)("button",{onClick:()=>a(!l),className:"text-gray-400 hover:text-gray-600 mr-2",children:l?"▼":"▶"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,c.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:l?n:o})]})]}),(0,c.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,c.jsx)(iS.Z,{className:"h-4 w-4"})})]})})})},iL=e=>{var s,t,l,a,r,i,n,o,d,m,u,x,h,p;let{response:g}=e,j=null,f={},v={};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=iI(j.litellm_params)||{},v=iI(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=iI(null==g?void 0:g.litellm_cache_params)||{},v=iI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},v={}}let y={redis_host:(null==v?void 0:null===(l=v.redis_client)||void 0===l?void 0:null===(t=l.connection_pool)||void 0===t?void 0:null===(s=t.connection_kwargs)||void 0===s?void 0:s.host)||(null==v?void 0:null===(i=v.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)||(null==v?void 0:null===(n=v.connection_kwargs)||void 0===n?void 0:n.host)||(null==v?void 0:v.host)||"N/A",redis_port:(null==v?void 0:null===(m=v.redis_client)||void 0===m?void 0:null===(d=m.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==v?void 0:null===(h=v.redis_async_client)||void 0===h?void 0:null===(x=h.connection_pool)||void 0===x?void 0:null===(u=x.connection_kwargs)||void 0===u?void 0:u.port)||(null==v?void 0:null===(p=v.connection_kwargs)||void 0===p?void 0:p.port)||(null==v?void 0:v.port)||"N/A",redis_version:(null==v?void 0:v.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,t,l,a,r,i,n,o,c,d,m,u;if(null==v?void 0:null===(e=v.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(v.redis_kwargs.startup_nodes);let x=(null==v?void 0:null===(l=v.redis_client)||void 0===l?void 0:null===(t=l.connection_pool)||void 0===t?void 0:null===(s=t.connection_kwargs)||void 0===s?void 0:s.host)||(null==v?void 0:null===(i=v.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),h=(null==v?void 0:null===(c=v.redis_client)||void 0===c?void 0:null===(o=c.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==v?void 0:null===(u=v.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(d=m.connection_kwargs)||void 0===d?void 0:d.port);return x&&h?JSON.stringify([{host:x,port:h}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==v?void 0:v.namespace)||"N/A"};return(0,c.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"border-b border-gray-200 px-4",children:[(0,c.jsx)(e0.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,c.jsx)(e0.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{className:"p-4",children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsxs)(k.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,c.jsx)("table",{className:"w-full border-collapse",children:(0,c.jsxs)("tbody",{children:[j&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,c.jsx)(iA,{label:"Error Message",value:j.message}),(0,c.jsx)(iA,{label:"Traceback",value:j.traceback})]}),(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,c.jsx)(iA,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,c.jsx)(iA,{label:"Ping Response",value:String(g.ping_response)}),(0,c.jsx)(iA,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,c.jsx)(iA,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,c.jsx)(iA,{label:"Redis Host",value:y.redis_host||"N/A"}),(0,c.jsx)(iA,{label:"Redis Port",value:y.redis_port||"N/A"}),(0,c.jsx)(iA,{label:"Redis Version",value:y.redis_version||"N/A"}),(0,c.jsx)(iA,{label:"Startup Nodes",value:y.startup_nodes||"N/A"}),(0,c.jsx)(iA,{label:"Namespace",value:y.namespace||"N/A"})]})]})})]})}),(0,c.jsx)(e4.Z,{className:"p-4",children:(0,c.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,c.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:v},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},iT=e=>{let{accessToken:s,healthCheckResponse:t,runCachingHealthCheck:l,responseTimeMs:a}=e,[r,i]=d.useState(null),[n,o]=d.useState(!1),m=async()=>{o(!0);let e=performance.now();await l(),i(performance.now()-e),o(!1)};return(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)(b.Z,{onClick:m,disabled:n,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:n?"Running Health Check...":"Run Health Check"}),(0,c.jsx)(iC,{responseTimeMs:r})]}),t&&(0,c.jsx)(iL,{response:t})]})},iP=e=>{if(e)return e.toISOString().split("T")[0]};function iE(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var iM=e=>{let{accessToken:s,token:t,userRole:l,userID:a,premiumUser:r}=e,[i,n]=(0,d.useState)([]),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)("0"),[b,_]=(0,d.useState)("0"),[N,Z]=(0,d.useState)("0"),[w,S]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,d.useState)(""),[A,L]=(0,d.useState)("");(0,d.useEffect)(()=>{s&&w&&((async()=>{p(await (0,j.adminGlobalCacheActivity)(s,iP(w.from),iP(w.to)))})(),I(new Date().toLocaleString()))},[s]);let T=Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),P=Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let E=async(e,t)=>{e&&t&&s&&p(await (0,j.adminGlobalCacheActivity)(s,iP(e),iP(t)))};(0,d.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",h);let e=h;o.length>0&&(e=e.filter(e=>o.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 s=0,t=0,l=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"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),t+=a.cache_hit_true_rows||0,l+=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(iE(t)),_(iE(l));let r=t+s;r>0?Z((t/r*100).toFixed(2)):Z("0"),n(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,u,w,h]);let M=async()=>{try{eo.Z.info("Running cache health check..."),L("");let e=await (0,j.cachingHealthCheckCall)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),L(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let t=JSON.parse(s.message);t.error&&(t=t.error),e=t}catch(t){e={message:s.message}}else e={message:"Unknown error occurred"};L({error:e})}};return(0,c.jsxs)(e1.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"Cache Analytics"}),(0,c.jsx)(e0.Z,{children:(0,c.jsx)("pre",{children:"Cache Health"})})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",C]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(y.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(iN.Z,{placeholder:"Select API Keys",value:o,onValueChange:m,children:T.map(e=>(0,c.jsx)(iZ.Z,{value:e,children:e},e))})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(iN.Z,{placeholder:"Select Models",value:u,onValueChange:x,children:P.map(e=>(0,c.jsx)(iZ.Z,{value:e,children:e},e))})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:w,onValueChange:e=>{S(e),E(e.from,e.to)}})})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[N,"%"]})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:b})})]})]}),(0,c.jsx)(sz.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,c.jsx)(s3.Z,{title:"Cache Hits vs API Requests",data:i,stack:!0,index:"name",valueFormatter:iE,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,c.jsx)(sz.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,c.jsx)(s3.Z,{className:"mt-6",data:i,stack:!0,index:"name",valueFormatter:iE,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(iT,{accessToken:s,healthCheckResponse:A,runCachingHealthCheck:M})})]})]})},iO=t(91810);(a=n||(n={})).PresidioPII="Presidio PII",a.Bedrock="Bedrock Guardrail",a.Lakera="Lakera";let iD={},iF=e=>{let s={};return s.PresidioPII="Presidio PII",s.Bedrock="Bedrock Guardrail",s.Lakera="Lakera",Object.entries(e).forEach(e=>{let[t,l]=e;l&&"object"==typeof l&&"ui_friendly_name"in l&&(s[t.split("_").map((e,s)=>e.charAt(0).toUpperCase()+e.slice(1)).join("")]=l.ui_friendly_name)}),iD=s,s},iR=()=>Object.keys(iD).length>0?iD:n,iz={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},iU=e=>{Object.entries(e).forEach(e=>{let[s,t]=e;t&&"object"==typeof t&&"ui_friendly_name"in t&&(iz[s.split("_").map((e,s)=>e.charAt(0).toUpperCase()+e.slice(1)).join("")]=s)})},iq=e=>!!e&&"Presidio PII"===iR()[e],iB="../ui/assets/logos/",iV={"Presidio PII":"".concat(iB,"presidio.png"),"Bedrock Guardrail":"".concat(iB,"bedrock.svg"),Lakera:"".concat(iB,"lakeraai.jpeg"),"Azure Content Safety Prompt Shield":"".concat(iB,"presidio.png"),"Azure Content Safety Text Moderation":"".concat(iB,"presidio.png")},iK=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(iz).find(s=>iz[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let t=iR()[s];return{logo:iV[t]||"",displayName:t||e}};var iG=t(33866),iH=t(97416),iJ=t(10798),iY=t(49638);let{Text:iW}=en.default,{Option:i$}=I.default,iQ=e=>e.replace(/_/g," "),iX=e=>{switch(e){case"MASK":return(0,c.jsx)(iH.Z,{style:{marginRight:4}});case"BLOCK":return(0,c.jsx)(t4.Z,{style:{marginRight:4}});default:return null}},i0=e=>{let{categories:s,selectedCategories:t,onChange:l}=e;return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)(iJ.Z,{className:"text-gray-500 mr-1"}),(0,c.jsx)(iW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:l,value:t,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,c.jsx)(t1.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,c.jsx)(i$,{value:e.category,children:e.category},e.category))})]})},i1=e=>{let{onSelectAll:s,onUnselectAll:t,hasSelectedEntities:l}=e;return(0,c.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(iW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,c.jsx)(V.Z,{title:"Apply action to all PII types at once",children:(0,c.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,c.jsx)(P.ZP,{type:"default",onClick:t,disabled:!l,icon:(0,c.jsx)(iY.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsx)(P.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,c.jsx)(iH.Z,{}),children:"Select All & Mask"}),(0,c.jsx)(P.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,c.jsx)(t4.Z,{}),children:"Select All & Block"})]})]})},i2=e=>{let{entities:s,selectedEntities:t,selectedActions:l,actions:a,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:n}=e;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,c.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,c.jsx)(iW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,c.jsx)(iW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,c.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,c.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,c.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(t.includes(e)?"bg-blue-50":""),children:[(0,c.jsxs)("div",{className:"flex items-center flex-1",children:[(0,c.jsx)(ts.Z,{checked:t.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,c.jsx)(iW,{className:t.includes(e)?"font-medium text-gray-900":"text-gray-700",children:iQ(e)}),n.get(e)&&(0,c.jsx)(t1.Z,{className:"ml-2 text-xs",color:"blue",children:n.get(e)})]}),(0,c.jsx)("div",{className:"w-32",children:(0,c.jsx)(I.default,{value:t.includes(e)&&l[e]||"MASK",onChange:s=>i(e,s),style:{width:120},disabled:!t.includes(e),className:"".concat(t.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,c.jsx)(i$,{value:e,children:(0,c.jsxs)("div",{className:"flex items-center",children:[iX(e),e]})},e))})})]},e))})]})},{Title:i4,Text:i5}=en.default;var i6=e=>{let{entities:s,actions:t,selectedEntities:l,selectedActions:a,onEntitySelect:r,onActionSelect:i,entityCategories:n=[]}=e,[o,m]=(0,d.useState)([]),u=new Map;n.forEach(e=>{e.entities.forEach(s=>{u.set(s,e.category)})});let x=s.filter(e=>0===o.length||o.includes(u.get(e)||""));return(0,c.jsxs)("div",{className:"pii-configuration",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)(i4,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,c.jsx)(iG.Z,{count:l.length,showZero:!0,style:{backgroundColor:l.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,c.jsxs)(i5,{className:"text-gray-500",children:[l.length," items selected"]})})]}),(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(i0,{categories:n,selectedCategories:o,onChange:m}),(0,c.jsx)(i1,{onSelectAll:e=>{s.forEach(s=>{l.includes(s)||r(s),i(s,e)})},onUnselectAll:()=>{l.forEach(e=>{r(e)})},hasSelectedEntities:l.length>0})]}),(0,c.jsx)(i2,{entities:x,selectedEntities:l,selectedActions:a,actions:t,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:u})]})},i3=e=>{var s;let{selectedProvider:t,accessToken:l,providerParams:a=null,value:r=null}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(a),[u,x]=(0,d.useState)(null);if((0,d.useEffect)(()=>{if(a){m(a);return}let e=async()=>{if(l){n(!0),x(null);try{let e=await (0,j.getGuardrailProviderSpecificParams)(l);console.log("Provider params API response:",e),m(e),iF(e),iU(e)}catch(e){console.error("Error fetching provider params:",e),x("Failed to load provider parameters")}finally{n(!1)}}};a||e()},[l,a]),!t)return null;if(i)return(0,c.jsx)(lI.Z,{tip:"Loading provider parameters..."});if(u)return(0,c.jsx)("div",{className:"text-red-500",children:u});let h=null===(s=iz[t])||void 0===s?void 0:s.toLowerCase(),p=o&&o[h];if(console.log("Provider key:",h),console.log("Provider fields:",p),!p||0===Object.keys(p).length)return(0,c.jsx)("div",{children:"No configuration fields available for this provider."});console.log("Value:",r);let g=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2?arguments[2]:void 0;return Object.entries(e).map(e=>{let[l,a]=e,i=s?"".concat(s,".").concat(l):l,n=t?t[l]:null==r?void 0:r[l];return(console.log("Field value:",n),"ui_friendly_name"===l||"optional_params"===l&&"nested"===a.type&&a.fields)?null:"nested"===a.type&&a.fields?(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"mb-2 font-medium",children:l}),(0,c.jsx)("div",{className:"ml-4 border-l-2 border-gray-200 pl-4",children:g(a.fields,i,n)})]},i):(0,c.jsx)(A.Z.Item,{name:i,label:l,tooltip:a.description,rules:a.required?[{required:!0,message:"".concat(l," is required")}]:void 0,children:"select"===a.type&&a.options?(0,c.jsx)(I.default,{placeholder:a.description,defaultValue:n||a.default_value,children:a.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"multiselect"===a.type&&a.options?(0,c.jsx)(I.default,{mode:"multiple",placeholder:a.description,defaultValue:n||a.default_value,children:a.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"bool"===a.type||"boolean"===a.type?(0,c.jsxs)(I.default,{placeholder:a.description,defaultValue:void 0!==n?String(n):a.default_value,children:[(0,c.jsx)(I.default.Option,{value:"true",children:"True"}),(0,c.jsx)(I.default.Option,{value:"false",children:"False"})]}):"number"===a.type?(0,c.jsx)(O,{step:1,width:400,placeholder:a.description,defaultValue:void 0!==n?Number(n):void 0}):l.includes("password")||l.includes("secret")||l.includes("key")?(0,c.jsx)(sW.o,{placeholder:a.description,type:"password",defaultValue:n||""}):(0,c.jsx)(sW.o,{placeholder:a.description,type:"text",defaultValue:n||""})},i)})};return(0,c.jsx)(c.Fragment,{children:g(p)})};let{Title:i8}=en.default,i7=e=>{let{field:s,fieldKey:t,fullFieldKey:l,value:a}=e,[r,i]=d.useState([]),[n,o]=d.useState(s.dict_key_options||[]);d.useEffect(()=>{if(a&&"object"==typeof a){let e=Object.keys(a);i(e.map(e=>({key:e,id:"".concat(e,"_").concat(Date.now(),"_").concat(Math.random())}))),o((s.dict_key_options||[]).filter(s=>!e.includes(s)))}},[a,s.dict_key_options]);let m=e=>{e&&(i([...r,{key:e,id:"".concat(e,"_").concat(Date.now())}]),o(n.filter(s=>s!==e)))},u=(e,s)=>{i(r.filter(s=>s.id!==e)),o([...n,s].sort())};return(0,c.jsxs)("div",{className:"space-y-3",children:[r.map(e=>(0,c.jsxs)("div",{className:"flex items-center space-x-3 p-3 border rounded-lg",children:[(0,c.jsx)("div",{className:"w-24 font-medium text-sm",children:e.key}),(0,c.jsx)("div",{className:"flex-1",children:(0,c.jsx)(A.Z.Item,{name:Array.isArray(l)?[...l,e.key]:[l,e.key],style:{marginBottom:0},initialValue:a&&"object"==typeof a?a[e.key]:void 0,normalize:"number"===s.dict_value_type?e=>{if(null==e||""===e)return;let s=Number(e);return isNaN(s)?e:s}:void 0,children:"number"===s.dict_value_type?(0,c.jsx)(O,{step:1,width:200,placeholder:"Enter ".concat(e.key," value")}):"boolean"===s.dict_value_type?(0,c.jsxs)(I.default,{placeholder:"Select ".concat(e.key," value"),children:[(0,c.jsx)(I.default.Option,{value:!0,children:"True"}),(0,c.jsx)(I.default.Option,{value:!1,children:"False"})]}):(0,c.jsx)(sW.o,{placeholder:"Enter ".concat(e.key," value"),type:"text"})})}),(0,c.jsx)("button",{type:"button",className:"text-red-500 hover:text-red-700 text-sm",onClick:()=>u(e.id,e.key),children:"Remove"})]},e.id)),n.length>0&&(0,c.jsxs)("div",{className:"flex items-center space-x-3 mt-2",children:[(0,c.jsx)(I.default,{placeholder:"Select category to configure",style:{width:200},onSelect:e=>e&&m(e),value:void 0,children:n.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:"Select a category to add threshold configuration"})]})]})};var i9=e=>{let{optionalParams:s,parentFieldKey:t,values:l}=e,a=(e,s)=>{let a="".concat(t,".").concat(e),r=null==l?void 0:l[e];return(console.log("value",r),"dict"===s.type&&s.dict_key_options)?(0,c.jsxs)("div",{className:"mb-8 p-6 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"mb-4 font-medium text-gray-900 text-base",children:e}),(0,c.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:s.description}),(0,c.jsx)(i7,{field:s,fieldKey:e,fullFieldKey:[t,e],value:r})]},a):(0,c.jsx)("div",{className:"mb-8 p-6 bg-white rounded-lg border border-gray-200 shadow-sm",children:(0,c.jsx)(A.Z.Item,{name:[t,e],label:(0,c.jsxs)("div",{className:"mb-2",children:[(0,c.jsx)("div",{className:"font-medium text-gray-900 text-base",children:e}),(0,c.jsx)("p",{className:"text-sm text-gray-600 mt-1",children:s.description})]}),rules:s.required?[{required:!0,message:"".concat(e," is required")}]:void 0,className:"mb-0",initialValue:void 0!==r?r:s.default_value,normalize:"number"===s.type?e=>{if(null==e||""===e)return;let s=Number(e);return isNaN(s)?e:s}:void 0,children:"select"===s.type&&s.options?(0,c.jsx)(I.default,{placeholder:s.description,children:s.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"multiselect"===s.type&&s.options?(0,c.jsx)(I.default,{mode:"multiple",placeholder:s.description,children:s.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"bool"===s.type||"boolean"===s.type?(0,c.jsxs)(I.default,{placeholder:s.description,children:[(0,c.jsx)(I.default.Option,{value:"true",children:"True"}),(0,c.jsx)(I.default.Option,{value:"false",children:"False"})]}):"number"===s.type?(0,c.jsx)(O,{step:1,width:400,placeholder:s.description}):e.includes("password")||e.includes("secret")||e.includes("key")?(0,c.jsx)(sW.o,{placeholder:s.description,type:"password"}):(0,c.jsx)(sW.o,{placeholder:s.description,type:"text"})})},a)};return s.fields&&0!==Object.keys(s.fields).length?(0,c.jsxs)("div",{className:"guardrail-optional-params",children:[(0,c.jsxs)("div",{className:"mb-8 pb-4 border-b border-gray-100",children:[(0,c.jsx)(i8,{level:3,className:"mb-2 font-semibold text-gray-900",children:"Optional Parameters"}),(0,c.jsx)("p",{className:"text-gray-600 text-sm",children:s.description||"Configure additional settings for this guardrail provider"})]}),(0,c.jsx)("div",{className:"space-y-8",children:Object.entries(s.fields).map(e=>{let[s,t]=e;return a(s,t)})})]}):null};let{Title:ne,Text:ns,Link:nt}=en.default,{Option:nl}=I.default,{Step:na}=iO.default,nr={pre_call:"Before LLM Call - Runs before the LLM call and checks the input (Recommended)",during_call:"During LLM Call - Runs in parallel with the LLM call, with response held until check completes",post_call:"After LLM Call - Runs after the LLM call and checks only the output",logging_only:"Logging Only - Only runs on logging callbacks without affecting the LLM call",pre_mcp_call:"Before MCP Tool Call - Runs before MCP tool execution and validates tool calls",during_mcp_call:"During MCP Tool Call - Runs in parallel with MCP tool execution for monitoring"};var ni=e=>{let{visible:s,onClose:t,accessToken:l,onSuccess:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(null),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)({}),[v,y]=(0,d.useState)(0),[N,Z]=(0,d.useState)(null),[w,k]=(0,d.useState)([]),[S,C]=(0,d.useState)(2),[T,P]=(0,d.useState)({});(0,d.useEffect)(()=>{l&&(async()=>{try{let[e,s]=await Promise.all([(0,j.getGuardrailUISettings)(l),(0,j.getGuardrailProviderSpecificParams)(l)]);x(e),Z(s),iF(s),iU(s)}catch(e){console.error("Error fetching guardrail data:",e),eo.Z.fromBackend("Failed to load guardrail configuration")}})()},[l]);let E=e=>{m(e),r.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),p([]),f({}),k([]),C(2),P({})},M=e=>{p(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},O=(e,s)=>{f(t=>({...t,[e]:s}))},D=async()=>{try{if(0===v&&(await r.validateFields(["guardrail_name","provider","mode","default_on"]),o)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===o&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await r.validateFields(e)}if(1===v&&iq(o)&&0===h.length){eo.Z.fromBackend("Please select at least one PII entity to continue");return}y(v+1)}catch(e){console.error("Form validation failed:",e)}},F=()=>{r.resetFields(),m(null),p([]),f({}),k([]),C(2),P({}),y(0)},R=()=>{F(),t()},z=async()=>{try{n(!0),await r.validateFields();let s=r.getFieldsValue(!0),i=iz[s.provider],c={guardrail_name:s.guardrail_name,litellm_params:{guardrail:i,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&h.length>0){let e={};h.forEach(s=>{e[s]=g[s]||"MASK"}),c.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(c.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(c.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);c.guardrail_info=e}catch(e){eo.Z.fromBackend("Invalid JSON in configuration"),n(!1);return}if(console.log("values: ",JSON.stringify(s)),N&&o){var e;let t=null===(e=iz[o])||void 0===e?void 0:e.toLowerCase();console.log("providerKey: ",t);let l=N[t]||{},a=new Set;console.log("providerSpecificParams: ",JSON.stringify(l)),Object.keys(l).forEach(e=>{"optional_params"!==e&&a.add(e)}),l.optional_params&&l.optional_params.fields&&Object.keys(l.optional_params.fields).forEach(e=>{a.add(e)}),console.log("allowedParams: ",a),a.forEach(e=>{let t=s[e];if(null==t||""===t){var l;t=null===(l=s.optional_params)||void 0===l?void 0:l[e]}null!=t&&""!==t&&(c.litellm_params[e]=t)})}if(!l)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(c)),await (0,j.createGuardrailCall)(l,c),eo.Z.success("Guardrail created successfully"),F(),a(),t()}catch(e){console.error("Failed to create guardrail:",e),eo.Z.fromBackend("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{n(!1)}},U=()=>{var e;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter a name for this guardrail"})}),(0,c.jsx)(A.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{placeholder:"Select a guardrail provider",onChange:E,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(iR()).map(e=>{let[s,t]=e;return(0,c.jsx)(nl,{value:s,label:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]}),children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(A.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,c.jsx)(I.default,{optionLabelProp:"label",mode:"multiple",children:(null==u?void 0:null===(e=u.supported_modes)||void 0===e?void 0:e.map(e=>(0,c.jsx)(nl,{value:e,label:e,children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:e}),"pre_call"===e&&(0,c.jsx)(t1.Z,{color:"green",style:{marginLeft:"8px"},children:"Recommended"})]}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr[e]})]})},e)))||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(nl,{value:"pre_call",label:"pre_call",children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"pre_call"})," ",(0,c.jsx)(t1.Z,{color:"green",children:"Recommended"})]}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.pre_call})]})}),(0,c.jsx)(nl,{value:"during_call",label:"during_call",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"during_call"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.during_call})]})}),(0,c.jsx)(nl,{value:"post_call",label:"post_call",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"post_call"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.post_call})]})}),(0,c.jsx)(nl,{value:"logging_only",label:"logging_only",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"logging_only"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.logging_only})]})})]})})}),(0,c.jsx)(A.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default.",children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:!0,children:"Yes"}),(0,c.jsx)(I.default.Option,{value:!1,children:"No"})]})}),(0,c.jsx)(i3,{selectedProvider:o,accessToken:l,providerParams:N})]})},q=()=>u&&"PresidioPII"===o?(0,c.jsx)(i6,{entities:u.supported_entities,actions:u.supported_actions,selectedEntities:h,selectedActions:g,onEntitySelect:M,onActionSelect:O,entityCategories:u.pii_entity_categories}):null,B=()=>{var e;if(!o||!N)return null;console.log("guardrail_provider_map: ",iz),console.log("selectedProvider: ",o);let s=null===(e=iz[o])||void 0===e?void 0:e.toLowerCase(),t=N&&N[s];return t&&t.optional_params?(0,c.jsx)(i9,{optionalParams:t.optional_params,parentFieldKey:"optional_params"}):null};return(0,c.jsx)(L.Z,{title:"Add Guardrail",open:s,onCancel:R,footer:null,width:700,children:(0,c.jsxs)(A.Z,{form:r,layout:"vertical",initialValues:{mode:"pre_call",default_on:!1},children:[(0,c.jsxs)(iO.default,{current:v,className:"mb-6",children:[(0,c.jsx)(na,{title:"Basic Info"}),(0,c.jsx)(na,{title:iq(o)?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(v){case 0:return U();case 1:if(iq(o))return q();return B();default:return null}})(),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[v>0&&(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{y(v-1)},children:"Previous"}),v<2&&(0,c.jsx)(b.Z,{onClick:D,children:"Next"}),2===v&&(0,c.jsx)(b.Z,{onClick:z,loading:i,children:"Create Guardrail"}),(0,c.jsx)(b.Z,{variant:"secondary",onClick:R,children:"Cancel"})]})]})})};let{Title:nn,Text:no}=en.default,{Option:nc}=I.default;var nd=e=>{var s;let{visible:t,onClose:l,accessToken:a,onSuccess:r,guardrailId:i,initialValues:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)((null==n?void 0:n.provider)||null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)([]),[y,N]=(0,d.useState)({});(0,d.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,j.getGuardrailUISettings)(a);g(e)}catch(e){console.error("Error fetching guardrail settings:",e),eo.Z.fromBackend("Failed to load guardrail settings")}})()},[a]),(0,d.useEffect)(()=>{(null==n?void 0:n.pii_entities_config)&&Object.keys(n.pii_entities_config).length>0&&(v(Object.keys(n.pii_entities_config)),N(n.pii_entities_config))},[n]);let Z=e=>{v(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},w=(e,s)=>{N(t=>({...t,[e]:s}))},k=async()=>{try{u(!0);let e=await o.validateFields(),s=iz[e.provider],t={guardrail_id:i,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=y[s]||"MASK"}),t.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(t.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(t.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):t.guardrail.guardrail_info=s}catch(e){eo.Z.fromBackend("Invalid JSON in configuration"),u(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(t));let n=await fetch("/guardrails/".concat(i),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let e=await n.text();throw Error(e||"Failed to update guardrail")}eo.Z.success("Guardrail updated successfully"),r(),l()}catch(e){console.error("Failed to update guardrail:",e),eo.Z.fromBackend("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{u(!1)}},S=()=>p&&x&&"PresidioPII"===x?(0,c.jsx)(i6,{entities:p.supported_entities,actions:p.supported_actions,selectedEntities:f,selectedActions:y,onEntitySelect:Z,onActionSelect:w,entityCategories:p.pii_entity_categories}):null;return(0,c.jsx)(L.Z,{title:"Edit Guardrail",open:t,onCancel:l,footer:null,width:700,children:(0,c.jsxs)(A.Z,{form:o,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter a name for this guardrail"})}),(0,c.jsx)(A.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{placeholder:"Select a guardrail provider",onChange:e=>{h(e),o.setFieldsValue({config:void 0}),v([]),N({})},disabled:!0,optionLabelProp:"label",children:Object.entries(iR()).map(e=>{let[s,t]=e;return(0,c.jsx)(nc,{value:s,label:t,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(A.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,c.jsx)(I.default,{children:(null==p?void 0:null===(s=p.supported_modes)||void 0===s?void 0:s.map(e=>(0,c.jsx)(nc,{value:e,children:e},e)))||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(nc,{value:"pre_call",children:"pre_call"}),(0,c.jsx)(nc,{value:"post_call",children:"post_call"})]})})}),(0,c.jsx)(A.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,c.jsx)(tj.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return S();switch(x){case"Aporia":return(0,c.jsx)(A.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,c.jsx)(A.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,c.jsx)(A.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,c.jsx)(A.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,c.jsx)(A.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,c.jsx)(A.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,c.jsx)(A.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:k,loading:m,children:"Update Guardrail"})]})]})})},nm=e=>{let{guardrailsList:s,isLoading:t,onDeleteClick:l,accessToken:a,onGuardrailUpdated:r,isAdmin:i=!1,onGuardrailClick:n}=e,[o,m]=(0,d.useState)([{id:"created_at",desc:!0}]),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),g=e=>e?new Date(e).toLocaleString():"-",j=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.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:()=>e.getValue()&&n(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.guardrail_name,children:(0,c.jsx)("span",{className:"text-xs font-medium",children:t.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:t,displayName:l}=iK(s.original.litellm_params.guardrail);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,c.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.litellm_params.mode})}},{header:"Default On",accessorKey:"litellm_params.default_on",cell:e=>{var s,t;let{row:l}=e,a=l.original;return(0,c.jsx)(eX.Z,{color:(null===(s=a.litellm_params)||void 0===s?void 0:s.default_on)?"green":"gray",className:"text-xs font-normal",size:"xs",children:(null===(t=a.litellm_params)||void 0===t?void 0:t.default_on)?"Default On":"Default Off"})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.created_at,children:(0,c.jsx)("span",{className:"text-xs",children:g(t.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.updated_at,children:(0,c.jsx)("span",{className:"text-xs",children:g(t.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"flex space-x-2",children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>t.guardrail_id&&l(t.guardrail_id,t.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],f=(0,s_.b7)({data:s,columns:j,state:{sorting:o},onSortingChange:m,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:f.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:t?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:j.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"Loading..."})})})}):s.length>0?f.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:j.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No guardrails found"})})})})})]})}),h&&(0,c.jsx)(nd,{visible:u,onClose:()=>x(!1),accessToken:a,onSuccess:()=>{x(!1),p(null),r()},guardrailId:h.guardrail_id||"",initialValues:{guardrail_name:h.guardrail_name||"",provider:Object.keys(iz).find(e=>iz[e]===(null==h?void 0:h.litellm_params.guardrail))||"",mode:h.litellm_params.mode,default_on:h.litellm_params.default_on,pii_entities_config:h.litellm_params.pii_entities_config,...h.guardrail_info}})]})},nu=e=>{var s,t,l,a,r,i,n,o,m,u,x;let{guardrailId:h,onClose:p,accessToken:g,isAdmin:f}=e,[v,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(null),[C,L]=(0,d.useState)(!0),[T,M]=(0,d.useState)(!1),[O]=A.Z.useForm(),[D,F]=(0,d.useState)([]),[R,z]=(0,d.useState)({}),[U,q]=(0,d.useState)(null),[B,V]=(0,d.useState)({}),H=async()=>{try{var e;if(L(!0),!g)return;let s=await (0,j.getGuardrailInfo)(g,h);if(N(s),null===(e=s.litellm_params)||void 0===e?void 0:e.pii_entities_config){let e=s.litellm_params.pii_entities_config;if(F([]),z({}),Object.keys(e).length>0){let s=[],t={};Object.entries(e).forEach(e=>{let[l,a]=e;s.push(l),t[l]="string"==typeof a?a:"MASK"}),F(s),z(t)}}else F([]),z({})}catch(e){eo.Z.fromBackend("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{L(!1)}},J=async()=>{try{if(!g)return;let e=await (0,j.getGuardrailProviderSpecificParams)(g);w(e)}catch(e){console.error("Error fetching guardrail provider specific params:",e)}},Y=async()=>{try{if(!g)return;let e=await (0,j.getGuardrailUISettings)(g);q(e)}catch(e){console.error("Error fetching guardrail UI settings:",e)}};(0,d.useEffect)(()=>{J()},[g]),(0,d.useEffect)(()=>{H(),Y()},[h,g]),(0,d.useEffect)(()=>{if(v&&O){var e;O.setFieldsValue({guardrail_name:v.guardrail_name,...v.litellm_params,guardrail_info:v.guardrail_info?JSON.stringify(v.guardrail_info,null,2):"",...(null===(e=v.litellm_params)||void 0===e?void 0:e.optional_params)&&{optional_params:v.litellm_params.optional_params}})}},[v,Z,O]);let W=async e=>{try{var s,t,l;if(!g)return;let a={litellm_params:{}};e.guardrail_name!==v.guardrail_name&&(a.guardrail_name=e.guardrail_name),e.default_on!==(null===(s=v.litellm_params)||void 0===s?void 0:s.default_on)&&(a.litellm_params.default_on=e.default_on);let r=v.guardrail_info,i=e.guardrail_info?JSON.parse(e.guardrail_info):void 0;JSON.stringify(r)!==JSON.stringify(i)&&(a.guardrail_info=i);let n=(null===(t=v.litellm_params)||void 0===t?void 0:t.pii_entities_config)||{},o={};D.forEach(e=>{o[e]=R[e]||"MASK"}),JSON.stringify(n)!==JSON.stringify(o)&&(a.litellm_params.pii_entities_config=o);let c=Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)});if(console.log("values: ",JSON.stringify(e)),console.log("currentProvider: ",c),Z&&c){let s=Z[null===(l=iz[c])||void 0===l?void 0:l.toLowerCase()]||{},t=new Set;console.log("providerSpecificParams: ",JSON.stringify(s)),Object.keys(s).forEach(e=>{"optional_params"!==e&&t.add(e)}),s.optional_params&&s.optional_params.fields&&Object.keys(s.optional_params.fields).forEach(e=>{t.add(e)}),console.log("allowedParams: ",t),t.forEach(s=>{var t,l;let r=e[s];(null==r||""===r)&&(r=null===(l=e.optional_params)||void 0===l?void 0:l[s]);let i=null===(t=v.litellm_params)||void 0===t?void 0:t[s];JSON.stringify(r)!==JSON.stringify(i)&&(null!=r&&""!==r?a.litellm_params[s]=r:null!=i&&""!==i&&(a.litellm_params[s]=null))})}if(0===Object.keys(a.litellm_params).length&&delete a.litellm_params,0===Object.keys(a).length){eo.Z.info("No changes detected"),M(!1);return}await (0,j.updateGuardrailCall)(g,h,a),eo.Z.success("Guardrail updated successfully"),H(),M(!1)}catch(e){console.error("Error updating guardrail:",e),eo.Z.fromBackend("Failed to update guardrail")}};if(C)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!v)return(0,c.jsx)("div",{className:"p-4",children:"Guardrail not found"});let $=e=>e?new Date(e).toLocaleString():"-",{logo:Q,displayName:X}=iK((null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)||""),ee=async(e,s)=>{await eM(e)&&(V(e=>({...e,[s]:!0})),setTimeout(()=>{V(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:p,className:"mb-4",children:"Back to Guardrails"}),(0,c.jsx)(S.Z,{children:v.guardrail_name||"Unnamed Guardrail"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:v.guardrail_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:B["guardrail-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>ee(v.guardrail_id,"guardrail-id"),className:"left-2 z-10 transition-all duration-200 ".concat(B["guardrail-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),f?(0,c.jsx)(e0.Z,{children:"Settings"},"settings"):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Provider"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[Q&&(0,c.jsx)("img",{src:Q,alt:"".concat(X," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)(S.Z,{children:X})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Mode"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:(null===(t=v.litellm_params)||void 0===t?void 0:t.mode)||"-"}),(0,c.jsx)(eX.Z,{color:(null===(l=v.litellm_params)||void 0===l?void 0:l.default_on)?"green":"gray",children:(null===(a=v.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Created At"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:$(v.created_at)}),(0,c.jsxs)(k.Z,{children:["Last Updated: ",$(v.updated_at)]})]})]})]}),(null===(r=v.litellm_params)||void 0===r?void 0:r.pii_entities_config)&&Object.keys(v.litellm_params.pii_entities_config).length>0&&(0,c.jsx)(G.Z,{className:"mt-6",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"PII Protection"}),(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(v.litellm_params.pii_entities_config).length," PII entities configured"]})]})}),v.guardrail_info&&Object.keys(v.guardrail_info).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsx)(k.Z,{children:"Guardrail Info"}),(0,c.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(v.guardrail_info).map(e=>{let[s,t]=e;return(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(k.Z,{className:"font-medium w-1/3",children:s}),(0,c.jsx)(k.Z,{className:"w-2/3",children:"object"==typeof t?JSON.stringify(t,null,2):String(t)})]},s)})})]})]}),f&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Guardrail Settings"}),!T&&(0,c.jsx)(b.Z,{onClick:()=>M(!0),children:"Edit Settings"})]}),T?(0,c.jsxs)(A.Z,{form:O,onFinish:W,initialValues:{guardrail_name:v.guardrail_name,...v.litellm_params,guardrail_info:v.guardrail_info?JSON.stringify(v.guardrail_info,null,2):"",...(null===(i=v.litellm_params)||void 0===i?void 0:i.optional_params)&&{optional_params:v.litellm_params.optional_params}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Default On",name:"default_on",children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:!0,children:"Yes"}),(0,c.jsx)(I.default.Option,{value:!1,children:"No"})]})}),(null===(n=v.litellm_params)||void 0===n?void 0:n.guardrail)==="presidio"&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(K.Z,{orientation:"left",children:"PII Protection"}),(0,c.jsx)("div",{className:"mb-6",children:U&&(0,c.jsx)(i6,{entities:U.supported_entities,actions:U.supported_actions,selectedEntities:D,selectedActions:R,onEntitySelect:e=>{F(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},onActionSelect:(e,s)=>{z(t=>({...t,[e]:s}))},entityCategories:U.pii_entity_categories})})]}),(0,c.jsx)(K.Z,{orientation:"left",children:"Provider Settings"}),(0,c.jsx)(i3,{selectedProvider:Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)})||null,accessToken:g,providerParams:Z,value:v.litellm_params}),Z&&(()=>{var e;let s=Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)});if(!s)return null;let t=Z[null===(e=iz[s])||void 0===e?void 0:e.toLowerCase()];return t&&t.optional_params?(0,c.jsx)(i9,{optionalParams:t.optional_params,parentFieldKey:"optional_params",values:v.litellm_params}):null})(),(0,c.jsx)(K.Z,{orientation:"left",children:"Advanced Settings"}),(0,c.jsx)(A.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,c.jsx)(E.default.TextArea,{rows:5})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,c.jsx)(P.ZP,{onClick:()=>M(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{children:"Save Changes"})]})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Guardrail ID"}),(0,c.jsx)("div",{className:"font-mono",children:v.guardrail_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Guardrail Name"}),(0,c.jsx)("div",{children:v.guardrail_name||"Unnamed Guardrail"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Provider"}),(0,c.jsx)("div",{children:X})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Mode"}),(0,c.jsx)("div",{children:(null===(o=v.litellm_params)||void 0===o?void 0:o.mode)||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Default On"}),(0,c.jsx)(eX.Z,{color:(null===(m=v.litellm_params)||void 0===m?void 0:m.default_on)?"green":"gray",children:(null===(u=v.litellm_params)||void 0===u?void 0:u.default_on)?"Yes":"No"})]}),(null===(x=v.litellm_params)||void 0===x?void 0:x.pii_entities_config)&&Object.keys(v.litellm_params.pii_entities_config).length>0&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"PII Protection"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(v.litellm_params.pii_entities_config).length," PII entities configured"]})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:$(v.created_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)("div",{children:$(v.updated_at)})]})]})]})})]})]})]})},nx=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)([]),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),f=!!t&&(0,eI.tY)(t),v=async()=>{if(s){o(!0);try{let e=await (0,j.getGuardrailsList)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,d.useEffect)(()=>{v()},[s]);let y=async()=>{if(x&&s){u(!0);try{await (0,j.deleteGuardrailCall)(s,x.id),eo.Z.success('Guardrail "'.concat(x.name,'" deleted successfully')),v()}catch(e){console.error("Error deleting guardrail:",e),eo.Z.fromBackend("Failed to delete guardrail")}finally{u(!1),h(null)}}};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(b.Z,{onClick:()=>{p&&g(null),i(!0)},disabled:!s,children:"+ Add New Guardrail"})}),p?(0,c.jsx)(nu,{guardrailId:p,onClose:()=>g(null),accessToken:s,isAdmin:f}):(0,c.jsx)(nm,{guardrailsList:l,isLoading:n,onDeleteClick:(e,s)=>{h({id:e,name:s})},accessToken:s,onGuardrailUpdated:v,isAdmin:f,onGuardrailClick:e=>g(e)}),(0,c.jsx)(ni,{visible:r,onClose:()=>{i(!1)},accessToken:s,onSuccess:()=>{v()}}),x&&(0,c.jsxs)(L.Z,{title:"Delete Guardrail",open:null!==x,onOk:y,onCancel:()=>{h(null)},confirmLoading:m,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",x.name," ?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})},nh=e=>{let{promptsList:s,isLoading:t,onPromptClick:l,onDeleteClick:a,accessToken:r,isAdmin:i}=e,[n,o]=(0,d.useState)([{id:"created_at",desc:!0}]),m=e=>e?new Date(e).toLocaleString():"-",u=[{header:"Prompt ID",accessorKey:"prompt_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.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:()=>e.getValue()&&(null==l?void 0:l(e.getValue())),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.created_at,children:(0,c.jsx)("span",{className:"text-xs",children:m(t.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.updated_at,children:(0,c.jsx)("span",{className:"text-xs",children:m(t.updated_at)})})}},{header:"Type",accessorKey:"prompt_info.prompt_type",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.prompt_info.prompt_type,children:(0,c.jsx)("span",{className:"text-xs",children:t.prompt_info.prompt_type})})}},...i?[{header:"Actions",id:"actions",enableSorting:!1,cell:e=>{let{row:s}=e,t=s.original,l=t.prompt_id||"Unknown Prompt";return(0,c.jsx)("div",{className:"flex items-center gap-1",children:(0,c.jsx)(V.Z,{title:"Delete prompt",children:(0,c.jsx)(b.Z,{size:"xs",variant:"light",color:"red",onClick:e=>{e.stopPropagation(),null==a||a(t.prompt_id,l)},icon:W.Z,className:"text-red-500 hover:text-red-700 hover:bg-red-50"})})})}}]:[]],x=(0,s_.b7)({data:s,columns:u,state:{sorting:n},onSortingChange:o,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:x.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.Z,{className:"py-1 h-8",onClick:e.column.getToggleSortingHandler(),children:(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:t?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:u.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"Loading..."})})})}):s.length>0?x.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:u.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No prompts found"})})})})})]})})})},np=e=>{var s,t,l;let{promptId:a,onClose:r,accessToken:i,isAdmin:n,onDelete:o}=e,[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!0),[_,N]=(0,d.useState)({}),[Z,w]=(0,d.useState)(!1),[C,I]=(0,d.useState)(!1),A=async()=>{try{if(v(!0),!i)return;let e=await (0,j.getPromptInfo)(i,a);u(e.prompt_spec),h(e.raw_prompt_template),g(e)}catch(e){eo.Z.fromBackend("Failed to load prompt information"),console.error("Error fetching prompt info:",e)}finally{v(!1)}};if((0,d.useEffect)(()=>{A()},[a,i]),f)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!m)return(0,c.jsx)("div",{className:"p-4",children:"Prompt not found"});let T=e=>e?new Date(e).toLocaleString():"-",E=async(e,s)=>{await eM(e)&&(N(e=>({...e,[s]:!0})),setTimeout(()=>{N(e=>({...e,[s]:!1}))},2e3))},M=async()=>{if(i&&m){I(!0);try{await (0,j.deletePromptCall)(i,m.prompt_id),eo.Z.success('Prompt "'.concat(m.prompt_id,'" deleted successfully')),null==o||o(),r()}catch(e){console.error("Error deleting prompt:",e),eo.Z.fromBackend("Failed to delete prompt")}finally{I(!1),w(!1)}}};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:r,className:"mb-4",children:"Back to Prompts"}),(0,c.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Prompt Details"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:m.prompt_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["prompt-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>E(m.prompt_id,"prompt-id"),className:"left-2 z-10 transition-all duration-200 ".concat(_["prompt-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),n&&(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>{w(!0)},className:"flex items-center",children:"Delete Prompt"})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),x?(0,c.jsx)(e0.Z,{children:"Prompt Template"},"prompt-template"):(0,c.jsx)(c.Fragment,{}),n?(0,c.jsx)(e0.Z,{children:"Details"},"details"):(0,c.jsx)(c.Fragment,{}),(0,c.jsx)(e0.Z,{children:"Raw JSON"},"raw-json")]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Prompt ID"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{className:"font-mono text-sm",children:m.prompt_id})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Prompt Type"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:(null===(s=m.prompt_info)||void 0===s?void 0:s.prompt_type)||"-"}),(0,c.jsx)(eX.Z,{color:"blue",className:"mt-1",children:(null===(t=m.prompt_info)||void 0===t?void 0:t.prompt_type)||"Unknown"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Created At"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:T(m.created_at)}),(0,c.jsxs)(k.Z,{children:["Last Updated: ",T(m.updated_at)]})]})]})]}),m.litellm_params&&Object.keys(m.litellm_params).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Parameters"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(m.litellm_params,null,2)})})]})]}),x&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Prompt Template"}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["prompt-content"]?(0,c.jsx)(sm.Z,{size:16}):(0,c.jsx)(su.Z,{size:16}),onClick:()=>E(x.content,"prompt-content"),className:"transition-all duration-200 ".concat(_["prompt-content"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:_["prompt-content"]?"Copied!":"Copy Content"})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Template ID"}),(0,c.jsx)("div",{className:"font-mono text-sm bg-gray-50 p-2 rounded",children:x.litellm_prompt_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Content"}),(0,c.jsx)("div",{className:"mt-2 p-4 bg-gray-50 rounded-md border overflow-auto max-h-96",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:x.content})})]}),x.metadata&&Object.keys(x.metadata).length>0&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Template Metadata"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap overflow-auto max-h-64",children:JSON.stringify(x.metadata,null,2)})})]})]})]})}),n&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Prompt Details"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt ID"}),(0,c.jsx)("div",{className:"font-mono text-sm bg-gray-50 p-2 rounded",children:m.prompt_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt Type"}),(0,c.jsx)("div",{children:(null===(l=m.prompt_info)||void 0===l?void 0:l.prompt_type)||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:T(m.created_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)("div",{children:T(m.updated_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Parameters"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap overflow-auto max-h-96",children:JSON.stringify(m.litellm_params,null,2)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt Info"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(m.prompt_info,null,2)})})]})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Raw API Response"}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["raw-json"]?(0,c.jsx)(sm.Z,{size:16}):(0,c.jsx)(su.Z,{size:16}),onClick:()=>E(JSON.stringify(p,null,2),"raw-json"),className:"transition-all duration-200 ".concat(_["raw-json"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:_["raw-json"]?"Copied!":"Copy JSON"})]}),(0,c.jsx)("div",{className:"p-4 bg-gray-50 rounded-md border overflow-auto",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(p,null,2)})})]})})]})]}),(0,c.jsxs)(L.Z,{title:"Delete Prompt",open:Z,onOk:M,onCancel:()=>{w(!1)},confirmLoading:C,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete prompt: ",(0,c.jsx)("strong",{children:null==m?void 0:m.prompt_id}),"?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})};let{Option:ng}=I.default;var nj=e=>{let{visible:s,onClose:t,accessToken:l,onSuccess:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)("dotprompt"),h=()=>{r.resetFields(),m([]),x("dotprompt"),t()},p=async()=>{try{let e=await r.validateFields();if(console.log("values: ",e),!l){eo.Z.fromBackend("Access token is required");return}if("dotprompt"===u&&0===o.length){eo.Z.fromBackend("Please upload a .prompt file");return}n(!0);let s={};if("dotprompt"===u&&o.length>0){let t=o[0].originFileObj;try{let a=await (0,j.convertPromptFileToJson)(l,t);console.log("Conversion result:",a),s={prompt_id:e.prompt_id,litellm_params:{prompt_integration:"dotprompt",prompt_id:a.prompt_id,prompt_data:a.json_data},prompt_info:{prompt_type:"db"}}}catch(e){console.error("Error converting prompt file:",e),eo.Z.fromBackend("Failed to convert prompt file to JSON"),n(!1);return}}try{await (0,j.createPromptCall)(l,s),eo.Z.success("Prompt created successfully!"),h(),a()}catch(e){console.error("Error creating prompt:",e),eo.Z.fromBackend("Failed to create prompt")}}catch(e){console.error("Form validation error:",e)}finally{n(!1)}};return(0,c.jsx)(L.Z,{title:"Add New Prompt",open:s,onCancel:h,footer:[(0,c.jsx)(P.ZP,{onClick:h,children:"Cancel"},"cancel"),(0,c.jsx)(P.ZP,{loading:i,onClick:p,children:"Create Prompt"},"submit")],width:600,children:(0,c.jsxs)(A.Z,{form:r,layout:"vertical",requiredMark:!1,children:[(0,c.jsx)(A.Z.Item,{label:"Prompt ID",name:"prompt_id",rules:[{required:!0,message:"Please enter a prompt ID"},{pattern:/^[a-zA-Z0-9_-]+$/,message:"Prompt ID can only contain letters, numbers, underscores, and hyphens"}],children:(0,c.jsx)(sW.o,{placeholder:"Enter unique prompt ID (e.g., my_prompt_id)"})}),(0,c.jsx)(A.Z.Item,{label:"Prompt Integration",name:"prompt_integration",initialValue:"dotprompt",children:(0,c.jsx)(I.default,{value:u,onChange:x,children:(0,c.jsx)(ng,{value:"dotprompt",children:"dotprompt"})})}),"dotprompt"===u&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(K.Z,{}),(0,c.jsxs)(A.Z.Item,{label:"Prompt File",extra:"Upload a .prompt file that follows the Dotprompt specification",children:[(0,c.jsx)(ed.default,{beforeUpload:e=>(e.name.endsWith(".prompt")||eo.Z.fromBackend("Please upload a .prompt file"),!1),fileList:o,onChange:e=>{let{fileList:s}=e;m(s.slice(-1))},onRemove:()=>{m([])},children:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(ej.Z,{}),children:"Select .prompt File"})}),o.length>0&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-600",children:["Selected: ",o[0].name]})]})]})]})})},nf=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)([]),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)(null),f=!!t&&(0,eI.tY)(t),v=async()=>{if(s){i(!0);try{let e=await (0,j.getPromptsList)(s);console.log("prompts: ".concat(JSON.stringify(e))),a(e.prompts)}catch(e){console.error("Error fetching prompts:",e)}finally{i(!1)}}};(0,d.useEffect)(()=>{v()},[s]);let y=async()=>{if(p&&s){h(!0);try{await (0,j.deletePromptCall)(s,p.id),eo.Z.success('Prompt "'.concat(p.name,'" deleted successfully')),v()}catch(e){console.error("Error deleting prompt:",e),eo.Z.fromBackend("Failed to delete prompt")}finally{h(!1),g(null)}}};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[n?(0,c.jsx)(np,{promptId:n,onClose:()=>o(null),accessToken:s,isAdmin:f,onDelete:v}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(b.Z,{onClick:()=>{n&&o(null),u(!0)},disabled:!s,children:"+ Add New Prompt"})}),(0,c.jsx)(nh,{promptsList:l,isLoading:r,onPromptClick:e=>{o(e)},onDeleteClick:(e,s)=>{g({id:e,name:s})},accessToken:s,isAdmin:f})]}),(0,c.jsx)(nj,{visible:m,onClose:()=>{u(!1)},accessToken:s,onSuccess:()=>{v()}}),p&&(0,c.jsxs)(L.Z,{title:"Delete Prompt",open:null!==p,onOk:y,onCancel:()=>{g(null)},confirmLoading:x,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete prompt: ",p.name," ?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})},nv=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,d.useState)(""),[i,n]=(0,d.useState)(!1),o=(e,s,t)=>{let l=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(t).map(e=>{let[s,t]=e;return"-H '".concat(s,": ").concat(t,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(l,"\n }'")},m=async()=>{n(!0);try{let e;try{e=JSON.parse(t)}catch(e){eo.Z.fromBackend("Invalid JSON in request body"),n(!1);return}let l={call_type:"completion",request_body:e};if(!s){eo.Z.fromBackend("No access token found"),n(!1);return}let a=await (0,j.transformRequestCall)(s,l);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),eo.Z.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),eo.Z.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),eo.Z.fromBackend("Failed to transform request")}finally{n(!1)}};return(0,c.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,c.jsx)(S.Z,{children:"Playground"}),(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,c.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,c.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,c.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,c.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,c.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,c.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:t,onChange:e=>l(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),m())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,c.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,c.jsxs)(P.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:m,loading:i,children:[(0,c.jsx)("span",{children:"Transform"}),(0,c.jsx)("span",{children:"→"})]})})]}),(0,c.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,c.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,c.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,c.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,c.jsx)("br",{}),(0,c.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,c.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,c.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,c.jsx)(P.ZP,{type:"text",icon:(0,c.jsx)(tR.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),eo.Z.success("Copied to clipboard")}})]})]})]}),(0,c.jsx)("div",{className:"mt-4 text-right w-full",children:(0,c.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,c.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})};let ny=e=>{try{let s=e.indexOf("/mcp/");if(-1===s)return{token:null,baseUrl:e};let t=e.split("/mcp/");if(2!==t.length)return{token:null,baseUrl:e};let l=t[0]+"/mcp/",a=t[1];if(!a)return{token:null,baseUrl:e};return{token:a,baseUrl:l}}catch(s){return console.error("Error parsing MCP URL:",s),{token:null,baseUrl:e}}},nb=e=>{let{token:s,baseUrl:t}=ny(e);return s?t+"...":e},n_=e=>{let{token:s}=ny(e);return{maskedUrl:nb(e),hasToken:!!s}},nN=e=>e?/^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(e)?Promise.resolve():Promise.reject("Please enter a valid URL (e.g., http://service-name.domain:1234/path or https://example.com)"):Promise.resolve(),nZ=e=>e&&e.includes("-")?Promise.reject("Server name cannot contain '-' (hyphen). Please use '_' (underscore) instead."):Promise.resolve(),nw=(e,s,t,l)=>[{accessorKey:"server_id",header:"Server ID",cell:e=>{let{row:t}=e;return(0,c.jsxs)("button",{onClick:()=>s(t.original.server_id),className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",children:[t.original.server_id.slice(0,7),"..."]})}},{accessorKey:"server_name",header:"Name"},{accessorKey:"alias",header:"Alias"},{id:"url",header:"URL",cell:e=>{let{row:s}=e,{maskedUrl:t}=n_(s.original.url);return(0,c.jsx)("span",{className:"font-mono text-sm",children:t})}},{accessorKey:"transport",header:"Transport",cell:e=>{let{getValue:s}=e;return(0,c.jsx)("span",{children:(s()||"http").toUpperCase()})}},{accessorKey:"auth_type",header:"Auth Type",cell:e=>{let{getValue:s}=e;return(0,c.jsx)("span",{children:s()||"none"})}},{id:"mcp_access_groups",header:"Access Groups",cell:e=>{let{row:s}=e,t=s.original.mcp_access_groups;if(Array.isArray(t)&&t.length>0&&"string"==typeof t[0]){let e=t.join(", ");return(0,c.jsx)(V.Z,{title:e,children:(0,c.jsx)("span",{className:"max-w-[200px] truncate block",children:e.length>30?"".concat(e.slice(0,30),"..."):e})})}return(0,c.jsx)("span",{className:"text-gray-400 italic",children:"None"})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.created_at?new Date(t.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.updated_at?new Date(t.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>t(s.original.server_id),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(s.original.server_id),className:"cursor-pointer"})]})}}];var nk=t(82376),nS=t(71437);let nC={NONE:"none",API_KEY:"api_key",BEARER_TOKEN:"bearer_token",BASIC:"basic"},nI={SSE:"sse"},nA=e=>(console.log(e),null==e)?nI.SSE:e,nL=e=>null==e?nC.NONE:e,nT=e=>nL(e)!==nC.NONE;var nP=t(62670),nE=e=>{let{value:s={},onChange:t,tools:l=[],disabled:a=!1}=e,r=(e,l)=>{let a={...s,tool_name_to_cost_per_query:{...s.tool_name_to_cost_per_query,[e]:l}};null==t||t(a)};return(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,c.jsx)(nP.Z,{className:"text-green-600"}),(0,c.jsx)(S.Z,{children:"Cost Configuration"}),(0,c.jsx)(V.Z,{title:"Configure costs for this MCP server's tool calls. Set a default rate and per-tool overrides.",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Default Cost per Query ($)",(0,c.jsx)(V.Z,{title:"Default cost charged for each tool call to this server.",children:(0,c.jsx)(B.Z,{className:"ml-1 text-gray-400"})})]}),(0,c.jsx)(eW.Z,{min:0,step:1e-4,precision:4,placeholder:"0.0000",value:s.default_cost_per_query,onChange:e=>{let l={...s,default_cost_per_query:e};null==t||t(l)},disabled:a,style:{width:"200px"},addonBefore:"$"}),(0,c.jsx)(k.Z,{className:"block mt-1 text-gray-500 text-sm",children:"Set a default cost for all tool calls to this server"})]}),l.length>0&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("label",{className:"block text-sm font-medium text-gray-700",children:["Tool-Specific Costs ($)",(0,c.jsx)(V.Z,{title:"Override the default cost for specific tools. Leave blank to use the default rate.",children:(0,c.jsx)(B.Z,{className:"ml-1 text-gray-400"})})]}),(0,c.jsx)(t_.default,{items:[{key:"1",label:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2 text-blue-500"}),(0,c.jsx)("span",{className:"font-medium",children:"Available Tools"}),(0,c.jsx)(iG.Z,{count:l.length,style:{backgroundColor:"#52c41a",marginLeft:"8px"}})]}),children:(0,c.jsx)("div",{className:"space-y-3 max-h-64 overflow-y-auto",children:l.map((e,t)=>{var l;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-lg",children:[(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900",children:e.name}),e.description&&(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm block mt-1",children:e.description})]}),(0,c.jsx)("div",{className:"ml-4",children:(0,c.jsx)(eW.Z,{min:0,step:1e-4,precision:4,placeholder:"Use default",value:null===(l=s.tool_name_to_cost_per_query)||void 0===l?void 0:l[e.name],onChange:s=>r(e.name,s),disabled:a,style:{width:"120px"},addonBefore:"$"})})]},t)})})}]})]})]}),(s.default_cost_per_query||s.tool_name_to_cost_per_query&&Object.keys(s.tool_name_to_cost_per_query).length>0)&&(0,c.jsxs)("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"text-blue-800 font-medium",children:"Cost Summary:"}),(0,c.jsxs)("div",{className:"mt-2 space-y-1",children:[s.default_cost_per_query&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• Default cost: $",s.default_cost_per_query.toFixed(4)," per query"]}),s.tool_name_to_cost_per_query&&Object.entries(s.tool_name_to_cost_per_query).map(e=>{let[s,t]=e;return null!=t&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• ",s,": $",t.toFixed(4)," per query"]},s)})]})]})]})})},nM=e=>{let{mcpServer:s,accessToken:t,onCancel:l,onSuccess:a,availableAccessGroups:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)({}),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(!1);(0,d.useEffect)(()=>{var e;(null===(e=s.mcp_info)||void 0===e?void 0:e.mcp_server_cost_info)&&o(s.mcp_info.mcp_server_cost_info)},[s]),(0,d.useEffect)(()=>{if(s.mcp_access_groups){let e=s.mcp_access_groups.map(e=>"string"==typeof e?e:e.name||String(e));i.setFieldValue("mcp_access_groups",e)}},[s]),(0,d.useEffect)(()=>{y()},[s,t]);let y=async()=>{if(t&&s.url){h(!0);try{let e={server_id:s.server_id,server_name:s.server_name,url:s.url,transport:s.transport,auth_type:s.auth_type,mcp_info:s.mcp_info},l=await (0,j.testMCPToolsListRequest)(t,e);l.tools&&!l.error?u(l.tools):(console.error("Failed to fetch tools:",l.message),u([]))}catch(e){console.error("Tools fetch error:",e),u([])}finally{h(!1)}}},N=async e=>{if(t)try{let l=(e.mcp_access_groups||[]).map(e=>"string"==typeof e?e:e.name||String(e)),r={...e,server_id:s.server_id,mcp_info:{server_name:e.server_name||e.url,description:e.description,mcp_server_cost_info:Object.keys(n).length>0?n:null},mcp_access_groups:l,alias:e.alias},i=await (0,j.updateMCPServer)(t,r);eo.Z.success("MCP Server updated successfully"),a(i)}catch(e){eo.Z.fromBackend("Failed to update MCP Server"+((null==e?void 0:e.message)?": ".concat(e.message):""))}};return(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"grid w-full grid-cols-2",children:[(0,c.jsx)(e0.Z,{children:"Server Configuration"}),(0,c.jsx)(e0.Z,{children:"Cost Configuration"})]}),(0,c.jsxs)(e5.Z,{className:"mt-6",children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:N,initialValues:s,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"MCP Server Name",name:"server_name",rules:[{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Alias",name:"alias",rules:[{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{onChange:()=>v(!0)})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"MCP Server URL",name:"url",rules:[{required:!0,message:"Please enter a server URL"},{validator:(e,s)=>nN(s)}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Transport Type",name:"transport",rules:[{required:!0}],children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:"sse",children:"Server-Sent Events (SSE)"}),(0,c.jsx)(I.default.Option,{value:"http",children:"HTTP"})]})}),(0,c.jsx)(A.Z.Item,{label:"Authentication",name:"auth_type",rules:[{required:!0}],children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:"none",children:"None"}),(0,c.jsx)(I.default.Option,{value:"api_key",children:"API Key"}),(0,c.jsx)(I.default.Option,{value:"bearer_token",children:"Bearer Token"}),(0,c.jsx)(I.default.Option,{value:"basic",children:"Basic Auth"})]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Access Groups",(0,c.jsx)(V.Z,{title:"Define access groups for this MCP server. Each group represents a set of permissions.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"mcp_access_groups",getValueFromEvent:e=>e,children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},showSearch:!0,placeholder:"Add or select access groups",tokenSeparators:[","],optionFilterProp:"value",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.value)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},onSearch:e=>g(e),options:(()=>{let e=r.map(e=>({value:e,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})}));return p&&!r.some(e=>e.toLowerCase().includes(p.toLowerCase()))&&e.push({value:p,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:p}),(0,c.jsx)("span",{className:"text-gray-400 text-xs ml-1",children:"create new group"})]})}),e})(),getPopupContainer:e=>e.parentNode})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,c.jsx)(P.ZP,{onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsx)(nE,{value:n,onChange:o,tools:m,disabled:x}),(0,c.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,c.jsx)(P.ZP,{onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>i.submit(),children:"Save Changes"})]})]})})]})]})},nO=e=>{let{costConfig:s}=e,t=(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null,l=(null==s?void 0:s.tool_name_to_cost_per_query)&&Object.keys(s.tool_name_to_cost_per_query).length>0;return t||l?(0,c.jsx)("div",{className:"mt-6 pt-6 border-t border-gray-200",children:(0,c.jsxs)("div",{className:"space-y-4",children:[t&&(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Default Cost per Query"}),(0,c.jsxs)("div",{className:"text-green-600 font-mono",children:["$",s.default_cost_per_query.toFixed(4)]})]}),l&&(null==s?void 0:s.tool_name_to_cost_per_query)&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Tool-Specific Costs"}),(0,c.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(s.tool_name_to_cost_per_query).map(e=>{let[s,t]=e;return null!=t&&(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 bg-gray-50 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:s}),(0,c.jsxs)(k.Z,{className:"text-green-600 font-mono",children:["$",t.toFixed(4)," per query"]})]},s)})})]}),(0,c.jsxs)("div",{className:"mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"text-blue-800 font-medium",children:"Cost Summary:"}),(0,c.jsxs)("div",{className:"mt-2 space-y-1",children:[t&&(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• Default cost: $",s.default_cost_per_query.toFixed(4)," per query"]}),l&&(null==s?void 0:s.tool_name_to_cost_per_query)&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• ",Object.keys(s.tool_name_to_cost_per_query).length," tool(s) with custom pricing"]})]})]})]})}):(0,c.jsx)("div",{className:"mt-6 pt-6 border-t border-gray-200",children:(0,c.jsx)("div",{className:"space-y-4",children:(0,c.jsx)("div",{className:"p-4 bg-gray-50 border border-gray-200 rounded-lg",children:(0,c.jsx)(k.Z,{className:"text-gray-600",children:"No cost configuration set for this server. Tool calls will be charged at $0.00 per tool call."})})})})};let nD=e=>{var s,t,l,a;let{mcpServer:r,onBack:i,isEditing:n,isProxyAdmin:o,accessToken:m,userRole:u,userID:x,availableAccessGroups:h}=e,[p,g]=(0,d.useState)(n),[j,f]=(0,d.useState)(!1),[v,_]=(0,d.useState)({}),{maskedUrl:N,hasToken:Z}=n_(r.url),w=(e,s)=>Z?s?e:N:e,C=async(e,s)=>{await eM(e)&&(_(e=>({...e,[s]:!0})),setTimeout(()=>{_(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4 max-w-full",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",className:"mb-4",onClick:i,children:"Back to All Servers"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(S.Z,{children:r.server_name}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-server_name"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.server_name,"mcp-server_name"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-server_name"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")}),r.alias&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("span",{className:"ml-4 text-gray-500",children:"Alias:"}),(0,c.jsx)("span",{className:"ml-1 font-mono text-blue-600",children:r.alias}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-alias"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.alias,"mcp-alias"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-alias"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:r.server_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-server-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.server_id,"mcp-server-id"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-server-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:p?2:0,children:[(0,c.jsx)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),(0,c.jsx)(e0.Z,{children:"MCP Tools"},"tools"),...o?[(0,c.jsx)(e0.Z,{children:"Settings"},"settings")]:[]]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Transport"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{children:nA(null!==(l=r.transport)&&void 0!==l?l:void 0)})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Auth Type"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(k.Z,{children:nL(null!==(a=r.auth_type)&&void 0!==a?a:void 0)})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Host Url"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,c.jsx)(k.Z,{className:"break-all overflow-wrap-anywhere",children:w(r.url,j)}),Z&&(0,c.jsx)("button",{onClick:()=>f(!j),className:"p-1 hover:bg-gray-100 rounded",children:(0,c.jsx)(sZ.Z,{icon:j?nk.Z:nS.Z,size:"sm",className:"text-gray-500"})})]})]})]}),(0,c.jsxs)(G.Z,{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:"Cost Configuration"}),(0,c.jsx)(nO,{costConfig:null===(s=r.mcp_info)||void 0===s?void 0:s.mcp_server_cost_info})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(os,{serverId:r.server_id,accessToken:m,auth_type:r.auth_type,userRole:u,userID:x,serverAlias:r.alias})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"MCP Server Settings"}),p?null:(0,c.jsx)(b.Z,{variant:"light",onClick:()=>g(!0),children:"Edit Settings"})]}),p?(0,c.jsx)(nM,{mcpServer:r,accessToken:m,onCancel:()=>g(!1),onSuccess:e=>{g(!1),i()},availableAccessGroups:h}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Server Name"}),(0,c.jsx)("div",{children:r.server_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Alias"}),(0,c.jsx)("div",{children:r.alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Description"}),(0,c.jsx)("div",{children:r.description})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"URL"}),(0,c.jsxs)("div",{className:"font-mono break-all overflow-wrap-anywhere max-w-full flex items-center gap-2",children:[w(r.url,j),Z&&(0,c.jsx)("button",{onClick:()=>f(!j),className:"p-1 hover:bg-gray-100 rounded",children:(0,c.jsx)(sZ.Z,{icon:j?nk.Z:nS.Z,size:"sm",className:"text-gray-500"})})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Transport"}),(0,c.jsx)("div",{children:nA(r.transport)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Auth Type"}),(0,c.jsx)("div",{children:nL(r.auth_type)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Access Groups"}),(0,c.jsx)("div",{children:r.mcp_access_groups&&r.mcp_access_groups.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:r.mcp_access_groups.map((e,s)=>{var t;return(0,c.jsx)("span",{className:"px-2 py-1 bg-gray-100 rounded-md text-sm",children:"string"==typeof e?e:null!==(t=null==e?void 0:e.name)&&void 0!==t?t:""},s)})}):(0,c.jsx)(k.Z,{className:"text-gray-500",children:"No access groups defined"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cost Configuration"}),(0,c.jsx)(nO,{costConfig:null===(t=r.mcp_info)||void 0===t?void 0:t.mcp_server_cost_info})]})]})]})})]})]})]})};var nF=t(83669);let{Panel:nR}=t_.default;var nz=e=>{let{accessToken:s,formValues:t,onToolsLoaded:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),h=t.url&&t.transport&&t.auth_type&&s,p=async()=>{if(s&&t.url){n(!0),m(null);try{let e={server_id:t.server_id||"",server_name:t.server_name||"",url:t.url,transport:t.transport,auth_type:t.auth_type,mcp_info:t.mcp_info},a=await (0,j.testMCPToolsListRequest)(s,e);if(a.tools&&!a.error)r(a.tools),m(null),null==l||l(a.tools),a.tools.length>0&&!u&&x(!0);else{let e=a.message||"Failed to retrieve tools list";m(e),r([]),null==l||l([]),x(!1)}}catch(e){console.error("Tools fetch error:",e),m(e instanceof Error?e.message:String(e)),r([]),null==l||l([]),x(!1)}finally{n(!1)}}};return((0,d.useEffect)(()=>{h?p():(r([]),m(null),x(!1),null==l||l([]))},[t.url,t.transport,t.auth_type,s]),h||t.url)?(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(nF.Z,{className:"text-blue-600"}),(0,c.jsx)(S.Z,{children:"Connection Status"})]}),!h&&t.url&&(0,c.jsxs)("div",{className:"text-center py-6 text-gray-400 border rounded-lg border-dashed",children:[(0,c.jsx)(rC.Z,{className:"text-2xl mb-2"}),(0,c.jsx)(k.Z,{children:"Complete required fields to test connection"}),(0,c.jsx)("br",{}),(0,c.jsx)(k.Z,{className:"text-sm",children:"Fill in URL, Transport, and Authentication to test MCP server connection"})]}),h&&(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-gray-700 font-medium",children:i?"Testing connection to MCP server...":a.length>0?"Connection successful":o?"Connection failed":"Ready to test connection"}),(0,c.jsx)("br",{}),(0,c.jsxs)(k.Z,{className:"text-gray-500 text-sm",children:["Server: ",t.url]})]}),i&&(0,c.jsxs)("div",{className:"flex items-center text-blue-600",children:[(0,c.jsx)(lI.Z,{size:"small",className:"mr-2"}),(0,c.jsx)(k.Z,{className:"text-blue-600",children:"Connecting..."})]}),!i&&!o&&a.length>0&&(0,c.jsxs)("div",{className:"flex items-center text-green-600",children:[(0,c.jsx)(nF.Z,{className:"mr-1"}),(0,c.jsx)(k.Z,{className:"text-green-600 font-medium",children:"Connected"})]}),o&&(0,c.jsxs)("div",{className:"flex items-center text-red-600",children:[(0,c.jsx)(lY.Z,{className:"mr-1"}),(0,c.jsx)(k.Z,{className:"text-red-600 font-medium",children:"Failed"})]})]}),i&&(0,c.jsxs)("div",{className:"flex items-center justify-center py-6",children:[(0,c.jsx)(lI.Z,{size:"large"}),(0,c.jsx)(k.Z,{className:"ml-3",children:"Testing connection and loading tools..."})]}),o&&(0,c.jsx)(ls.Z,{message:"Connection Failed",description:o,type:"error",showIcon:!0,action:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(tl.Z,{}),onClick:p,size:"small",children:"Retry"})}),!i&&a.length>0&&(0,c.jsx)(t_.default,{items:[{key:"1",label:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2 text-green-500"}),(0,c.jsx)("span",{className:"font-medium",children:"Available Tools"}),(0,c.jsx)(iG.Z,{count:a.length,style:{backgroundColor:"#52c41a",marginLeft:"8px"}})]}),children:(0,c.jsx)("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:a.map((e,s)=>(0,c.jsxs)("div",{className:"p-3 bg-gray-50 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900",children:e.name}),e.description&&(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm block mt-1",children:e.description})]},s))})}]}),!i&&0===a.length&&!o&&(0,c.jsxs)("div",{className:"text-center py-6 text-gray-500 border rounded-lg border-dashed",children:[(0,c.jsx)(nF.Z,{className:"text-2xl mb-2 text-green-500"}),(0,c.jsx)(k.Z,{className:"text-green-600 font-medium",children:"Connection successful!"}),(0,c.jsx)("br",{}),(0,c.jsx)(k.Z,{className:"text-gray-500",children:"No tools found for this MCP server"})]})]})]})}):null},nU=e=>{let{isVisible:s}=e;return s?(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Stdio Configuration (JSON)",(0,c.jsx)(V.Z,{title:"Paste your stdio MCP server configuration in JSON format. You can use the full mcpServers structure from config.yaml or just the inner server configuration.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"stdio_config",rules:[{required:!0,message:"Please enter stdio configuration"},{validator:(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}}}],children:(0,c.jsx)(E.default.TextArea,{placeholder:'{\n "mcpServers": {\n "circleci-mcp-server": {\n "command": "npx",\n "args": ["-y", "@circleci/mcp-server-circleci"],\n "env": {\n "CIRCLECI_TOKEN": "your-circleci-token",\n "CIRCLECI_BASE_URL": "https://circleci.com"\n }\n }\n }\n}',rows:12,className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500 font-mono text-sm"})}):null};let nq="".concat("../ui/assets/logos/","mcp_logo.png");var nB=e=>{let{userRole:s,accessToken:t,onCreateSuccess:l,isModalVisible:a,setModalVisible:r,availableAccessGroups:i}=e,[n]=A.Z.useForm(),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)({}),[h,p]=(0,d.useState)({}),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),[N,Z]=(0,d.useState)("sse"),[w,k]=(0,d.useState)(""),[S,C]=(0,d.useState)(""),T=(e,s)=>{if(!e){C("");return}"sse"!==s||e.endsWith("/sse")?"http"!==s||e.endsWith("/mcp")?C(""):C("Typically MCP HTTP URLs end with /mcp. You can add this url but this is a warning."):C("Typically MCP SSE URLs end with /sse. You can add this url but this is a warning.")},P=async e=>{m(!0);try{let s=e.mcp_access_groups,a={};if(e.stdio_config&&"stdio"===N)try{let s=JSON.parse(e.stdio_config),t=s;if(s.mcpServers&&"object"==typeof s.mcpServers){let l=Object.keys(s.mcpServers);if(l.length>0){let a=l[0];t=s.mcpServers[a],e.server_name||(e.server_name=a.replace(/-/g,"_"))}}a={command:t.command,args:t.args,env:t.env},console.log("Parsed stdio config:",a)}catch(e){eo.Z.fromBackend("Invalid JSON in stdio configuration");return}let i={...e,...a,stdio_config:void 0,mcp_info:{server_name:e.server_name||e.url,description:e.description,mcp_server_cost_info:Object.keys(u).length>0?u:null},mcp_access_groups:s,alias:e.alias};if(console.log("Payload: ".concat(JSON.stringify(i))),null!=t){let e=await (0,j.createMCPServer)(t,i);eo.Z.success("MCP Server created successfully"),n.resetFields(),x({}),y([]),C(""),r(!1),l(e)}}catch(e){eo.Z.fromBackend("Error creating MCP Server: "+e)}finally{m(!1)}},E=()=>{n.resetFields(),x({}),y([]),C(""),r(!1)};return(d.useEffect(()=>{if(!g&&h.server_name){let e=h.server_name.replace(/\s+/g,"_");n.setFieldsValue({alias:e}),p(s=>({...s,alias:e}))}},[h.server_name]),(0,eI.tY)(s))?(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:[(0,c.jsx)("img",{src:nq,alt:"MCP Logo",className:"w-8 h-8 object-contain",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"}}),(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add New MCP Server"})]}),open:a,width:1e3,onCancel:E,footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsxs)(A.Z,{form:n,onFinish:P,onValuesChange:(e,s)=>p(s),layout:"vertical",className:"space-y-6",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Server Name",(0,c.jsx)(V.Z,{title:"Best practice: Use a descriptive name that indicates the server's purpose (e.g., 'GitHub_MCP', 'Email_Service'). Hyphens '-' are not allowed; use underscores '_' instead.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"server_name",rules:[{required:!1,message:"Please enter a server name"},{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., GitHub_MCP, Zapier_MCP, etc.",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Alias",(0,c.jsx)(V.Z,{title:"A short, unique identifier for this server. Defaults to the server name with spaces replaced by underscores.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"alias",rules:[{required:!1},{validator:(e,s)=>s&&s.includes("-")?Promise.reject("Alias cannot contain '-' (hyphen). Please use '_' (underscore) instead."):Promise.resolve()}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., GitHub_MCP, Zapier_MCP, etc.",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500",onChange:()=>f(!0)})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Description"}),name:"description",rules:[{required:!1,message:"Please enter a server description"}],children:(0,c.jsx)(_.Z,{placeholder:"Brief description of what this server does",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Transport Type"}),name:"transport",rules:[{required:!0,message:"Please select a transport type"}],children:(0,c.jsxs)(I.default,{placeholder:"Select transport",className:"rounded-lg",size:"large",onChange:e=>{if(Z(e),"stdio"===e)n.setFieldsValue({url:void 0,auth_type:void 0}),C("");else{n.setFieldsValue({command:void 0,args:void 0,env:void 0});let s=n.getFieldValue("url");s&&T(s,e)}},value:N,children:[(0,c.jsx)(I.default.Option,{value:"http",children:"HTTP"}),(0,c.jsx)(I.default.Option,{value:"sse",children:"Server-Sent Events (SSE)"}),(0,c.jsx)(I.default.Option,{value:"stdio",children:"Standard Input/Output (stdio)"})]})}),"stdio"!==N&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"MCP Server URL"}),name:"url",rules:[{required:!0,message:"Please enter a server URL"},{validator:(e,s)=>nN(s)}],children:(0,c.jsxs)("div",{children:[(0,c.jsx)(_.Z,{placeholder:"https://your-mcp-server.com",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500",onChange:e=>T(e.target.value,N)}),S&&(0,c.jsx)("div",{className:"mt-1 text-red-500 text-sm font-medium",children:S})]})}),"stdio"!==N&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Authentication"}),name:"auth_type",rules:[{required:!0,message:"Please select an auth type"}],children:(0,c.jsxs)(I.default,{placeholder:"Select auth type",className:"rounded-lg",size:"large",children:[(0,c.jsx)(I.default.Option,{value:"none",children:"None"}),(0,c.jsx)(I.default.Option,{value:"api_key",children:"API Key"}),(0,c.jsx)(I.default.Option,{value:"bearer_token",children:"Bearer Token"}),(0,c.jsx)(I.default.Option,{value:"basic",children:"Basic Auth"})]})}),(0,c.jsx)(nU,{isVisible:"stdio"===N}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Access Groups",(0,c.jsx)(V.Z,{title:"Specify access groups for this MCP server. Users must be in at least one of these groups to access the server.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"mcp_access_groups",className:"mb-4",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"value",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.value)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},onSearch:e=>k(e),tokenSeparators:[","],options:(()=>{let e=i.map(e=>({value:e,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})}));return w&&!i.some(e=>e.toLowerCase().includes(w.toLowerCase()))&&e.push({value:w,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:w}),(0,c.jsx)("span",{className:"text-gray-400 text-xs ml-1",children:"create new group"})]})}),e})(),maxTagCount:"responsive",allowClear:!0})})]}),(0,c.jsx)("div",{className:"mt-8 pt-6 border-t border-gray-200",children:(0,c.jsx)(nz,{accessToken:t,formValues:h,onToolsLoaded:y})}),(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsx)(nE,{value:u,onChange:x,tools:v,disabled:!1})}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:E,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",loading:o,children:o?"Creating...":"Add MCP Server"})]})]})})}):null},nV=t(64935),nK=t(11239),nG=t(54001),nH=t(96137),nJ=t(96362),nY=t(80221),nW=t(29202);let{Title:n$,Text:nQ}=en.default,{Panel:nX}=t_.default,n0=e=>{let{icon:s,title:t,description:l,children:a,serverName:r,accessGroups:i=["dev"]}=e,[n,o]=(0,d.useState)(!1),m=()=>{let e={"x-litellm-api-key":"Bearer YOUR_LITELLM_API_KEY"};if(n&&r){let s=[r.replace(/\s+/g,"_"),...i].join(",");e["x-mcp-servers"]=[s]}return e};return(0,c.jsxs)(tN.Z,{className:"border border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)("span",{className:"p-2 rounded-lg bg-gray-50",children:s}),(0,c.jsxs)("div",{children:[(0,c.jsx)(n$,{level:5,className:"mb-0",children:t}),(0,c.jsx)(nQ,{className:"text-gray-600",children:l})]})]}),r&&("Implementation Example"===t||"Configuration"===t)&&(0,c.jsxs)(A.Z.Item,{className:"mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(tj.Z,{size:"small",checked:n,onChange:o}),(0,c.jsxs)(nQ,{className:"text-sm",children:["Limit tools to specific MCP servers or MCP groups by passing the ",(0,c.jsx)("code",{children:"x-mcp-servers"})," header"]})]}),n&&(0,c.jsx)(ls.Z,{className:"mt-2",type:"info",showIcon:!0,message:"Two Options",description:(0,c.jsxs)("div",{children:[(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Option 1:"})," Get a specific server: ",(0,c.jsxs)("code",{children:['["',r.replace(/\s+/g,"_"),'"]']})]}),(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Option 2:"})," Get a group of MCPs: ",(0,c.jsx)("code",{children:'["dev-group"]'})]}),(0,c.jsxs)("p",{className:"mt-2 text-sm text-gray-600",children:["You can also mix both: ",(0,c.jsx)("code",{children:'["Server1,dev-group"]'})]})]})})]}),d.Children.map(a,e=>{if(d.isValidElement(e)&&e.props.hasOwnProperty("code")&&e.props.hasOwnProperty("copyKey")){let s=e.props.code;if(s&&s.includes('"headers":'))return d.cloneElement(e,{code:s.replace(/"headers":\s*{[^}]*}/,'"headers": '.concat(JSON.stringify(m(),null,8)))})}return e})]})};var n1=e=>{let{currentServerAccessGroups:s=[]}=e,t=(0,j.getProxyBaseUrl)(),[l,a]=(0,d.useState)({}),[r,i]=(0,d.useState)({openai:[],litellm:[],cursor:[],http:[]}),[n]=(0,d.useState)("Zapier_MCP"),o=async(e,s)=>{await eM(e)&&(a(e=>({...e,[s]:!0})),setTimeout(()=>{a(e=>({...e,[s]:!1}))},2e3))},m=e=>{let{code:s,copyKey:t,title:a,className:r=""}=e;return(0,c.jsxs)("div",{className:"relative group",children:[a&&(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(nV.Z,{size:16,className:"text-blue-600"}),(0,c.jsx)(nQ,{strong:!0,className:"text-gray-700",children:a})]}),(0,c.jsxs)(tN.Z,{className:"bg-gray-50 border border-gray-200 relative ".concat(r),children:[(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:l[t]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>o(s,t),className:"absolute top-2 right-2 z-10 transition-all duration-200 ".concat(l[t]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")}),(0,c.jsx)("pre",{className:"text-sm overflow-x-auto pr-10 text-gray-800 font-mono leading-relaxed",children:s})]})]})},u=e=>{let{step:s,title:t,children:l}=e;return(0,c.jsxs)("div",{className:"flex gap-4",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("div",{className:"w-8 h-8 bg-blue-600 text-white rounded-full flex items-center justify-center text-sm font-semibold",children:s})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsx)(nQ,{strong:!0,className:"text-gray-800 block mb-2",children:t}),l]})]})};return(0,c.jsx)("div",{children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{className:"text-3xl font-bold text-gray-900 mb-3",children:"Connect to your MCP client"}),(0,c.jsx)(k.Z,{className:"text-lg text-gray-600",children:"Use tools directly from any MCP client with LiteLLM MCP. Enable your AI assistant to perform real-world tasks through a simple, secure connection."})]}),(0,c.jsxs)(e1.Z,{className:"w-full",children:[(0,c.jsx)(e2.Z,{className:"flex justify-start mt-8 mb-6",children:(0,c.jsxs)("div",{className:"flex bg-gray-100 p-1 rounded-lg",children:[(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nV.Z,{size:18}),"OpenAI API"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nK.Z,{size:18}),"LiteLLM Proxy"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nY.Z,{size:18}),"Cursor"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nW.Z,{size:18}),"Streamable HTTP"]})})]})}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 p-6 rounded-lg border border-blue-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nV.Z,{className:"text-blue-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-blue-900",children:"OpenAI Responses API Integration"})]}),(0,c.jsx)(nQ,{className:"text-blue-700",children:"Connect OpenAI Responses API to your LiteLLM MCP server for seamless tool integration"})]}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(n0,{icon:(0,c.jsx)(nG.Z,{className:"text-blue-600",size:16}),title:"API Key Setup",description:"Configure your OpenAI API key for authentication",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsxs)(nQ,{children:["Get your API key from the"," ",(0,c.jsxs)("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-700 inline-flex items-center gap-1",children:["OpenAI platform ",(0,c.jsx)(nJ.Z,{size:12})]})]})}),(0,c.jsx)(m,{title:"Environment Variable",code:'export OPENAI_API_KEY="sk-..."',copyKey:"openai-env"})]})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nH.Z,{className:"text-blue-600",size:16}),title:"MCP Server Information",description:"Connection details for your LiteLLM MCP server",children:(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"openai-server-url"})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-blue-600",size:16}),title:"Implementation Example",description:"Complete cURL example for using the Responses API",serverName:"Zapier Gmail",accessGroups:["dev"],children:(0,c.jsx)(m,{code:'curl --location \'https://api.openai.com/v1/responses\' \\\n--header \'Content-Type: application/json\' \\\n--header "Authorization: Bearer $OPENAI_API_KEY" \\\n--data \'{\n "model": "gpt-4.1",\n "tools": [\n {\n "type": "mcp",\n "server_label": "litellm",\n "server_url": "'.concat(t,'/mcp",\n "require_approval": "never",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n ],\n "input": "Run available tools",\n "tool_choice": "required"\n}\''),copyKey:"openai-curl",className:"text-xs"})})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-emerald-50 to-green-50 p-6 rounded-lg border border-emerald-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nK.Z,{className:"text-emerald-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-emerald-900",children:"LiteLLM Proxy API Integration"})]}),(0,c.jsx)(nQ,{className:"text-emerald-700",children:"Connect to LiteLLM Proxy Responses API for seamless tool integration with multiple model providers"})]}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(n0,{icon:(0,c.jsx)(nG.Z,{className:"text-emerald-600",size:16}),title:"API Key Setup",description:"Configure your LiteLLM Proxy API key for authentication",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsx)(nQ,{children:"Get your API key from your LiteLLM Proxy dashboard or contact your administrator"})}),(0,c.jsx)(m,{title:"Environment Variable",code:'export LITELLM_API_KEY="sk-..."',copyKey:"litellm-env"})]})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nH.Z,{className:"text-emerald-600",size:16}),title:"MCP Server Information",description:"Connection details for your LiteLLM MCP server",children:(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"litellm-server-url"})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-emerald-600",size:16}),title:"Implementation Example",description:"Complete cURL example for using the LiteLLM Proxy Responses API",serverName:n,accessGroups:["dev"],children:(0,c.jsx)(m,{code:"curl --location '".concat(t,'/v1/responses\' \\\n--header \'Content-Type: application/json\' \\\n--header "Authorization: Bearer $LITELLM_API_KEY" \\\n--data \'{\n "model": "gpt-4",\n "tools": [\n {\n "type": "mcp",\n "server_label": "litellm",\n "server_url": "').concat(t,'/mcp",\n "require_approval": "never",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n ],\n "input": "Run available tools",\n "tool_choice": "required"\n}\''),copyKey:"litellm-curl",className:"text-xs"})})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-purple-50 to-blue-50 p-6 rounded-lg border border-purple-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nY.Z,{className:"text-purple-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-purple-900",children:"Cursor IDE Integration"})]}),(0,c.jsx)(nQ,{className:"text-purple-700",children:"Use tools directly from Cursor IDE with LiteLLM MCP. Enable your AI assistant to perform real-world tasks without leaving your coding environment."})]}),(0,c.jsxs)(tN.Z,{className:"border border-gray-200",children:[(0,c.jsx)(n$,{level:5,className:"mb-4 text-gray-800",children:"Setup Instructions"}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(u,{step:1,title:"Open Cursor Settings",children:(0,c.jsxs)(nQ,{className:"text-gray-600",children:["Use the keyboard shortcut ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"⇧+⌘+J"})," (Mac) or ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Ctrl+Shift+J"})," (Windows/Linux)"]})}),(0,c.jsx)(u,{step:2,title:"Navigate to MCP Tools",children:(0,c.jsx)(nQ,{className:"text-gray-600",children:'Go to the "MCP Tools" tab and click "New MCP Server"'})}),(0,c.jsxs)(u,{step:3,title:"Add Configuration",children:[(0,c.jsxs)(nQ,{className:"text-gray-600 mb-3",children:["Copy the JSON configuration below and paste it into Cursor, then save with ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Cmd+S"})," or ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Ctrl+S"})]}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-purple-600",size:16}),title:"Configuration",description:"Cursor MCP configuration",serverName:"Zapier Gmail",accessGroups:["dev"],children:(0,c.jsx)(m,{code:'{\n "mcpServers": {\n "Zapier_MCP": {\n "server_url": "'.concat(t,'/mcp",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n }\n}'),copyKey:"cursor-config",className:"text-xs"})})]})]})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-green-50 to-teal-50 p-6 rounded-lg border border-green-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nW.Z,{className:"text-green-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-green-900",children:"Streamable HTTP Transport"})]}),(0,c.jsx)(nQ,{className:"text-green-700",children:"Connect to LiteLLM MCP using HTTP transport. Compatible with any MCP client that supports HTTP streaming."})]}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nW.Z,{className:"text-green-600",size:16}),title:"Universal MCP Connection",description:"Use this URL with any MCP client that supports HTTP transport",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsx)(nQ,{children:"Each MCP client supports different transports. Refer to your client documentation to determine the appropriate transport method."})}),(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"http-server-url"}),(0,c.jsx)(m,{title:"Headers Configuration",code:JSON.stringify({"x-litellm-api-key":"Bearer YOUR_LITELLM_API_KEY"},null,2),copyKey:"http-headers"}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(P.ZP,{type:"link",className:"p-0 h-auto text-blue-600 hover:text-blue-700",href:"https://modelcontextprotocol.io/docs/concepts/transports",icon:(0,c.jsx)(nJ.Z,{size:14}),children:"Learn more about MCP transports"})})]})})]}),{})})]})]})]})})};let{Option:n2}=I.default,n4=e=>{let{isModalOpen:s,title:t,confirmDelete:l,cancelDelete:a}=e;return s?(0,c.jsx)(L.Z,{open:s,onOk:l,okType:"danger",onCancel:a,children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:t}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)("p",{children:"Are you sure you want to delete this MCP Server?"})})]})}):null};var n5=e=>{let{accessToken:s,userRole:t,userID:l}=e,{data:a,isLoading:r,refetch:i,dataUpdatedAt:n}=(0,sj.a)({queryKey:["mcpServers"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,j.fetchMCPServers)(s)},enabled:!!s}),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)("all"),[_,N]=(0,d.useState)("all"),[Z,w]=(0,d.useState)([]),[C,A]=(0,d.useState)(!1),L="Internal User"===t,T=d.useMemo(()=>{if(!a)return[];let e=new Set,s=[];return a.forEach(t=>{t.teams&&t.teams.forEach(t=>{let l=t.team_id;e.has(l)||(e.add(l),s.push(t))})}),s},[a]),P=d.useMemo(()=>a?Array.from(new Set(a.flatMap(e=>e.mcp_access_groups).filter(e=>null!=e))):[],[a]),E=e=>{y(e),O(e,_)},M=e=>{N(e),O(v,e)},O=(e,s)=>{if(!a)return w([]);let t=a;if("personal"===e){w([]);return}"all"!==e&&(t=t.filter(s=>{var t;return null===(t=s.teams)||void 0===t?void 0:t.some(s=>s.team_id===e)})),"all"!==s&&(t=t.filter(e=>{var t;return null===(t=e.mcp_access_groups)||void 0===t?void 0:t.some(e=>"string"==typeof e?e===s:e&&e.name===s)})),w(t)};(0,d.useEffect)(()=>{O(v,_)},[n]);let D=d.useMemo(()=>nw(null!=t?t:"",e=>{p(e),f(!1)},e=>{p(e),f(!0)},F),[t]);function F(e){m(e),x(!0)}let R=async()=>{if(null!=o&&null!=s){try{await (0,j.deleteMCPServer)(s,o),eo.Z.success("Deleted MCP Server successfully"),i()}catch(e){console.error("Error deleting the mcp server:",e)}x(!1),m(null)}};return s&&t&&l?(0,c.jsxs)("div",{className:"w-full h-full p-6",children:[(0,c.jsx)(n4,{isModalOpen:u,title:"Delete MCP Server",confirmDelete:R,cancelDelete:()=>{x(!1),m(null)}}),(0,c.jsx)(nB,{userRole:t,accessToken:s,onCreateSuccess:e=>{w(s=>[...s,e]),A(!1)},isModalVisible:C,setModalVisible:A,availableAccessGroups:P}),(0,c.jsx)(S.Z,{children:"MCP Servers"}),(0,c.jsx)(k.Z,{className:"text-tremor-content mt-2",children:"Configure and manage your MCP servers"}),(0,eI.tY)(t)&&(0,c.jsx)(b.Z,{className:"mt-4 mb-4",onClick:()=>A(!0),children:"+ Add New MCP Server"}),(0,c.jsxs)(e1.Z,{className:"w-full h-full",children:[(0,c.jsx)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"All Servers"}),(0,c.jsx)(e0.Z,{children:"Connect"})]})}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(()=>h?(0,c.jsx)(nD,{mcpServer:Z.find(e=>e.server_id===h)||{server_id:"",server_name:"",alias:"",url:"",transport:"",auth_type:"",created_at:"",created_by:"",updated_at:"",updated_by:""},onBack:()=>{f(!1),p(null),i()},isProxyAdmin:(0,eI.tY)(t),isEditing:g,accessToken:s,userID:l,userRole:t,availableAccessGroups:P}):(0,c.jsxs)("div",{className:"w-full h-full",children:[(0,c.jsx)("div",{className:"w-full px-6",children:(0,c.jsx)("div",{className:"flex flex-col space-y-4",children:(0,c.jsx)("div",{className:"flex items-center justify-between bg-gray-50 rounded-lg p-4 border-2 border-gray-200",children:(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"Current Team:"}),(0,c.jsxs)(I.default,{value:v,onChange:E,style:{width:300},children:[(0,c.jsx)(n2,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:L?"All Available Servers":"All Servers"})]})}),(0,c.jsx)(n2,{value:"personal",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Personal"})]})}),T.map(e=>(0,c.jsx)(n2,{value:e.team_id,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e.team_alias||e.team_id})]})},e.team_id))]}),(0,c.jsxs)(k.Z,{className:"text-lg font-semibold text-gray-900 ml-6",children:["Access Group:",(0,c.jsx)(V.Z,{title:"An MCP Access Group is a set of users or teams that have permission to access specific MCP servers. Use access groups to control and organize who can connect to which servers.",children:(0,c.jsx)(tL.Z,{style:{marginLeft:4,color:"#888"}})})]}),(0,c.jsxs)(I.default,{value:_,onChange:M,style:{width:300},children:[(0,c.jsx)(n2,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"All Access Groups"})]})}),P.map(e=>(0,c.jsx)(n2,{value:e,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})},e))]})]})})})}),(0,c.jsx)("div",{className:"w-full px-6 mt-6",children:(0,c.jsx)(lx,{data:Z,columns:D,renderSubComponent:()=>(0,c.jsx)("div",{}),getRowCanExpand:()=>!1,isLoading:r,noDataMessage:"No MCP servers configured"})})]}),{})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(n1,{})})]})]})]}):(console.log("Missing required authentication parameters",{accessToken:s,userRole:t,userID:l}),(0,c.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."}))},n6=t(21770);function n3(e){let{tool:s,needsAuth:t,authValue:l,onSubmit:a,isLoading:r,result:i,error:n,onClose:o}=e,[m]=A.Z.useForm(),[u,x]=d.useState("formatted"),[h,p]=d.useState(null),[g,j]=d.useState(null),f=d.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),v=d.useMemo(()=>f.properties&&f.properties.params&&"object"===f.properties.params.type&&f.properties.params.properties?{type:"object",properties:f.properties.params.properties,required:f.properties.params.required||[]}:f,[f]);d.useEffect(()=>{h&&(i||n)&&j(Date.now()-h)},[i,n,h]);let y=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0;{let s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.focus(),s.select();let t=document.execCommand("copy");if(document.body.removeChild(s),!t)throw Error("execCommand failed");return!0}}catch(e){return console.error("Copy failed:",e),!1}},N=async()=>{await y(JSON.stringify(i,null,2))?eo.Z.success("Result copied to clipboard"):eo.Z.fromBackend("Failed to copy result")},Z=async()=>{await y(s.name)?eo.Z.success("Tool name copied to clipboard"):eo.Z.fromBackend("Failed to copy tool name")};return(0,c.jsxs)("div",{className:"space-y-4 h-full",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between pb-3 border-b border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-3",children:[s.mcp_info.logo_url&&(0,c.jsx)("img",{src:s.mcp_info.logo_url,alt:"".concat(s.mcp_info.server_name," logo"),className:"w-6 h-6 object-contain"}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-1",children:[(0,c.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Test Tool:"}),(0,c.jsxs)("div",{className:"group inline-flex items-center space-x-1 bg-slate-50 hover:bg-slate-100 px-3 py-1 rounded-md cursor-pointer transition-colors border border-slate-200",onClick:Z,title:"Click to copy tool name",children:[(0,c.jsx)("span",{className:"font-mono text-slate-700 font-medium text-sm",children:s.name}),(0,c.jsx)("svg",{className:"w-3 h-3 text-slate-400 group-hover:text-slate-600 transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]})]}),(0,c.jsx)("p",{className:"text-xs text-gray-600",children:s.description}),(0,c.jsxs)("p",{className:"text-xs text-gray-500",children:["Provider: ",s.mcp_info.server_name]})]})]}),(0,c.jsx)(b.Z,{onClick:o,variant:"light",size:"sm",className:"text-gray-500 hover:text-gray-700",children:(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4 h-full",children:[(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"border-b border-gray-100 px-4 py-2",children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Input Parameters"}),(0,c.jsx)(V.Z,{title:"Configure the input parameters for this tool call",children:(0,c.jsx)(B.Z,{className:"text-gray-400 hover:text-gray-600"})})]})}),(0,c.jsx)("div",{className:"p-4",children:(0,c.jsxs)(A.Z,{form:m,onFinish:e=>{p(Date.now()),j(null);let s={};Object.entries(e).forEach(e=>{var t;let[l,a]=e,r=null===(t=v.properties)||void 0===t?void 0:t[l];if(r&&null!=a&&""!==a)switch(r.type){case"boolean":s[l]="true"===a||!0===a;break;case"number":s[l]=Number(a);break;case"string":s[l]=String(a);break;default:s[l]=a}else null!=a&&""!==a&&(s[l]=a)}),a(f.properties&&f.properties.params&&"object"===f.properties.params.type&&f.properties.params.properties?{params:s}:s)},layout:"vertical",className:"space-y-3",children:["string"==typeof s.inputSchema?(0,c.jsx)("div",{className:"space-y-3",children:(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Input ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"input",rules:[{required:!0,message:"Please enter input for this tool"}],className:"mb-3",children:(0,c.jsx)(_.Z,{placeholder:"Enter input for this tool",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})})}):void 0===v.properties?(0,c.jsx)("div",{className:"text-center py-6 bg-gray-50 rounded-lg border border-gray-200",children:(0,c.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-gray-900 mb-1",children:"No Parameters Required"}),(0,c.jsx)("p",{className:"text-xs text-gray-500",children:"This tool can be called without any input parameters."})]})}):(0,c.jsx)("div",{className:"space-y-3",children:Object.entries(v.properties).map(e=>{var s,t,l,a,r;let[i,n]=e;return(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:[i," ",(null===(s=v.required)||void 0===s?void 0:s.includes(i))&&(0,c.jsx)("span",{className:"text-red-500",children:"*"}),n.description&&(0,c.jsx)(V.Z,{title:n.description,children:(0,c.jsx)(B.Z,{className:"ml-2 text-gray-400 hover:text-gray-600"})})]}),name:i,rules:[{required:null===(t=v.required)||void 0===t?void 0:t.includes(i),message:"Please enter ".concat(i)}],className:"mb-3",children:["string"===n.type&&n.enum&&(0,c.jsxs)("select",{className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors",defaultValue:n.default,children:[!(null===(l=v.required)||void 0===l?void 0:l.includes(i))&&(0,c.jsxs)("option",{value:"",children:["Select ",i]}),n.enum.map(e=>(0,c.jsx)("option",{value:e,children:e},e))]}),"string"===n.type&&!n.enum&&(0,c.jsx)(_.Z,{placeholder:n.description||"Enter ".concat(i),className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"}),"number"===n.type&&(0,c.jsx)("input",{type:"number",placeholder:n.description||"Enter ".concat(i),className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors"}),"boolean"===n.type&&(0,c.jsxs)("select",{className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors",defaultValue:(null===(a=n.default)||void 0===a?void 0:a.toString())||"",children:[!(null===(r=v.required)||void 0===r?void 0:r.includes(i))&&(0,c.jsxs)("option",{value:"",children:["Select ",i]}),(0,c.jsx)("option",{value:"true",children:"True"}),(0,c.jsx)("option",{value:"false",children:"False"})]})]},i)})}),(0,c.jsx)("div",{className:"pt-3 border-t border-gray-100",children:(0,c.jsx)(b.Z,{onClick:()=>m.submit(),disabled:r,variant:"primary",className:"w-full",loading:r,children:r?"Calling Tool...":i||n?"Call Again":"Call Tool"})})]})})]}),(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"border-b border-gray-100 px-4 py-2",children:(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Tool Result"})}),(0,c.jsx)("div",{className:"p-4",children:i||n||r?(0,c.jsxs)("div",{className:"space-y-3",children:[i&&!r&&!n&&(0,c.jsx)("div",{className:"p-2 bg-green-50 border border-green-200 rounded-lg",children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("svg",{className:"h-4 w-4 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,c.jsx)("h4",{className:"text-xs font-medium text-green-900",children:"Tool executed successfully"}),null!==g&&(0,c.jsxs)("span",{className:"text-xs text-green-600 ml-1",children:["• ",(g/1e3).toFixed(2),"s"]})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,c.jsxs)("div",{className:"flex bg-white rounded border border-green-300 p-0.5",children:[(0,c.jsx)("button",{onClick:()=>x("formatted"),className:"px-2 py-1 text-xs font-medium rounded transition-colors ".concat("formatted"===u?"bg-green-100 text-green-800":"text-green-600 hover:text-green-800"),children:"Formatted"}),(0,c.jsx)("button",{onClick:()=>x("json"),className:"px-2 py-1 text-xs font-medium rounded transition-colors ".concat("json"===u?"bg-green-100 text-green-800":"text-green-600 hover:text-green-800"),children:"JSON"})]}),(0,c.jsx)("button",{onClick:N,className:"p-1 hover:bg-green-100 rounded text-green-700",title:"Copy response",children:(0,c.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]})}),(0,c.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[r&&(0,c.jsxs)("div",{className:"flex flex-col justify-center items-center h-48 text-gray-500",children:[(0,c.jsxs)("div",{className:"relative",children:[(0,c.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-gray-200"}),(0,c.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-blue-600 border-t-transparent absolute top-0"})]}),(0,c.jsx)("p",{className:"text-sm font-medium mt-3",children:"Calling tool..."}),(0,c.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Please wait while we process your request"})]}),n&&(0,c.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,c.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("svg",{className:"h-4 w-4 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-1",children:[(0,c.jsx)("h4",{className:"text-xs font-medium text-red-900",children:"Tool Call Failed"}),null!==g&&(0,c.jsxs)("span",{className:"text-xs text-red-600",children:["• ",(g/1e3).toFixed(2),"s"]})]}),(0,c.jsx)("div",{className:"bg-white border border-red-200 rounded p-2 max-h-48 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-xs whitespace-pre-wrap text-red-700 font-mono",children:n.message})})]})]})}),i&&!r&&!n&&(0,c.jsx)("div",{className:"space-y-3",children:"formatted"===u?i.map((e,s)=>(0,c.jsxs)("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:["text"===e.type&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Text Response"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsx)("div",{className:"bg-white rounded border border-gray-200 max-h-64 overflow-y-auto",children:(0,c.jsx)("div",{className:"p-3 space-y-2",children:e.text.split("\n\n").map((e,s)=>{if(""===e.trim())return null;if(e.startsWith("##")){let t=e.replace(/^#+\s/,"");return(0,c.jsx)("div",{className:"border-b border-gray-200 pb-1 mb-2",children:(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:t})},s)}let t=/(https?:\/\/[^\s\)]+)/g;if(t.test(e)){let l=e.split(t);return(0,c.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded p-2",children:(0,c.jsx)("div",{className:"text-xs text-gray-700 leading-relaxed whitespace-pre-wrap",children:l.map((e,s)=>t.test(e)?(0,c.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline break-all",children:e},s):e)})},s)}return e.includes("Score:")?(0,c.jsx)("div",{className:"bg-green-50 border-l-4 border-green-400 p-2 rounded-r",children:(0,c.jsx)("p",{className:"text-xs text-green-800 font-medium whitespace-pre-wrap",children:e})},s):(0,c.jsx)("div",{className:"bg-gray-50 rounded p-2 border border-gray-200",children:(0,c.jsx)("div",{className:"text-xs text-gray-700 leading-relaxed whitespace-pre-wrap font-mono",children:e})},s)}).filter(Boolean)})})})]}),"image"===e.type&&e.url&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Image Response"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsx)("div",{className:"bg-gray-50 rounded p-3 border border-gray-200",children:(0,c.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded shadow-sm"})})})]}),"embedded_resource"===e.type&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Embedded Resource"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2 p-3 bg-blue-50 border border-blue-200 rounded",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("svg",{className:"h-5 w-5 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsxs)("p",{className:"text-xs font-medium text-blue-900",children:["Resource Type: ",e.resource_type]}),e.url&&(0,c.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-xs text-blue-600 hover:text-blue-800 hover:underline mt-1 transition-colors",children:["View Resource",(0,c.jsxs)("svg",{className:"ml-1 h-3 w-3",fill:"currentColor",viewBox:"0 0 20 20",children:[(0,c.jsx)("path",{d:"M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"}),(0,c.jsx)("path",{d:"M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"})]})]})]})]})})]})]},s)):(0,c.jsx)("div",{className:"bg-white rounded border border-gray-200",children:(0,c.jsx)("div",{className:"p-3 overflow-auto max-h-80 bg-gray-50",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all text-gray-800",children:JSON.stringify(i,null,2)})})})})]})]}):(0,c.jsx)("div",{className:"flex flex-col justify-center items-center h-48 text-gray-500",children:(0,c.jsxs)("div",{className:"text-center max-w-sm",children:[(0,c.jsx)("div",{className:"mb-3",children:(0,c.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-300",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),(0,c.jsx)("h4",{className:"text-sm font-medium text-gray-900 mb-1",children:"Ready to Call Tool"}),(0,c.jsx)("p",{className:"text-xs text-gray-500 leading-relaxed",children:'Configure the input parameters and click "Call Tool" to see the results here.'})]})})})]})]})]})}var n8=t(29488),n7=t(36724);let n9=e=>{let s,{visible:t,onOk:l,onCancel:a,authType:r}=e,[i]=A.Z.useForm();if(r===nC.API_KEY||r===nC.BEARER_TOKEN){let e=r===nC.API_KEY?"API Key":"Bearer Token";s=(0,c.jsx)(A.Z.Item,{name:"authValue",label:e,rules:[{required:!0,message:"Please input your ".concat(e)}],children:(0,c.jsx)(E.default.Password,{})})}else r===nC.BASIC&&(s=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{name:"username",label:"Username",rules:[{required:!0,message:"Please input your username"}],children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{name:"password",label:"Password",rules:[{required:!0,message:"Please input your password"}],children:(0,c.jsx)(E.default.Password,{})})]}));return(0,c.jsx)(L.Z,{open:t,title:"Authentication",onOk:()=>{i.validateFields().then(e=>{r===nC.BASIC?l("".concat(e.username.trim(),":").concat(e.password.trim())):l(e.authValue.trim())})},onCancel:a,destroyOnClose:!0,children:(0,c.jsx)(A.Z,{form:i,layout:"vertical",children:s})})},oe=e=>{let{authType:s,onAuthSubmit:t,onClearAuth:l,hasAuth:a}=e,[r,i]=(0,d.useState)(!1);return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)(n7.xv,{className:"text-sm font-medium text-gray-700",children:["Authentication ",a?"✓":""]}),(0,c.jsxs)("div",{className:"flex gap-2",children:[a&&(0,c.jsx)(n7.zx,{onClick:()=>{l()},size:"sm",variant:"secondary",className:"text-xs text-red-600 hover:text-red-700",children:"Clear"}),(0,c.jsx)(n7.zx,{onClick:()=>i(!0),size:"sm",variant:"secondary",className:"text-xs",children:a?"Update":"Add Auth"})]})]}),(0,c.jsx)(n7.xv,{className:"text-xs text-gray-500",children:a?"Authentication configured and saved locally":"Some tools may require authentication"}),(0,c.jsx)(n9,{visible:r,onOk:e=>{t(e),i(!1)},onCancel:()=>i(!1),authType:s})]})};var os=e=>{let{serverId:s,accessToken:t,auth_type:l,userRole:a,userID:r,serverAlias:i}=e,[n,o]=(0,d.useState)(""),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(nT(l)){let e=(0,n8.Ui)(s,i||void 0);e&&o(e)}},[s,i,l]);let f=e=>{o(e),e&&nT(l)&&((0,n8.Hc)(s,e,l||"none",i||void 0),eo.Z.success("Authentication token saved locally"))},v=()=>{o(""),(0,n8.e4)(s),eo.Z.info("Authentication token cleared")},{data:y,isLoading:b,error:_}=(0,sj.a)({queryKey:["mcpTools",s,n,i],queryFn:()=>{if(!t)throw Error("Access Token required");return(0,j.listMCPTools)(t,s,n,i||void 0)},enabled:!!t,staleTime:3e4}),{mutate:N,isPending:Z}=(0,n6.D)({mutationFn:async e=>{if(!t)throw Error("Access Token required");try{return await (0,j.callMCPTool)(t,e.tool.name,e.arguments,e.authValue,i||void 0)}catch(e){throw e}},onSuccess:e=>{h(e),g(null)},onError:e=>{g(e),h(null)}}),w=(null==y?void 0:y.tools)||[],k=""!==n;return(0,c.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,c.jsx)(n7.Zb,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,c.jsxs)("div",{className:"flex h-auto w-full gap-4",children:[(0,c.jsxs)("div",{className:"w-1/4 p-4 bg-gray-50 flex flex-col",children:[(0,c.jsx)(n7.Dx,{className:"text-xl font-semibold mb-6 mt-2",children:"MCP Tools"}),(0,c.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,c.jsxs)("div",{className:"flex flex-col flex-1 min-h-0",children:[(0,c.jsxs)(n7.xv,{className:"font-medium block mb-3 text-gray-700 flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2"})," Available Tools",w.length>0&&(0,c.jsx)("span",{className:"ml-2 bg-blue-100 text-blue-800 text-xs font-medium px-2 py-0.5 rounded-full",children:w.length})]}),b&&(0,c.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 bg-white border border-gray-200 rounded-lg",children:[(0,c.jsxs)("div",{className:"relative mb-3",children:[(0,c.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-gray-200"}),(0,c.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-600 border-t-transparent absolute top-0"})]}),(0,c.jsx)("p",{className:"text-xs font-medium text-gray-700",children:"Loading tools..."})]}),(null==y?void 0:y.error)&&!b&&!w.length&&(0,c.jsx)("div",{className:"p-3 text-xs text-red-800 rounded-lg bg-red-50 border border-red-200",children:(0,c.jsxs)("p",{className:"font-medium",children:["Error: ",y.message]})}),!b&&!(null==y?void 0:y.error)&&(!w||0===w.length)&&(0,c.jsxs)("div",{className:"p-4 text-center bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"mx-auto w-8 h-8 bg-gray-200 rounded-full flex items-center justify-center mb-2",children:(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 8.172V5L8 4z"})})}),(0,c.jsx)("p",{className:"text-xs font-medium text-gray-700 mb-1",children:"No tools available"}),(0,c.jsx)("p",{className:"text-xs text-gray-500",children:"No tools found for this server"})]}),!b&&!(null==y?void 0:y.error)&&w.length>0&&(0,c.jsx)("div",{className:"space-y-2 flex-1 overflow-y-auto min-h-0 mcp-tools-scrollable",style:{maxHeight:"400px",scrollbarWidth:"auto",scrollbarColor:"#cbd5e0 #f7fafc"},children:w.map(e=>(0,c.jsxs)("div",{className:"border rounded-lg p-3 cursor-pointer transition-all hover:shadow-sm ".concat((null==m?void 0:m.name)===e.name?"border-blue-500 bg-blue-50 ring-1 ring-blue-200":"border-gray-200 bg-white hover:border-gray-300"),onClick:()=>{u(e),h(null),g(null)},children:[(0,c.jsxs)("div",{className:"flex items-start space-x-2",children:[e.mcp_info.logo_url&&(0,c.jsx)("img",{src:e.mcp_info.logo_url,alt:"".concat(e.mcp_info.server_name," logo"),className:"w-4 h-4 object-contain flex-shrink-0 mt-0.5"}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("h4",{className:"font-mono text-xs font-medium text-gray-900 truncate",children:e.name}),(0,c.jsx)("p",{className:"text-xs text-gray-500 truncate",children:e.mcp_info.server_name}),(0,c.jsx)("p",{className:"text-xs text-gray-600 mt-1 line-clamp-2 leading-relaxed",children:e.description})]})]}),(null==m?void 0:m.name)===e.name&&(0,c.jsx)("div",{className:"mt-2 pt-2 border-t border-blue-200",children:(0,c.jsxs)("div",{className:"flex items-center text-xs font-medium text-blue-700",children:[(0,c.jsx)("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,c.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),"Selected"]})})]},e.name))})]}),nT(l)&&(0,c.jsx)("div",{className:"pt-4 border-t border-gray-200 flex-shrink-0 mt-6",children:k?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(n7.xv,{className:"font-medium block mb-3 text-gray-700 flex items-center",children:[(0,c.jsx)(rX.Z,{className:"mr-2"})," Authentication"]}),(0,c.jsx)(oe,{authType:l,onAuthSubmit:f,onClearAuth:v,hasAuth:k})]}):(0,c.jsxs)("div",{className:"p-4 bg-gradient-to-r from-orange-50 to-red-50 border border-orange-200 rounded-lg",children:[(0,c.jsxs)("div",{className:"flex items-center mb-3",children:[(0,c.jsx)(rX.Z,{className:"mr-2 text-orange-600 text-lg"}),(0,c.jsx)(n7.xv,{className:"font-semibold text-orange-800",children:"Authentication Required"})]}),(0,c.jsx)(n7.xv,{className:"text-sm text-orange-700 mb-4",children:"This MCP server requires authentication. You must add your credentials below to access the tools."}),(0,c.jsx)(oe,{authType:l,onAuthSubmit:f,onClearAuth:v,hasAuth:k})]})})]})]}),(0,c.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,c.jsx)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:(0,c.jsx)(n7.Dx,{className:"text-xl font-semibold mb-0",children:"Tool Testing Playground"})}),(0,c.jsx)("div",{className:"flex-1 overflow-auto p-4",children:m?(0,c.jsx)("div",{className:"h-full",children:(0,c.jsx)(n3,{tool:m,needsAuth:nT(l),authValue:n,onSubmit:e=>{N({tool:m,arguments:e,authValue:n})},result:x,error:p,isLoading:Z,onClose:()=>u(null)})}):(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(ez.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(n7.xv,{className:"text-lg font-medium text-gray-600 mb-2",children:"Select a Tool to Test"}),(0,c.jsx)(n7.xv,{className:"text-center text-gray-500 max-w-md",children:"Choose a tool from the left sidebar to start testing its functionality with custom inputs."})]})})]})]})})})},ot=t(57018),ol=e=>{let{tagId:s,onClose:t,accessToken:l,is_admin:a,editTag:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(r),[x,h]=(0,d.useState)([]),p=async()=>{if(l)try{let e=(await (0,j.tagInfoCall)(l,[s]))[s];e&&(o(e),r&&i.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),eo.Z.fromBackend("Error fetching tag details: "+e)}};(0,d.useEffect)(()=>{p()},[s,l]),(0,d.useEffect)(()=>{l&&eH("dummy-user","Admin",l,h)},[l]);let g=async e=>{if(l)try{await (0,j.tagUpdateCall)(l,{name:e.name,description:e.description,models:e.models}),eo.Z.success("Tag updated successfully"),u(!1),p()}catch(e){console.error("Error updating tag:",e),eo.Z.fromBackend("Error updating tag: "+e)}};return n?(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.zx,{onClick:t,className:"mb-4",children:"← Back to Tags"}),(0,c.jsxs)(ot.Dx,{children:["Tag Name: ",n.name]}),(0,c.jsx)(ot.xv,{className:"text-gray-500",children:n.description||"No description"})]}),a&&!m&&(0,c.jsx)(ot.zx,{onClick:()=>u(!0),children:"Edit Tag"})]}),m?(0,c.jsx)(ot.Zb,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:g,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed LLMs"," ",(0,c.jsx)(V.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select LLMs",children:x.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(ot.zx,{onClick:()=>u(!1),children:"Cancel"}),(0,c.jsx)(ot.zx,{type:"submit",children:"Save Changes"})]})]})}):(0,c.jsx)("div",{className:"space-y-6",children:(0,c.jsxs)(ot.Zb,{children:[(0,c.jsx)(ot.Dx,{children:"Tag Details"}),(0,c.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Name"}),(0,c.jsx)(ot.xv,{children:n.name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Description"}),(0,c.jsx)(ot.xv,{children:n.description||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Allowed LLMs"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===n.models.length?(0,c.jsx)(ot.Ct,{color:"red",children:"All Models"}):n.models.map(e=>{var s;return(0,c.jsx)(ot.Ct,{color:"blue",children:(0,c.jsx)(V.Z,{title:"ID: ".concat(e),children:(null===(s=n.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Created"}),(0,c.jsx)(ot.xv,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(ot.xv,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,c.jsx)("div",{children:"Loading..."})},oa=e=>{let{data:s,onEdit:t,onDelete:l,onSelectTag:a}=e,[r,i]=d.useState([{id:"created_at",desc:!0}]),n=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:t.name,children:(0,c.jsx)(b.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",onClick:()=>a(t.name),children:t.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.description,children:(0,c.jsx)("span",{className:"text-xs",children:t.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,t;let{row:l}=e,a=l.original;return(0,c.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(t=a.models)||void 0===t?void 0:t.map(e=>{var s;return(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,c.jsx)(V.Z,{title:"ID: ".concat(e),children:(0,c.jsx)(k.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>t(a),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(a.name),className:"cursor-pointer"})]})}}],o=(0,s_.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No tags found"})})})})})]})})})},or=e=>{let{accessToken:s,userID:t,userRole:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(null),[N,Z]=(0,d.useState)(""),[w]=A.Z.useForm(),[S,C]=(0,d.useState)([]),T=async()=>{if(s)try{let e=await (0,j.tagListCall)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),eo.Z.fromBackend("Error fetching tags: "+e)}},P=async e=>{if(s)try{await (0,j.tagCreateCall)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),eo.Z.success("Tag created successfully"),n(!1),w.resetFields(),T()}catch(e){console.error("Error creating tag:",e),eo.Z.fromBackend("Error creating tag: "+e)}},M=async e=>{f(e),p(!0)},O=async()=>{if(s&&g){try{await (0,j.tagDeleteCall)(s,g),eo.Z.success("Tag deleted successfully"),T()}catch(e){console.error("Error deleting tag:",e),eo.Z.fromBackend("Error deleting tag: "+e)}p(!1),f(null)}};return(0,d.useEffect)(()=>{t&&l&&s&&(async()=>{try{let e=await (0,j.modelInfoCall)(s,t,l);e&&e.data&&C(e.data)}catch(e){console.error("Error fetching models:",e),eo.Z.fromBackend("Error fetching models: "+e)}})()},[s,t,l]),(0,d.useEffect)(()=>{T()},[s]),(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,c.jsx)(ol,{tagId:o,onClose:()=>{m(null),x(!1)},accessToken:s,is_admin:"Admin"===l,editTag:u}):(0,c.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,c.jsx)("h1",{children:"Tag Management"}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[N&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",N]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{T(),Z(new Date().toLocaleString())}})]})]}),(0,c.jsxs)(k.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,c.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,c.jsx)(b.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create New Tag"}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(oa,{data:a,onEdit:e=>{m(e.name),x(!0)},onDelete:M,onSelectTag:m})})}),(0,c.jsx)(L.Z,{title:"Create New Tag",visible:i,width:800,footer:null,onCancel:()=>{n(!1),w.resetFields()},children:(0,c.jsxs)(A.Z,{form:w,onFinish:P,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Models"," ",(0,c.jsx)(V.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select LLMs",children:S.map(e=>(0,c.jsx)(I.default.Option,{value:e.model_info.id,children:(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{children:e.model_name}),(0,c.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(b.Z,{type:"submit",children:"Create Tag"})})]})}),h&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:O,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{p(!1),f(null)},children:"Cancel"})]})]})]})})]})})},oi=e=>{let{data:s,onView:t,onEdit:l,onDelete:a}=e,[r,i]=d.useState([{id:"created_at",desc:!0}]),n=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,c.jsx)("button",{onClick:()=>t(l.vector_store_id),className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",children:l.vector_store_id.length>15?"".concat(l.vector_store_id.slice(0,15),"..."):l.vector_store_id})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.vector_store_name,children:(0,c.jsx)("span",{className:"text-xs",children:t.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.vector_store_description,children:(0,c.jsx)("span",{className:"text-xs",children:t.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,t=s.original,{displayName:l,logo:a}=(0,sU.dr)(t.custom_llm_provider);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[a&&(0,c.jsx)("img",{src:a,alt:l,className:"h-4 w-4"}),(0,c.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.created_at).toLocaleDateString()})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.updated_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>a(t.vector_store_id),className:"cursor-pointer"})]})}}],o=(0,s_.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No vector stores found"})})})})})]})})})};(r=o||(o={})).Bedrock="Amazon Bedrock",r.PgVector="PostgreSQL pgvector (LiteLLM Connector)",r.VertexRagEngine="Vertex AI RAG Engine",r.OpenAI="OpenAI",r.Azure="Azure OpenAI";let on={Bedrock:"bedrock",PgVector:"pg_vector",VertexRagEngine:"vertex_ai",OpenAI:"openai",Azure:"azure"},oo="/ui/assets/logos/",oc={"Amazon Bedrock":"".concat(oo,"bedrock.svg"),"PostgreSQL pgvector (LiteLLM Connector)":"".concat(oo,"postgresql.svg"),"Vertex AI RAG Engine":"".concat(oo,"google.svg"),OpenAI:"".concat(oo,"openai_small.svg"),"Azure OpenAI":"".concat(oo,"microsoft_azure.svg")},od={bedrock:[],pg_vector:[{name:"api_base",label:"API Base",tooltip:"Enter the base URL of your deployed litellm-pgvector server (e.g., http://your-server:8000)",placeholder:"http://your-deployed-server:8000",required:!0,type:"text"},{name:"api_key",label:"API Key",tooltip:"Enter the API key from your deployed litellm-pgvector server",placeholder:"your-deployed-api-key",required:!0,type:"password"}],vertex_rag_engine:[],openai:[{name:"api_key",label:"API Key",tooltip:"Enter your OpenAI API key",placeholder:"sk-...",required:!0,type:"password"}],azure:[{name:"api_key",label:"API Key",tooltip:"Enter your Azure OpenAI API key",placeholder:"your-azure-api-key",required:!0,type:"password"},{name:"api_base",label:"API Base",tooltip:"Enter your Azure OpenAI endpoint (e.g., https://your-resource.openai.azure.com/)",placeholder:"https://your-resource.openai.azure.com/",required:!0,type:"text"}]},om=e=>od[e]||[];var ou=e=>{let{isVisible:s,onCancel:t,onSuccess:l,accessToken:a,credentials:r}=e,[i]=A.Z.useForm(),[n,m]=(0,d.useState)("{}"),[u,x]=(0,d.useState)("bedrock"),h=async e=>{if(a)try{let s={};try{s=n.trim()?JSON.parse(n):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t={vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name},r=om(e.custom_llm_provider).reduce((s,t)=>(s[t.name]=e[t.name],s),{});t.litellm_params=r,await (0,j.vectorStoreCreateCall)(a,t),eo.Z.success("Vector store created successfully"),i.resetFields(),m("{}"),l()}catch(e){console.error("Error creating vector store:",e),eo.Z.fromBackend("Error creating vector store: "+e)}},p=()=>{i.resetFields(),m("{}"),x("bedrock"),t()};return(0,c.jsx)(L.Z,{title:"Add New Vector Store",visible:s,width:1e3,footer:null,onCancel:p,children:(0,c.jsxs)(A.Z,{form:i,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Provider"," ",(0,c.jsx)(V.Z,{title:"Select the provider for this vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,c.jsx)(I.default,{onChange:e=>x(e),children:Object.entries(o).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:on[s],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:oc[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),"pg_vector"===u&&(0,c.jsx)(ls.Z,{message:"PG Vector Setup Required",description:(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"LiteLLM provides a server to connect to PG Vector. To use this provider:"}),(0,c.jsxs)("ol",{style:{marginLeft:"16px",marginTop:"8px"},children:[(0,c.jsxs)("li",{children:["Deploy the litellm-pgvector server from: ",(0,c.jsx)("a",{href:"https://github.com/BerriAI/litellm-pgvector",target:"_blank",rel:"noopener noreferrer",children:"https://github.com/BerriAI/litellm-pgvector"})]}),(0,c.jsx)("li",{children:"Configure your PostgreSQL database with pgvector extension"}),(0,c.jsx)("li",{children:"Start the server and note the API base URL and API key"}),(0,c.jsx)("li",{children:"Enter those details in the fields below"})]})]}),type:"info",showIcon:!0,style:{marginBottom:"16px"}}),"vertex_rag_engine"===u&&(0,c.jsx)(ls.Z,{message:"Vertex AI RAG Engine Setup",description:(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"To use Vertex AI RAG Engine:"}),(0,c.jsxs)("ol",{style:{marginLeft:"16px",marginTop:"8px"},children:[(0,c.jsxs)("li",{children:["Set up your Vertex AI RAG Engine corpus following the guide: ",(0,c.jsx)("a",{href:"https://cloud.google.com/vertex-ai/generative-ai/docs/rag-engine/rag-overview",target:"_blank",rel:"noopener noreferrer",children:"Vertex AI RAG Engine Overview"})]}),(0,c.jsx)("li",{children:"Create a corpus in your Google Cloud project"}),(0,c.jsx)("li",{children:"Note the corpus ID from the Vertex AI console"}),(0,c.jsx)("li",{children:"Enter the corpus ID in the Vector Store ID field below"})]})]}),type:"info",showIcon:!0,style:{marginBottom:"16px"}}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Vector Store ID"," ",(0,c.jsx)(V.Z,{title:"Enter the vector store ID from your api provider",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,c.jsx)(_.Z,{placeholder:"vertex_rag_engine"===u?"6917529027641081856 (Get corpus ID from Vertex AI console)":"Enter vector store ID from your provider"})}),om(u).map(e=>(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:[e.label," ",(0,c.jsx)(V.Z,{title:e.tooltip,children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:e.name,rules:e.required?[{required:!0,message:"Please input the ".concat(e.label.toLowerCase())}]:[],children:(0,c.jsx)(_.Z,{type:e.type||"text",placeholder:e.placeholder})},e.name)),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Vector Store Name"," ",(0,c.jsx)(V.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"vector_store_description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Existing Credentials"," ",(0,c.jsx)(V.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON metadata for the vector store (optional)",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),children:(0,c.jsx)(E.default.TextArea,{rows:4,value:n,onChange:e=>m(e.target.value),placeholder:'{"key": "value"}'})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,c.jsx)(b.Z,{onClick:p,variant:"secondary",children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},ox=e=>{let{isVisible:s,onCancel:t,onConfirm:l}=e;return(0,c.jsxs)(L.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:t,children:[(0,c.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,c.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:l,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:t,variant:"primary",children:"Cancel"})]})]})},oh=t(23907);let{TextArea:op}=E.default,{Text:og,Title:oj}=en.default;var of=e=>{let{vectorStoreId:s,accessToken:t,className:l=""}=e,[a,r]=(0,d.useState)(""),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)({}),h=async()=>{if(!a.trim()){tc.ZP.warning("Please enter a search query");return}n(!0);try{let e=await (0,j.vectorStoreSearchCall)(t,s,a),l={query:a,response:e,timestamp:Date.now()};m(e=>[l,...e]),r("")}catch(e){console.error("Error searching vector store:",e),eo.Z.fromBackend("Failed to search vector store")}finally{n(!1)}},p=e=>new Date(e).toLocaleString(),g=(e,s)=>{let t="".concat(e,"-").concat(s);x(e=>({...e,[t]:!e[t]}))};return(0,c.jsx)(tN.Z,{className:"w-full rounded-xl shadow-md",children:(0,c.jsxs)("div",{className:"flex flex-col h-[600px]",children:[(0,c.jsxs)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rQ.Z,{className:"mr-2 text-blue-500"}),(0,c.jsx)(oj,{level:4,className:"mb-0",children:"Test Vector Store"})]}),o.length>0&&(0,c.jsx)(P.ZP,{onClick:()=>{m([]),x({}),eo.Z.success("Search history cleared")},size:"small",children:"Clear History"})]}),(0,c.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===o.length?(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(rQ.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(og,{children:"Test your vector store by entering a search query below"})]}):(0,c.jsx)("div",{className:"space-y-4",children:o.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("div",{className:"text-right",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3 bg-blue-50 border border-blue-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,c.jsx)("strong",{className:"text-sm",children:"Query"}),(0,c.jsx)("span",{className:"text-xs text-gray-500",children:p(e.timestamp)})]}),(0,c.jsx)("div",{className:"text-left",children:e.query})]})}),(0,c.jsx)("div",{className:"text-left",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3 bg-white border border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(rQ.Z,{className:"text-green-500"}),(0,c.jsx)("strong",{className:"text-sm",children:"Vector Store Results"}),e.response&&(0,c.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600",children:[(null===(t=e.response.data)||void 0===t?void 0:t.length)||0," results"]})]}),e.response&&e.response.data&&e.response.data.length>0?(0,c.jsx)("div",{className:"space-y-3",children:e.response.data.map((e,t)=>{let l=u["".concat(s,"-").concat(t)]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 cursor-pointer hover:bg-gray-100 transition-colors",onClick:()=>g(s,t),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[l?(0,c.jsx)(tZ.Z,{className:"text-gray-500 mr-2"}):(0,c.jsx)(la.Z,{className:"text-gray-500 mr-2"}),(0,c.jsxs)("span",{className:"font-medium text-sm",children:["Result ",t+1]}),!l&&e.content&&e.content[0]&&(0,c.jsxs)("span",{className:"ml-2 text-xs text-gray-500 truncate max-w-md",children:["- ",e.content[0].text.substring(0,100),"..."]})]}),(0,c.jsxs)("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded",children:["Score: ",e.score.toFixed(4)]})]}),l&&(0,c.jsxs)("div",{className:"border-t bg-white p-3",children:[e.content&&e.content.map((e,s)=>(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsxs)("div",{className:"text-xs text-gray-500 mb-1",children:["Content (",e.type,")"]}),(0,c.jsx)("div",{className:"text-sm bg-gray-50 p-3 rounded border text-gray-800 max-h-40 overflow-y-auto",children:e.text})]},s)),(e.file_id||e.filename||e.attributes)&&(0,c.jsxs)("div",{className:"mt-3 pt-3 border-t border-gray-200",children:[(0,c.jsx)("div",{className:"text-xs text-gray-500 mb-2 font-medium",children:"Metadata"}),(0,c.jsxs)("div",{className:"space-y-2 text-xs",children:[e.file_id&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium",children:"File ID:"})," ",e.file_id]}),e.filename&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium",children:"Filename:"})," ",e.filename]}),e.attributes&&Object.keys(e.attributes).length>0&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium block mb-1",children:"Attributes:"}),(0,c.jsx)("pre",{className:"text-xs bg-white p-2 rounded border overflow-x-auto",children:JSON.stringify(e.attributes,null,2)})]})]})]})]})]},t)})}):(0,c.jsx)("div",{className:"text-gray-500 text-sm",children:"No results found"})]})}),sr(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),h())},placeholder:"Enter your search query... (Shift+Enter for new line)",disabled:i,autoSize:{minRows:1,maxRows:4},style:{resize:"none"}})}),(0,c.jsx)(P.ZP,{type:"primary",onClick:h,disabled:i||!a.trim(),icon:(0,c.jsx)(oh.Z,{}),loading:i,children:"Search"})]})})]})})},ov=e=>{let{vectorStoreId:s,onClose:t,accessToken:l,is_admin:a,editVectorStore:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(r),[x,h]=(0,d.useState)("{}"),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)("details"),y=async()=>{if(l)try{let e=await (0,j.vectorStoreInfoCall)(l,s);if(e&&e.vector_store){if(o(e.vector_store),e.vector_store.vector_store_metadata){let s="string"==typeof e.vector_store.vector_store_metadata?JSON.parse(e.vector_store.vector_store_metadata):e.vector_store.vector_store_metadata;h(JSON.stringify(s,null,2))}r&&i.setFieldsValue({vector_store_id:e.vector_store.vector_store_id,custom_llm_provider:e.vector_store.custom_llm_provider,vector_store_name:e.vector_store.vector_store_name,vector_store_description:e.vector_store.vector_store_description})}}catch(e){console.error("Error fetching vector store details:",e),eo.Z.fromBackend("Error fetching vector store details: "+e)}},_=async()=>{if(l)try{let e=await (0,j.credentialListCall)(l);console.log("List credentials response:",e),g(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e)}};(0,d.useEffect)(()=>{y(),_()},[s,l]);let N=async e=>{if(l)try{let s={};try{s=x?JSON.parse(x):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t={vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s};await (0,j.vectorStoreUpdateCall)(l,t),eo.Z.success("Vector store updated successfully"),u(!1),y()}catch(e){console.error("Error updating vector store:",e),eo.Z.fromBackend("Error updating vector store: "+e)}};return n?(0,c.jsxs)("div",{className:"p-4 max-w-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",className:"mb-4",onClick:t,children:"Back to Vector Stores"}),(0,c.jsxs)(S.Z,{children:["Vector Store ID: ",n.vector_store_id]}),(0,c.jsx)(k.Z,{className:"text-gray-500",children:n.vector_store_description||"No description"})]}),a&&!m&&(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Vector Store"})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"Details"}),(0,c.jsx)(e0.Z,{children:"Test Vector Store"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:m?(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(S.Z,{children:"Edit Vector Store"})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:N,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{label:"Vector Store ID",name:"vector_store_id",rules:[{required:!0,message:"Please input a vector store ID"}],children:(0,c.jsx)(E.default,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{label:"Vector Store Name",name:"vector_store_name",children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"vector_store_description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Provider"," ",(0,c.jsx)(V.Z,{title:"Select the provider for this vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return"Bedrock"===s?(0,c.jsx)(I.default.Option,{value:sU.fK[s],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s):null})})}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(k.Z,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter provider credentials below"})}),(0,c.jsx)(A.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON metadata for the vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),children:(0,c.jsx)(E.default.TextArea,{rows:4,value:x,onChange:e=>h(e.target.value),placeholder:'{"key": "value"}'})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:()=>u(!1),children:"Cancel"}),(0,c.jsx)(P.ZP,{type:"primary",htmlType:"submit",children:"Save Changes"})]})]})})]}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Vector Store Details"}),a&&(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Vector Store"})]}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"ID"}),(0,c.jsx)(k.Z,{children:n.vector_store_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Name"}),(0,c.jsx)(k.Z,{children:n.vector_store_name||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Description"}),(0,c.jsx)(k.Z,{children:n.vector_store_description||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Provider"}),(0,c.jsx)("div",{className:"flex items-center space-x-2 mt-1",children:(()=>{let e=n.custom_llm_provider||"bedrock",{displayName:s,logo:t}=(()=>{let s=Object.keys(sU.fK).find(s=>sU.fK[s].toLowerCase()===e.toLowerCase());if(!s)return{displayName:e,logo:""};let t=sU.Cl[s],l=sU.cd[t];return{displayName:t,logo:l}})();return(0,c.jsxs)(c.Fragment,{children:[t&&(0,c.jsx)("img",{src:t,alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let t=e.target,l=t.parentElement;if(l){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),l.replaceChild(e,t)}}}),(0,c.jsx)(eX.Z,{color:"blue",children:s})]})})()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("div",{className:"bg-gray-50 p-3 rounded mt-2 font-mono text-xs overflow-auto max-h-48",children:(0,c.jsx)("pre",{children:x})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(k.Z,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(of,{vectorStoreId:n.vector_store_id,accessToken:l||""})})]})]})]}):(0,c.jsx)("div",{children:"Loading..."})},oy=e=>{let{accessToken:s,userID:t,userRole:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(null),[h,p]=(0,d.useState)(""),[g,f]=(0,d.useState)([]),[_,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(!1),S=async()=>{if(s)try{let e=await (0,j.vectorStoreListCall)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),eo.Z.fromBackend("Error fetching vector stores: "+e)}},C=async()=>{if(s)try{let e=await (0,j.credentialListCall)(s);console.log("List credentials response:",e),f(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),eo.Z.fromBackend("Error fetching credentials: "+e)}},I=async e=>{x(e),m(!0)},A=async()=>{if(s&&u){try{await (0,j.vectorStoreDeleteCall)(s,u),eo.Z.success("Vector store deleted successfully"),S()}catch(e){console.error("Error deleting vector store:",e),eo.Z.fromBackend("Error deleting vector store: "+e)}m(!1),x(null)}};return(0,d.useEffect)(()=>{S(),C()},[s]),_?(0,c.jsx)("div",{className:"w-full h-full",children:(0,c.jsx)(ov,{vectorStoreId:_,onClose:()=>{N(null),w(!1),S()},accessToken:s,is_admin:(0,eI.tY)(l||""),editVectorStore:Z})}):(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,c.jsx)("h1",{children:"Vector Store Management"}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[h&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",h]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{S(),C(),p(new Date().toLocaleString())}})]})]}),(0,c.jsx)(k.Z,{className:"mb-4",children:(0,c.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings.."})}),(0,c.jsx)(b.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Add Vector Store"}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(oi,{data:a,onView:e=>{N(e),w(!1)},onEdit:e=>{N(e),w(!0)},onDelete:I})})}),(0,c.jsx)(ou,{isVisible:i,onCancel:()=>n(!1),onSuccess:()=>{n(!1),S()},accessToken:s,credentials:g}),(0,c.jsx)(ox,{isVisible:o,onCancel:()=>m(!1),onConfirm:A})]})})},ob=e=>{let{userID:s,userRole:t,accessToken:l}=e,{logoUrl:a,setLogoUrl:r}=(0,g.F)(),[i,n]=(0,d.useState)(""),[o,m]=(0,d.useState)(!1);(0,d.useEffect)(()=>{l&&u()},[l]);let u=async()=>{try{let s=(0,j.getProxyBaseUrl)(),t=await fetch(s?"".concat(s,"/get/ui_theme_settings"):"/get/ui_theme_settings",{method:"GET",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(t.ok){var e;let s=await t.json(),l=(null===(e=s.values)||void 0===e?void 0:e.logo_url)||"";n(l),r(l||null)}}catch(e){console.error("Error fetching theme settings:",e)}},x=async()=>{m(!0);try{let e=(0,j.getProxyBaseUrl)();if((await fetch(e?"".concat(e,"/update/ui_theme_settings"):"/update/ui_theme_settings",{method:"PATCH",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({logo_url:i||null})})).ok)eo.Z.success("Logo settings updated successfully!"),r(i||null);else throw Error("Failed to update settings")}catch(e){console.error("Error updating logo settings:",e),eo.Z.fromBackend("Failed to update logo settings")}finally{m(!1)}},h=async()=>{n(""),r(null),m(!0);try{let e=(0,j.getProxyBaseUrl)();if((await fetch(e?"".concat(e,"/update/ui_theme_settings"):"/update/ui_theme_settings",{method:"PATCH",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({logo_url:null})})).ok)eo.Z.success("Logo reset to default!");else throw Error("Failed to reset logo")}catch(e){console.error("Error resetting logo:",e),eo.Z.fromBackend("Failed to reset logo")}finally{m(!1)}};return l?(0,c.jsxs)("div",{className:"w-full mx-auto max-w-4xl px-6 py-8",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"text-2xl font-bold mb-2",children:"Logo Customization"}),(0,c.jsx)(k.Z,{className:"text-gray-600",children:"Customize your LiteLLM admin dashboard with a custom logo."})]}),(0,c.jsx)(G.Z,{className:"shadow-sm p-6",children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium text-gray-700 mb-2 block",children:"Custom Logo URL"}),(0,c.jsx)(_.Z,{placeholder:"https://example.com/logo.png",value:i,onValueChange:e=>{n(e),r(e||null)},className:"w-full"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500 mt-1",children:"Enter a URL for your custom logo or leave empty to use the default LiteLLM logo"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium text-gray-700 mb-2 block",children:"Current Logo"}),(0,c.jsx)("div",{className:"bg-gray-50 rounded-lg p-6 flex items-center justify-center min-h-[120px]",children:i?(0,c.jsx)("img",{src:i,alt:"Custom logo",className:"max-w-full max-h-24 object-contain",onError:e=>{var s;let t=e.target;t.style.display="none";let l=document.createElement("div");l.className="text-gray-500 text-sm",l.textContent="Failed to load image",null===(s=t.parentElement)||void 0===s||s.appendChild(l)}}):(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"Default LiteLLM logo will be used"})})]}),(0,c.jsxs)("div",{className:"flex gap-3 pt-4",children:[(0,c.jsx)(b.Z,{onClick:x,loading:o,disabled:o,color:"indigo",children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:h,loading:o,disabled:o,variant:"secondary",color:"gray",children:"Reset to Default"})]})]})})]}):null};let o_=new x.S;function oN(){return(0,c.jsxs)("div",{className:re("h-screen","flex items-center justify-center gap-4"),children:[(0,c.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,c.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,c.jsx)(rt,{className:"size-4"}),(0,c.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function oZ(){let[e,s]=(0,d.useState)(""),[t,l]=(0,d.useState)(!1),[a,r]=(0,d.useState)(!1),[i,n]=(0,d.useState)(null),[o,x]=(0,d.useState)(null),[v,y]=(0,d.useState)([]),[b,_]=(0,d.useState)([]),[N,Z]=(0,d.useState)([]),[w,k]=(0,d.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,C]=(0,d.useState)(!0),I=(0,m.useSearchParams)(),[A,L]=(0,d.useState)({data:[]}),[T,P]=(0,d.useState)(null),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)(!0),[F,R]=(0,d.useState)(null),z=I.get("invitation_id"),[U,q]=(0,d.useState)(()=>I.get("page")||"api-keys"),[B,V]=(0,d.useState)(null),[K,G]=(0,d.useState)(!1),H=e=>{y(s=>s?[...s,e]:[e]),M(()=>!E)},J=!1===O&&null===T&&null===z;return((0,d.useEffect)(()=>{let e=function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token");(0,j.getUiConfig)().then(s=>{P(e),D(!1)})},[]),(0,d.useEffect)(()=>{J&&(window.location.href=(j.proxyBaseUrl||"")+"/sso/key/generate")},[J]),(0,d.useEffect)(()=>{if(!T)return;let e=(0,u.o)(T);if(e){if(V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let t=function(e){if(!e)return"Undefined Role";switch(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_user_viewer":case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);s(t),"Admin Viewer"==t&&q("usage")}e.user_email&&n(e.user_email),e.login_method&&C("username_password"==e.login_method),e.premium_user&&l(e.premium_user),e.auth_header_name&&(0,j.setGlobalLitellmHeaderName)(e.auth_header_name),e.user_id&&R(e.user_id)}},[T]),(0,d.useEffect)(()=>{B&&F&&e&&eH(F,e,B,Z),B&&F&&e&&f(B,F,e,null,x),B&&lU(B,_)},[B,F,e]),O||J)?(0,c.jsx)(oN,{}):(0,c.jsx)(d.Suspense,{fallback:(0,c.jsx)(oN,{}),children:(0,c.jsx)(h.aH,{client:o_,children:(0,c.jsx)(g.f,{accessToken:B,children:z?(0,c.jsx)(sR,{userID:F,userRole:e,premiumUser:t,teams:o,keys:v,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:x,setKeys:y,organizations:b,addKey:H,createClicked:E}):(0,c.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,c.jsx)(p.Z,{userID:F,userRole:e,premiumUser:t,userEmail:i,setProxySettings:k,proxySettings:w,accessToken:B,isPublicPage:!1,sidebarCollapsed:K,onToggleSidebar:()=>{G(!K)}}),(0,c.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(ib,{accessToken:B,setPage:e=>{let s=new URLSearchParams(I);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),q(e)},userRole:e,defaultSelectedKey:U,collapsed:K})}),"api-keys"==U?(0,c.jsx)(sR,{userID:F,userRole:e,premiumUser:t,teams:o,keys:v,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:x,setKeys:y,organizations:b,addKey:H,createClicked:E}):"models"==U?(0,c.jsx)(lf,{userID:F,userRole:e,token:T,keys:v,accessToken:B,modelData:A,setModelData:L,premiumUser:t,teams:o}):"llm-playground"==U?(0,c.jsx)(r8,{userID:F,userRole:e,token:T,accessToken:B,disabledPersonalKeyCreation:a}):"users"==U?(0,c.jsx)(lP,{userID:F,userRole:e,token:T,keys:v,teams:o,accessToken:B,setKeys:y}):"teams"==U?(0,c.jsx)(lR,{teams:o,setTeams:x,searchParams:I,accessToken:B,userID:F,userRole:e,organizations:b,premiumUser:t}):"organizations"==U?(0,c.jsx)(lq,{organizations:b,setOrganizations:_,userModels:N,accessToken:B,userRole:e,premiumUser:t}):"admin-panel"==U?(0,c.jsx)(l0,{setTeams:x,searchParams:I,accessToken:B,userID:F,showSSOBanner:S,premiumUser:t,proxySettings:w}):"api_ref"==U?(0,c.jsx)(ro,{proxySettings:w}):"settings"==U?(0,c.jsx)(ae,{userID:F,userRole:e,accessToken:B,premiumUser:t}):"budgets"==U?(0,c.jsx)(au,{accessToken:B}):"guardrails"==U?(0,c.jsx)(nx,{accessToken:B,userRole:e}):"prompts"==U?(0,c.jsx)(nf,{accessToken:B,userRole:e}):"transform-request"==U?(0,c.jsx)(nv,{accessToken:B}):"general-settings"==U?(0,c.jsx)(ao,{userID:F,userRole:e,accessToken:B,modelData:A}):"ui-theme"==U?(0,c.jsx)(ob,{userID:F,userRole:e,accessToken:B}):"model-hub-table"==U?(0,c.jsx)(aB.Z,{accessToken:B,publicPage:!1,premiumUser:t,userRole:e}):"caching"==U?(0,c.jsx)(iM,{userID:F,userRole:e,token:T,accessToken:B,premiumUser:t}):"pass-through-settings"==U?(0,c.jsx)(lp,{userID:F,userRole:e,accessToken:B,modelData:A}):"logs"==U?(0,c.jsx)(aU,{userID:F,userRole:e,token:T,accessToken:B,allTeams:null!=o?o:[],premiumUser:t}):"mcp-servers"==U?(0,c.jsx)(n5,{accessToken:B,userRole:e,userID:F}):"tag-management"==U?(0,c.jsx)(or,{accessToken:B,userRole:e,userID:F}):"vector-stores"==U?(0,c.jsx)(oy,{accessToken:B,userRole:e,userID:F}):"new_usage"==U?(0,c.jsx)(rn,{userID:F,userRole:e,accessToken:B,teams:null!=o?o:[],premiumUser:t}):(0,c.jsx)(ik,{userID:F,userRole:e,token:T,accessToken:B,keys:v,premiumUser:t})]})]})})})})}}},function(e){e.O(0,[665,990,50,521,866,220,154,162,172,971,117,744],function(){return e(e.s=31283)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-bb7f38c1ba8189cf.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-bb7f38c1ba8189cf.js deleted file mode 100644 index 501bf35550..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-bb7f38c1ba8189cf.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{36362:function(e,s,t){Promise.resolve().then(t.bind(t,85617))},12011:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return y}});var l=t(57437),a=t(2265),r=t(99376),i=t(20831),n=t(94789),o=t(12514),c=t(49804),d=t(67101),m=t(84264),u=t(49566),x=t(96761),h=t(84566),p=t(19250),g=t(14474),j=t(13634),f=t(73002),v=t(3914);function y(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,v.e)("token");let t=s.get("invitation_id"),y=s.get("action"),[b,_]=(0,a.useState)(null),[N,Z]=(0,a.useState)(""),[w,k]=(0,a.useState)(""),[S,C]=(0,a.useState)(null),[I,A]=(0,a.useState)(""),[L,T]=(0,a.useState)(""),[P,E]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{(0,p.getUiConfig)().then(e=>{console.log("ui config in onboarding.tsx:",e),E(!1)})},[]),(0,a.useEffect)(()=>{t&&!P&&(0,p.getOnboardingCredentials)(t).then(e=>{let s=e.login_url;console.log("login_url:",s),A(s);let t=e.token,l=(0,g.o)(t);T(t),console.log("decoded:",l),_(l.key),console.log("decoded user email:",l.user_email),k(l.user_email),C(l.user_id)})},[t,P]),(0,l.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,l.jsxs)(o.Z,{children:[(0,l.jsx)(x.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,l.jsx)(x.Z,{className:"text-xl",children:"reset_password"===y?"Reset Password":"Sign up"}),(0,l.jsx)(m.Z,{children:"reset_password"===y?"Reset your password to access Admin UI.":"Claim your user account to login to Admin UI."}),"reset_password"!==y&&(0,l.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:h.GH$,color:"sky",children:(0,l.jsxs)(d.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,l.jsx)(c.Z,{children:"SSO is under the Enterprise Tier."}),(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:",b,"token:",L,"formValues:",e),b&&L&&(e.user_email=w,S&&t&&(0,p.claimOnboardingToken)(b,t,S,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+L,console.log("redirecting to:",s);let t=(0,p.getProxyBaseUrl)();console.log("proxyBaseUrl:",t),t?window.location.href=t+s:window.location.href=s}))},children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,l.jsx)(u.Z,{type:"email",disabled:!0,value:w,defaultValue:w,className:"max-w-md"})}),(0,l.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"reset_password"===y?"Enter your new password":"Create a password for your account",children:(0,l.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,l.jsx)("div",{className:"mt-10",children:(0,l.jsx)(f.ZP,{htmlType:"submit",children:"reset_password"===y?"Reset Password":"Sign Up"})})]})]})})}},85617:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return oZ}});var l,a,r,i,n,o,c=t(57437),d=t(2265),m=t(99376),u=t(14474),x=t(21623),h=t(29827),p=t(65373),g=t(69734),j=t(19250);let f=async(e,s,t,l,a)=>{let r;r="Admin"!=t&&"Admin Viewer"!=t?await (0,j.teamListCall)(e,(null==l?void 0:l.organization_id)||null,s):await (0,j.teamListCall)(e,(null==l?void 0:l.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var v=t(49804),y=t(67101),b=t(20831),_=t(49566),N=t(87452),Z=t(88829),w=t(72208),k=t(84264),S=t(96761),C=t(29233),I=t(52787),A=t(13634),L=t(82680),T=t(29967),P=t(73002),E=t(64482),M=t(30150),O=e=>{let{step:s=.01,style:t={width:"100%"},placeholder:l="Enter a numerical value",min:a,max:r,onChange:i,...n}=e;return(0,c.jsx)(M.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:t,placeholder:l,min:a,max:r,onChange:i,...n})};let D=async(e,s,t)=>{try{if(null===e||null===s)return;if(null!==t){let l=(await (0,j.modelAvailableCall)(t,e,s,!0,null,!0)).data.map(e=>e.id),a=[],r=[];return l.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},F=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},R=(e,s)=>{let t=[],l=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));l.push(...r),t.push(e)}else l.push(e)}),[...t,...l].filter((e,s,t)=>t.indexOf(e)===s)};var z=t(63610),U=e=>{let{onChange:s,value:t,className:l,accessToken:a,placeholder:r="Select vector stores",disabled:i=!1}=e,[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a){u(!0);try{let e=await (0,j.vectorStoreListCall)(a);e.data&&o(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{u(!1)}}})()},[a]),(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:r,onChange:s,value:t,loading:m,className:l,options:n.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"},disabled:i})})},q=e=>{let{teams:s,value:t,onChange:l,disabled:a}=e;return console.log("disabled",a),(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Search or select a team",value:t,onChange:l,disabled:a,filterOption:(e,t)=>{if(!t)return!1;let l=null==s?void 0:s.find(e=>e.team_id===t.key);if(!l)return!1;let a=e.toLowerCase().trim(),r=(l.team_alias||"").toLowerCase(),i=(l.team_id||"").toLowerCase();return r.includes(a)||i.includes(a)},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,c.jsxs)(I.default.Option,{value:e.team_id,children:[(0,c.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,c.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},B=t(15424),V=t(89970),K=t(23496),G=t(12514),H=t(91777),J=t(82182),Y=t(22452),W=t(74998);(l=i||(i={})).Braintrust="Braintrust",l.CustomCallbackAPI="Custom Callback API",l.Datadog="Datadog",l.Langfuse="Langfuse",l.LangfuseOtel="LangfuseOtel",l.LangSmith="LangSmith",l.Lago="Lago",l.OpenMeter="OpenMeter",l.OTel="Open Telemetry",l.S3="S3",l.Arize="Arize";let $={Braintrust:"braintrust",CustomCallbackAPI:"custom_callback_api",Datadog:"datadog",Langfuse:"langfuse",LangfuseOtel:"langfuse_otel",LangSmith:"langsmith",Lago:"lago",OpenMeter:"openmeter",OTel:"otel",S3:"s3",Arize:"arize"},Q=Object.fromEntries(Object.entries($).map(e=>{let[s,t]=e;return[t,s]})),X=e=>e.map(e=>Q[e]||e),ee=e=>e.map(e=>$[e]||e),es="/ui/assets/logos/",et={Langfuse:{logo:"".concat(es,"langfuse.png"),supports_key_team_logging:!0,dynamic_params:{langfuse_public_key:"text",langfuse_secret_key:"password",langfuse_host:"text"},description:"Langfuse v2 Logging Integration"},LangfuseOtel:{logo:"".concat(es,"langfuse.png"),supports_key_team_logging:!0,dynamic_params:{langfuse_public_key:"text",langfuse_secret_key:"password",langfuse_host:"text"},description:"Langfuse v3 OTEL Logging Integration"},Arize:{logo:"".concat(es,"arize.png"),supports_key_team_logging:!0,dynamic_params:{arize_api_key:"password",arize_space_id:"text"},description:"Arize Logging Integration"},LangSmith:{logo:"".concat(es,"langsmith.png"),supports_key_team_logging:!0,dynamic_params:{langsmith_api_key:"password",langsmith_project:"text",langsmith_base_url:"text",langsmith_sampling_rate:"number"},description:"Langsmith Logging Integration"},Braintrust:{logo:"".concat(es,"braintrust.png"),supports_key_team_logging:!1,dynamic_params:{},description:"Braintrust Logging Integration"},"Custom Callback API":{logo:"".concat(es,"custom.svg"),supports_key_team_logging:!0,dynamic_params:{},description:"Custom Callback API Logging Integration"},Datadog:{logo:"".concat(es,"datadog.png"),supports_key_team_logging:!1,dynamic_params:{},description:"Datadog Logging Integration"},Lago:{logo:"".concat(es,"lago.svg"),supports_key_team_logging:!1,dynamic_params:{},description:"Lago Billing Logging Integration"},OpenMeter:{logo:"".concat(es,"openmeter.png"),supports_key_team_logging:!1,dynamic_params:{},description:"OpenMeter Logging Integration"},"Open Telemetry":{logo:"".concat(es,"otel.png"),supports_key_team_logging:!1,dynamic_params:{},description:"OpenTelemetry Logging Integration"},S3:{logo:"".concat(es,"aws.svg"),supports_key_team_logging:!1,dynamic_params:{},description:"S3 Bucket (AWS) Logging Integration"}},{Option:el}=I.default;var ea=e=>{let{value:s=[],onChange:t,disabledCallbacks:l=[],onDisabledCallbacksChange:a}=e,r=Object.entries(et).filter(e=>{let[s,t]=e;return t.supports_key_team_logging}).map(e=>{let[s,t]=e;return s}),i=Object.keys(et),n=e=>{null==t||t(e)},o=e=>{n(s.filter((s,t)=>t!==e))},d=(e,t,l)=>{let a=[...s];if("callback_name"===t){let s=$[l]||l;a[e]={...a[e],[t]:s,callback_vars:{}}}else a[e]={...a[e],[t]:l};n(a)},m=(e,t,l)=>{let a=[...s];a[e]={...a[e],callback_vars:{...a[e].callback_vars,[t]:l}},n(a)},u=(e,s)=>{var t,l;if(!e.callback_name)return null;let a=null===(t=Object.entries($).find(s=>{let[t,l]=s;return l===e.callback_name}))||void 0===t?void 0:t[0];if(!a)return null;let r=(null===(l=et[a])||void 0===l?void 0:l.dynamic_params)||{};return 0===Object.keys(r).length?null:(0,c.jsxs)("div",{className:"mt-6 pt-4 border-t border-gray-100",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-4",children:[(0,c.jsx)("div",{className:"w-3 h-3 bg-blue-100 rounded-full flex items-center justify-center",children:(0,c.jsx)("div",{className:"w-1.5 h-1.5 bg-blue-500 rounded-full"})}),(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Integration Parameters"})]}),(0,c.jsx)("div",{className:"grid grid-cols-1 gap-4",children:Object.entries(r).map(t=>{let[l,a]=t;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("label",{className:"text-sm font-medium text-gray-700 capitalize flex items-center space-x-1",children:[(0,c.jsx)("span",{children:l.replace(/_/g," ")}),(0,c.jsx)(V.Z,{title:"Environment variable reference recommended: os.environ/".concat(l.toUpperCase()),children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help text-xs"})}),"password"===a&&(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:"Sensitive"}),"number"===a&&(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 text-yellow-800",children:"Number"})]}),"number"===a&&(0,c.jsx)("span",{className:"text-xs text-gray-500",children:"Value must be between 0 and 1"}),"number"===a?(0,c.jsx)(O,{step:.01,width:400,placeholder:"os.environ/".concat(l.toUpperCase()),value:e.callback_vars[l]||"",onChange:e=>m(s,l,e.target.value)}):(0,c.jsx)(_.Z,{type:"password"===a?"password":"text",placeholder:"os.environ/".concat(l.toUpperCase()),value:e.callback_vars[l]||"",onChange:e=>m(s,l,e.target.value)})]},l)})})]})};return(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(H.Z,{className:"w-5 h-5 text-red-500"}),(0,c.jsx)("span",{className:"text-base font-semibold text-gray-800",children:"Disabled Callbacks"}),(0,c.jsx)(V.Z,{title:"Select callbacks to disable for this key. Disabled callbacks will not receive any logging data.",children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help"})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Disabled Callbacks"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select callbacks to disable",value:l,onChange:e=>{let s=ee(e);null==a||a(s)},style:{width:"100%"},optionLabelProp:"label",children:i.map(e=>{var s,t;let l=null===(s=et[e])||void 0===s?void 0:s.logo,a=null===(t=et[e])||void 0===t?void 0:t.description;return(0,c.jsx)(el,{value:e,label:e,children:(0,c.jsx)(V.Z,{title:a,placement:"right",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,c.jsx)("img",{src:l,alt:e,className:"w-4 h-4 object-contain",onError:s=>{let t=s.target,l=t.parentElement;if(l){let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=e.charAt(0),l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e})]})})},e)})}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"Select callbacks that should be disabled for this key. These callbacks will not receive any logging data."})]})]}),(0,c.jsx)(K.Z,{}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(J.Z,{className:"w-5 h-5 text-blue-500"}),(0,c.jsx)("span",{className:"text-base font-semibold text-gray-800",children:"Logging Integrations"}),(0,c.jsx)(V.Z,{title:"Configure callback logging integrations for this team.",children:(0,c.jsx)(B.Z,{className:"text-gray-400 cursor-help"})})]}),(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{n([...s,{callback_name:"",callback_type:"success",callback_vars:{}}])},icon:Y.Z,size:"sm",className:"hover:border-blue-400 hover:text-blue-500",type:"button",children:"Add Integration"})]}),(0,c.jsx)("div",{className:"space-y-4",children:s.map((e,s)=>{var t,l;let a=e.callback_name?null===(t=Object.entries($).find(s=>{let[t,l]=s;return l===e.callback_name}))||void 0===t?void 0:t[0]:void 0,i=a?null===(l=et[a])||void 0===l?void 0:l.logo:null;return(0,c.jsxs)(G.Z,{className:"border border-gray-200 shadow-sm hover:shadow-md transition-shadow duration-200",decoration:"top",decorationColor:"blue",children:[(0,c.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[i&&(0,c.jsx)("img",{src:i,alt:a,className:"w-5 h-5 object-contain"}),(0,c.jsxs)("span",{className:"text-sm font-medium",children:[a||"New Integration"," Configuration"]})]}),(0,c.jsx)(b.Z,{variant:"light",onClick:()=>o(s),icon:W.Z,size:"xs",color:"red",className:"hover:bg-red-50",type:"button",children:"Remove"})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Integration Type"}),(0,c.jsx)(I.default,{value:a,placeholder:"Select integration",onChange:e=>d(s,"callback_name",e),className:"w-full",optionLabelProp:"label",children:r.map(e=>{var s,t;let l=null===(s=et[e])||void 0===s?void 0:s.logo,a=null===(t=et[e])||void 0===t?void 0:t.description;return(0,c.jsx)(el,{value:e,label:e,children:(0,c.jsx)(V.Z,{title:a,placement:"right",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,c.jsx)("img",{src:l,alt:e,className:"w-4 h-4 object-contain",onError:s=>{let t=s.target,l=t.parentElement;if(l){let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=e.charAt(0),l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e})]})})},e)})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Event Type"}),(0,c.jsxs)(I.default,{value:e.callback_type,onChange:e=>d(s,"callback_type",e),className:"w-full",children:[(0,c.jsx)(el,{value:"success",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{children:"Success Only"})]})}),(0,c.jsx)(el,{value:"failure",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-red-500 rounded-full"}),(0,c.jsx)("span",{children:"Failure Only"})]})}),(0,c.jsx)(el,{value:"success_and_failure",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{children:"Success & Failure"})]})})]})]})]}),u(e,s)]})]},s)})}),0===s.length&&(0,c.jsxs)("div",{className:"text-center py-12 text-gray-500 border-2 border-dashed border-gray-200 rounded-lg bg-gray-50/50",children:[(0,c.jsx)(J.Z,{className:"w-12 h-12 text-gray-300 mb-3 mx-auto"}),(0,c.jsx)("div",{className:"text-base font-medium mb-1",children:"No logging integrations configured"}),(0,c.jsx)("div",{className:"text-sm text-gray-400",children:'Click "Add Integration" to configure logging for this team'})]})]})},er=function(e){let{value:s,onChange:t,premiumUser:l=!1,disabledCallbacks:a=[],onDisabledCallbacksChange:r}=e;return l?(0,c.jsx)(ea,{value:s,onChange:t,disabledCallbacks:a,onDisabledCallbacksChange:r}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex flex-wrap gap-2 mb-3",children:[(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium opacity-50",children:"✨ langfuse-logging"}),(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium opacity-50",children:"✨ datadog-logging"})]}),(0,c.jsx)("div",{className:"p-3 bg-yellow-50 border border-yellow-200 rounded-lg",children:(0,c.jsxs)(k.Z,{className:"text-sm text-yellow-800",children:["Setting Key/Team logging settings is a LiteLLM Enterprise feature. Global Logging Settings are available for all free users. Get a trial key ",(0,c.jsx)("a",{href:"https://www.litellm.ai/#pricing",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"here"}),"."]})})]})},ei=t(57365),en=t(93192),eo=t(9114);function ec(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:t,baseUrl:l,invitationLinkData:a,modalType:r="invitation"}=e,{Title:i,Paragraph:n}=en.default,o=()=>{if(!l)return"";let e=new URL(l).pathname,s=e&&"/"!==e?"".concat(e,"/ui"):"ui";if(null==a?void 0:a.has_user_setup_sso)return new URL(s,l).toString();let t="".concat(s,"?invitation_id=").concat(null==a?void 0:a.id);return"resetPassword"===r&&(t+="&action=reset_password"),new URL(t,l).toString()};return(0,c.jsxs)(L.Z,{title:"invitation"===r?"Invitation Link":"Reset Password Link",visible:s,width:800,footer:null,onOk:()=>{t(!1)},onCancel:()=>{t(!1)},children:[(0,c.jsx)(n,{children:"invitation"===r?"Copy and send the generated link to onboard this user to the proxy.":"Copy and send the generated link to the user to reset their password."}),(0,c.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,c.jsx)(k.Z,{className:"text-base",children:"User ID"}),(0,c.jsx)(k.Z,{children:null==a?void 0:a.user_id})]}),(0,c.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,c.jsx)(k.Z,{children:"invitation"===r?"Invitation Link":"Reset Password Link"}),(0,c.jsx)(k.Z,{children:(0,c.jsx)(k.Z,{children:o()})})]}),(0,c.jsx)("div",{className:"flex justify-end mt-5",children:(0,c.jsx)(C.CopyToClipboard,{text:o(),onCopy:()=>eo.Z.success("Copied!"),children:(0,c.jsx)(b.Z,{variant:"primary",children:"invitation"===r?"Copy invitation link":"Copy password reset link"})})})]})}var ed=t(65319),em=t(72188),eu=t(73879),ex=t(34310),eh=t(38434),ep=t(26349),eg=t(35291),ej=t(3632),ef=t(15452),ev=t.n(ef),ey=t(71157),eb=t(44643),e_=t(88532),eN=e=>{let{accessToken:s,teams:t,possibleUIRoles:l,onUsersCreated:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(null),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(null),[w,S]=(0,d.useState)("http://localhost:4000");(0,d.useEffect)(()=>{(async()=>{try{let e=await (0,j.getProxyUISettings)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),S(new URL("/",window.location.href).toString())},[s]);let I=async()=>{u(!0);let e=n.map(e=>({...e,status:"pending"}));o(e);let t=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),n.models&&"string"==typeof n.models&&""!==n.models.trim()&&(e.models=n.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),n.max_budget&&""!==n.max_budget.toString().trim()){let s=parseFloat(n.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}n.budget_duration&&""!==n.budget_duration.trim()&&(e.budget_duration=n.budget_duration.trim()),n.metadata&&"string"==typeof n.metadata&&""!==n.metadata.trim()&&(e.metadata=n.metadata.trim()),console.log("Sending user data:",e);let r=await (0,j.userCreateCall)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){t=!0,console.log("Success case triggered");let e=(null===(l=r.data)||void 0===l?void 0:l.user_id)||r.user_id;try{if(null==N?void 0:N.SSO_ENABLED){let e=new URL("/ui",w).toString();o(s=>s.map((s,t)=>t===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let t=await (0,j.invitationCreateCall)(s,e),l=new URL("/ui?invitation_id=".concat(t.id),w).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:l}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===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),o(s=>s.map((s,t)=>t===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(i=s.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,t)=>t===a?{...s,status:"failed",error:e}:s))}}u(!1),t&&a&&a()};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(b.Z,{className:"mb-0",onClick:()=>i(!0),children:"+ Bulk Invite Users"}),(0,c.jsx)(L.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>i(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,c.jsx)("div",{className:"flex flex-col",children:0===n.length?(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,c.jsxs)("div",{className:"ml-11 mb-6",children:[(0,c.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,c.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,c.jsx)("li",{children:"Download our CSV template"}),(0,c.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,c.jsx)("li",{children:"Save the file and upload it here"}),(0,c.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,c.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"user_email"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"user_role"}),(0,c.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,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"teams"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"font-medium",children:"models"}),(0,c.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,c.jsxs)(b.Z,{onClick:()=>{let e=new Blob([ev().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"}),s=window.URL.createObjectURL(e),t=document.createElement("a");t.href=s,t.download="bulk_users_template.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,c.jsx)(eu.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,c.jsxs)("div",{className:"ml-11",children:[y?(0,c.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(f?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[f?(0,c.jsx)(ex.Z,{className:"text-red-500 text-xl mr-3"}):(0,c.jsx)(eh.Z,{className:"text-blue-500 text-xl mr-3"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(en.default.Text,{strong:!0,className:f?"text-red-800":"text-blue-800",children:y.name}),(0,c.jsxs)(en.default.Text,{className:"block text-xs ".concat(f?"text-red-600":"text-blue-600"),children:[(y.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,c.jsxs)(b.Z,{size:"xs",variant:"secondary",onClick:()=>{_(null),o([]),h(null),g(null),v(null)},className:"flex items-center",children:[(0,c.jsx)(ep.Z,{className:"mr-1"})," Remove"]})]}),f?(0,c.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,c.jsx)(eg.Z,{className:"mr-2 mt-0.5"}),(0,c.jsx)("span",{children:f})]}):!p&&(0,c.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,c.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,c.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,c.jsx)(ed.default,{beforeUpload:e=>((h(null),g(null),v(null),_(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?v("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ev().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let l=["user_email","user_role"].filter(e=>!s.includes(e));if(l.length>0){g("Your CSV is missing these required columns: ".concat(l.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let l=e.data.slice(1).map((e,l)=>{var a,r,i,n,o,c;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(d.max_budget.toString())&&m.push("Max budget must be greater than 0")),d.budget_duration&&!d.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(d.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),d.teams&&"string"==typeof d.teams&&t&&t.length>0){let e=t.map(e=>e.team_id),s=d.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(d.isValid=!1,d.error=m.join(", ")),d}).filter(Boolean),a=l.filter(e=>e.isValid);o(l),0===l.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?h("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{h("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(v("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),eo.Z.fromBackend("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,c.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,c.jsx)(ej.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,c.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,c.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,c.jsx)(b.Z,{size:"sm",children:"Browse files"}),(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,c.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(e_.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(en.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,c.jsx)(en.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,c.jsx)(en.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center mb-4",children:[(0,c.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:n.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),x&&(0,c.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(eg.Z,{className:"text-red-500 mr-2 mt-1"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-red-600 font-medium",children:x}),n.some(e=>!e.isValid)&&(0,c.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,c.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,c.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,c.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,c.jsxs)("div",{className:"ml-11",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,c.jsx)("div",{className:"flex items-center",children:n.some(e=>"success"===e.status||"failed"===e.status)?(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,c.jsxs)(k.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[n.filter(e=>"success"===e.status).length," Successful"]}),n.some(e=>"failed"===e.status)&&(0,c.jsxs)(k.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[n.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,c.jsxs)(k.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[n.filter(e=>e.isValid).length," of ",n.length," users valid"]})]})}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex space-x-3",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",children:"Back"}),(0,c.jsx)(b.Z,{onClick:I,disabled:0===n.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]})]}),n.some(e=>"success"===e.status)&&(0,c.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)("div",{className:"mr-3 mt-1",children:(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-blue-500"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,c.jsxs)(k.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,c.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,c.jsx)(em.Z,{dataSource:n,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,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,c.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,c.jsx)("div",{className:"mt-1",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,c.jsx)(C.CopyToClipboard,{text:s.invitation_link,onCopy:()=>eo.Z.success("Invitation link copied!"),children:(0,c.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,c.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,c.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,c.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,c.jsx)(b.Z,{onClick:I,disabled:0===n.filter(e=>e.isValid).length||m,children:m?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]}),n.some(e=>"success"===e.status||"failed"===e.status)&&(0,c.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,c.jsx)(b.Z,{onClick:()=>{o([]),h(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,c.jsxs)(b.Z,{onClick:()=>{let e=n.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||""})),s=new Blob([ev().unparse(e)],{type:"text/csv"}),t=window.URL.createObjectURL(s),l=document.createElement("a");l.href=t,l.download="bulk_users_results.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(t)},variant:"primary",className:"flex items-center",children:[(0,c.jsx)(eu.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:eZ}=I.default,ew=()=>"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let s=16*Math.random()|0;return("x"==e?s:3&s|8).toString(16)});var ek=e=>{let{userID:s,accessToken:t,teams:l,possibleUIRoles:a,onUserCreated:r,isEmbedded:i=!1}=e,n=(0,h.NL)(),[o,m]=(0,d.useState)(null),[u]=A.Z.useForm(),[x,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),[C,T]=(0,d.useState)(!1),[M,O]=(0,d.useState)(null),[D,R]=(0,d.useState)(null);(0,d.useEffect)(()=>{let e=async()=>{try{let e=await (0,j.modelAvailableCall)(t,s,"any"),l=[];for(let s=0;s{var l,a,c;try{eo.Z.info("Making API Call"),i||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,j.userCreateCall)(t,null,e);await n.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let c=(null===(l=a.data)||void 0===l?void 0:l.user_id)||a.user_id;if(r&&i){r(c),u.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:ew(),user_id:c,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};O(e),T(!0)}else(0,j.invitationCreateCall)(t,c).then(e=>{e.has_user_setup_sso=!1,O(e),T(!0)});eo.Z.success("API user Created"),u.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(c=s.response)||void 0===c?void 0:null===(a=c.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";eo.Z.fromBackend(e),console.error("Error creating the user:",s)}};return i?(0,c.jsxs)(A.Z,{form:u,onFinish:z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,c.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,c.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:l?l.map(e=>(0,c.jsx)(eZ,{value:e.team_id,children:e.team_alias},e.team_id)):(0,c.jsx)(eZ,{value:null,children:"Default Team"},"default")})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{className:"mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,c.jsx)(eN,{accessToken:t,teams:l,possibleUIRoles:a}),(0,c.jsxs)(L.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),u.resetFields()},onCancel:()=>{p(!1),f(!1),u.resetFields()},children:[(0,c.jsx)(k.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,c.jsxs)(A.Z,{form:u,onFinish:z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"User Email",name:"user_email",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Global Proxy Role"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{})})]}),name:"user_role",children:(0,c.jsx)(I.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.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,c.jsx)(I.default,{placeholder:"Select Team ID",style:{width:"100%"},children:l?l.map(e=>(0,c.jsx)(eZ,{value:e.team_id,children:e.team_alias},e.team_id)):(0,c.jsx)(eZ,{value:null,children:"Default Team"},"default")})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsxs)(N.Z,{children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)(S.Z,{children:"Personal Key Creation"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)(A.Z.Item,{className:"gap-2",label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.Z,{title:"Models user has access to, outside of team scope.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),v.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})})})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create User"})})]})]}),g&&(0,c.jsx)(ec,{isInvitationLinkModalVisible:C,setIsInvitationLinkModalVisible:T,baseUrl:D||"",invitationLinkData:M})]})},eS=t(7310),eC=t.n(eS),eI=t(20347);let{Option:eA}=I.default,eL=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var eT=e=>{let{value:s,onChange:t,className:l="",style:a={}}=e;return(0,c.jsxs)(I.default,{style:{width:"100%",...a},value:s||void 0,onChange:t,className:l,placeholder:"n/a",children:[(0,c.jsx)(eA,{value:"24h",children:"daily"}),(0,c.jsx)(eA,{value:"7d",children:"weekly"}),(0,c.jsx)(eA,{value:"30d",children:"monthly"})]})};function eP(e,s){let t=structuredClone(e);for(let[e,l]of Object.entries(s))e in t&&(t[e]=l);return t}let eE=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return null==e?"-":e.toLocaleString("en-US",{minimumFractionDigits:s,maximumFractionDigits:s})},eM=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Copied to clipboard";if(!e)return!1;try{return await navigator.clipboard.writeText(e),eo.Z.success(s),!0}catch(e){return eo.Z.fromBackend("Failed to copy to clipboard"),console.error("Failed to copy: ",e),!1}};var eO=e=>{let{onChange:s,value:t,className:l,accessToken:a,placeholder:r="Select MCP servers",disabled:i=!1}=e,[n,o]=(0,d.useState)([]),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(a){h(!0);try{let[e,s]=await Promise.all([(0,j.fetchMCPServers)(a),(0,j.fetchMCPAccessGroups)(a)]),t=Array.isArray(e)?e:e.data||[],l=Array.isArray(s)?s:s.data||[];o(t),u(l)}catch(e){console.error("Error fetching MCP servers or access groups:",e)}finally{h(!1)}}})()},[a]);let p=[...m.map(e=>({label:e,value:e,isAccessGroup:!0,searchText:"".concat(e," Access Group")})),...n.map(e=>({label:"".concat(e.server_name||e.server_id," (").concat(e.server_id,")"),value:e.server_id,isAccessGroup:!1,searchText:"".concat(e.server_name||e.server_id," ").concat(e.server_id," MCP Server")}))],g=[...(null==t?void 0:t.servers)||[],...(null==t?void 0:t.accessGroups)||[]];return(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:r,onChange:e=>{s({servers:e.filter(e=>!m.includes(e)),accessGroups:e.filter(e=>m.includes(e))})},value:g,loading:x,className:l,showSearch:!0,style:{width:"100%"},disabled:i,filterOption:(e,s)=>{var t;return((null===(t=p.find(e=>e.value===(null==s?void 0:s.value)))||void 0===t?void 0:t.searchText)||"").toLowerCase().includes(e.toLowerCase())},children:p.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,label:e.label,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,c.jsx)("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:e.isAccessGroup?"#52c41a":"#1890ff",flexShrink:0}}),(0,c.jsx)("span",{style:{flex:1},children:e.label}),(0,c.jsx)("span",{style:{color:e.isAccessGroup?"#52c41a":"#1890ff",fontSize:"12px",fontWeight:500,opacity:.8},children:e.isAccessGroup?"Access Group":"MCP Server"})]})},e.value))})})},eD=t(77355),eF=t(93416),eR=t(95704),ez=t(69993);let eU=async e=>{try{let s=await (0,j.modelHubCall)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};var eq=e=>{let{accessToken:s,value:t,placeholder:l="Select a Model",onChange:a,disabled:r=!1,style:i,className:n,showLabel:o=!0,labelText:m="Select Model"}=e,[u,x]=(0,d.useState)(t),[h,p]=(0,d.useState)(!1),[g,j]=(0,d.useState)([]),f=(0,d.useRef)(null);return(0,d.useEffect)(()=>{x(t)},[t]),(0,d.useEffect)(()=>{s&&(async()=>{try{let e=await eU(s);console.log("Fetched models for selector:",e),e.length>0&&j(e)}catch(e){console.error("Error fetching model info:",e)}})()},[s]),(0,c.jsxs)("div",{children:[o&&(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(ez.Z,{className:"mr-2"})," ",m]}),(0,c.jsx)(I.default,{value:u,placeholder:l,onChange:e=>{"custom"===e?(p(!0),x(void 0)):(p(!1),x(e),a&&a(e))},options:[...Array.from(new Set(g.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%",...i},showSearch:!0,className:"rounded-md ".concat(n||""),disabled:r}),h&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{x(e),a&&a(e)},500)},disabled:r})]})},eB=e=>{let{accessToken:s,initialModelAliases:t={},onAliasUpdate:l,showExampleConfig:a=!0}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)({aliasName:"",targetModel:""}),[m,u]=(0,d.useState)(null);(0,d.useEffect)(()=>{i(Object.entries(t).map((e,s)=>{let[t,l]=e;return{id:"".concat(s,"-").concat(t),aliasName:t,targetModel:l}}))},[t]);let x=e=>{u({...e})},h=()=>{if(!m)return;if(!m.aliasName||!m.targetModel){eo.Z.fromBackend("Please provide both alias name and target model");return}if(r.some(e=>e.id!==m.id&&e.aliasName===m.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=r.map(e=>e.id===m.id?m:e);i(e),u(null);let s={};e.forEach(e=>{s[e.aliasName]=e.targetModel}),l&&l(s),eo.Z.success("Alias updated successfully")},p=()=>{u(null)},g=e=>{let s=r.filter(s=>s.id!==e);i(s);let t={};s.forEach(e=>{t[e.aliasName]=e.targetModel}),l&&l(t),eo.Z.success("Alias deleted successfully")},j=r.reduce((e,s)=>(e[s.aliasName]=s.targetModel,e),{});return(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Add New Alias"}),(0,c.jsxs)("div",{className:"grid grid-cols-3 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Alias Name"}),(0,c.jsx)("input",{type:"text",value:n.aliasName,onChange:e=>o({...n,aliasName:e.target.value}),placeholder:"e.g., gpt-4o",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Target Model"}),(0,c.jsx)(eq,{accessToken:s,value:n.targetModel,placeholder:"Select target model",onChange:e=>o({...n,targetModel:e}),showLabel:!1})]}),(0,c.jsx)("div",{className:"flex items-end",children:(0,c.jsxs)("button",{onClick:()=>{if(!n.aliasName||!n.targetModel){eo.Z.fromBackend("Please provide both alias name and target model");return}if(r.some(e=>e.aliasName===n.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=[...r,{id:"".concat(Date.now(),"-").concat(n.aliasName),aliasName:n.aliasName,targetModel:n.targetModel}];i(e),o({aliasName:"",targetModel:""});let s={};e.forEach(e=>{s[e.aliasName]=e.targetModel}),l&&l(s),eo.Z.success("Alias added successfully")},disabled:!n.aliasName||!n.targetModel,className:"flex items-center px-4 py-2 rounded-md text-sm ".concat(n.aliasName&&n.targetModel?"bg-green-600 text-white hover:bg-green-700":"bg-gray-300 text-gray-500 cursor-not-allowed"),children:[(0,c.jsx)(eD.Z,{className:"w-4 h-4 mr-1"}),"Add Alias"]})})]})]}),(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Manage Existing Aliases"}),(0,c.jsx)("div",{className:"rounded-lg custom-border relative mb-6",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(eR.iA,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(eR.ss,{children:(0,c.jsxs)(eR.SC,{children:[(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Alias Name"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Target Model"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Actions"})]})}),(0,c.jsxs)(eR.RM,{children:[r.map(e=>(0,c.jsx)(eR.SC,{className:"h-8",children:m&&m.id===e.id?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:m.aliasName,onChange:e=>u({...m,aliasName:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)(eq,{accessToken:s,value:m.targetModel,onChange:e=>u({...m,targetModel:e}),showLabel:!1,style:{height:"32px"}})}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:h,className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:"Save"}),(0,c.jsx)("button",{onClick:p,className:"text-xs bg-gray-50 text-gray-600 px-2 py-1 rounded hover:bg-gray-100",children:"Cancel"})]})})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-900",children:e.aliasName}),(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-500",children:e.targetModel}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>x(e),className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:(0,c.jsx)(eF.Z,{className:"w-3 h-3"})}),(0,c.jsx)("button",{onClick:()=>g(e.id),className:"text-xs bg-red-50 text-red-600 px-2 py-1 rounded hover:bg-red-100",children:(0,c.jsx)(W.Z,{className:"w-3 h-3"})})]})})]})},e.id)),0===r.length&&(0,c.jsx)(eR.SC,{children:(0,c.jsx)(eR.pj,{colSpan:3,className:"py-0.5 text-sm text-gray-500 text-center",children:"No aliases added yet. Add a new alias above."})})]})]})})}),a&&(0,c.jsxs)(eR.Zb,{children:[(0,c.jsx)(eR.Dx,{className:"mb-4",children:"Configuration Example"}),(0,c.jsx)(eR.xv,{className:"text-gray-600 mb-4",children:"Here's how your current aliases would look in the config:"}),(0,c.jsx)("div",{className:"bg-gray-100 rounded-lg p-4 font-mono text-sm",children:(0,c.jsxs)("div",{className:"text-gray-700",children:["model_aliases:",0===Object.keys(j).length?(0,c.jsxs)("span",{className:"text-gray-500",children:[(0,c.jsx)("br",{}),"\xa0\xa0# No aliases configured yet"]}):Object.entries(j).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[(0,c.jsx)("br",{}),'\xa0\xa0"',s,'": "',t,'"']},s)})]})})]})]})};let{Option:eV}=I.default,eK=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let t of e)t.metadata&&t.metadata.tags&&s.push(...t.metadata.tags);let t=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",t),t},eG=async(e,s,t,l)=>{try{if(null===e||null===s)return[];if(null!==t){let a=(await (0,j.modelAvailableCall)(t,e,s,!0,l,!0)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eH=async(e,s,t,l)=>{try{if(null===e||null===s)return;if(null!==t){let a=(await (0,j.modelAvailableCall)(t,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),l(a)}}catch(e){console.error("Error fetching user models:",e)}};var eJ=e=>{let{userID:s,team:t,teams:l,userRole:a,accessToken:r,data:i,addKey:n,premiumUser:o=!1}=e,[m]=A.Z.useForm(),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(null),[M,D]=(0,d.useState)([]),[R,K]=(0,d.useState)([]),[G,H]=(0,d.useState)("you"),[J,Y]=(0,d.useState)(eK(i)),[W,$]=(0,d.useState)([]),[Q,X]=(0,d.useState)([]),[es,et]=(0,d.useState)([]),[el,ea]=(0,d.useState)(t),[ei,en]=(0,d.useState)(!1),[ec,ed]=(0,d.useState)(null),[em,eu]=(0,d.useState)({}),[ex,eh]=(0,d.useState)([]),[ep,eg]=(0,d.useState)(!1),[ej,ef]=(0,d.useState)([]),[ev,ey]=(0,d.useState)(!1),[eb,e_]=(0,d.useState)([]),[eN,eZ]=(0,d.useState)("default"),[ew,eS]=(0,d.useState)({}),eA=()=>{x(!1),m.resetFields(),et([]),e_([]),eZ("default"),eS({})},eL=()=>{x(!1),p(null),ea(null),m.resetFields(),et([]),e_([]),eZ("default"),eS({})};(0,d.useEffect)(()=>{s&&a&&r&&eH(s,a,r,D)},[r,s,a]);let eP=async()=>{try{if(null==r)return;let e=await (0,j.fetchMCPAccessGroups)(r);ef(e)}catch(e){console.error("Failed to fetch MCP access groups:",e)}};(0,d.useEffect)(()=>{eP()},[r]),(0,d.useEffect)(()=>{let e=async()=>{try{let e=await (0,j.getPromptsList)(r);X(e.prompts.map(e=>e.prompt_id))}catch(e){console.error("Failed to fetch prompts:",e)}};(async()=>{try{let e=(await (0,j.getGuardrailsList)(r)).guardrails.map(e=>e.guardrail_name);$(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})(),e()},[r]),(0,d.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)eu(JSON.parse(e));else{let e=await (0,j.getPossibleUserRoles)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),eu(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let eM=R.includes("no-default-models")&&!el,eD=async e=>{try{var t,l,a,o,c;let d;let u=null!==(a=null==e?void 0:e.key_alias)&&void 0!==a?a:"",h=null!==(o=null==e?void 0:e.team_id)&&void 0!==o?o:null;if((null!==(c=null==i?void 0:i.filter(e=>e.team_id===h).map(e=>e.key_alias))&&void 0!==c?c:[]).includes(u))throw Error("Key alias ".concat(u," already exists for team with ID ").concat(h,", please provide another key alias"));eo.Z.info("Making API Call"),x(!0),"you"===G&&(e.user_id=s);let g={};try{g=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}if("service_account"===G&&(g.service_account_id=e.key_alias),es.length>0&&(g={...g,logging:es.filter(e=>e.callback_name)}),eb.length>0){let e=ee(eb);g={...g,litellm_disabled_callbacks:e}}if(e.metadata=JSON.stringify(g),e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission={vector_stores:e.allowed_vector_store_ids},delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups&&((null===(t=e.allowed_mcp_servers_and_groups.servers)||void 0===t?void 0:t.length)>0||(null===(l=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===l?void 0:l.length)>0)){e.object_permission||(e.object_permission={});let{servers:s,accessGroups:t}=e.allowed_mcp_servers_and_groups;s&&s.length>0&&(e.object_permission.mcp_servers=s),t&&t.length>0&&(e.object_permission.mcp_access_groups=t),delete e.allowed_mcp_servers_and_groups}e.allowed_mcp_access_groups&&e.allowed_mcp_access_groups.length>0&&(e.object_permission||(e.object_permission={}),e.object_permission.mcp_access_groups=e.allowed_mcp_access_groups,delete e.allowed_mcp_access_groups),Object.keys(ew).length>0&&(e.aliases=JSON.stringify(ew)),d="service_account"===G?await (0,j.keyCreateServiceAccountCall)(r,e):await (0,j.keyCreateCall)(r,s,e),console.log("key create Response:",d),n(d),p(d.key),f(d.soft_budget),eo.Z.success("API Key Created"),m.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};(0,d.useEffect)(()=>{if(s&&a&&r){var e;eG(s,a,r,null!==(e=null==el?void 0:el.team_id)&&void 0!==e?e:null).then(e=>{var s;K(Array.from(new Set([...null!==(s=null==el?void 0:el.models)&&void 0!==s?s:[],...e])))})}m.setFieldValue("models",[])},[el,r,s,a]);let eF=async e=>{if(!e){eh([]);return}eg(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let t=(await (0,j.userFilterUICall)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));eh(t)}catch(e){console.error("Error fetching users:",e),eo.Z.fromBackend("Failed to search for users")}finally{eg(!1)}},eR=(0,d.useCallback)(eC()(e=>eF(e),300),[r]),ez=(e,s)=>{let t=s.user;m.setFieldsValue({user_id:t.user_id})};return(0,c.jsxs)("div",{children:[a&&eI.LQ.includes(a)&&(0,c.jsx)(b.Z,{className:"mx-auto",onClick:()=>x(!0),children:"+ Create New Key"}),(0,c.jsx)(L.Z,{visible:u,width:1e3,footer:null,onOk:eA,onCancel:eL,children:(0,c.jsxs)(A.Z,{form:m,onFinish:eD,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Key Ownership"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Owned By"," ",(0,c.jsx)(V.Z,{title:"Select who will own this API key",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,c.jsxs)(T.ZP.Group,{onChange:e=>H(e.target.value),value:G,children:[(0,c.jsx)(T.ZP,{value:"you",children:"You"}),(0,c.jsx)(T.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,c.jsx)(T.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===G&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["User ID"," ",(0,c.jsx)(V.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===G,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eR(e)},onSelect:(e,s)=>ez(e,s),options:ex,loading:ep,allowClear:!0,style:{width:"100%"},notFoundContent:ep?"Searching...":"No users found"}),(0,c.jsx)(P.ZP,{onClick:()=>en(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Team"," ",(0,c.jsx)(V.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:t?t.team_id:null,className:"mt-4",rules:[{required:"service_account"===G,message:"Please select a team for the service account"}],help:"service_account"===G?"required":"",children:(0,c.jsx)(q,{teams:l,onChange:e=>{ea((null==l?void 0:l.find(s=>s.team_id===e))||null)}})})]}),eM&&(0,c.jsx)("div",{className:"mb-8 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-blue-800 text-sm",children:"Please select a team to continue configuring your API key. If you do not see any teams, please contact your Proxy Admin to either provide you with access to models or to add you to a team."})}),!eM&&(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Key Details"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["you"===G||"another_user"===G?"Key Name":"Service Account ID"," ",(0,c.jsx)(V.Z,{title:"you"===G||"another_user"===G?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===G?"key name":"service account ID")}],help:"required",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:"management"===eN||"read_only"===eN?[]:[{required:!0,message:"Please select a model"}],help:"management"===eN||"read_only"===eN?"Models field is disabled for this key type":"required",className:"mt-4",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:"management"===eN||"read_only"===eN,onChange:e=>{e.includes("all-team-models")&&m.setFieldsValue({models:["all-team-models"]})},children:[(0,c.jsx)(eV,{value:"all-team-models",children:"All Team Models"},"all-team-models"),R.map(e=>(0,c.jsx)(eV,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Key Type"," ",(0,c.jsx)(V.Z,{title:"Select the type of key to determine what routes and operations this key can access",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"key_type",initialValue:"default",className:"mt-4",children:(0,c.jsxs)(I.default,{defaultValue:"default",placeholder:"Select key type",style:{width:"100%"},optionLabelProp:"label",onChange:e=>{eZ(e),("management"===e||"read_only"===e)&&m.setFieldsValue({models:[]})},children:[(0,c.jsx)(eV,{value:"default",label:"Default",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"Default"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call LLM API + Management routes"})]})}),(0,c.jsx)(eV,{value:"llm_api",label:"LLM API",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"LLM API"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call only LLM API routes (chat/completions, embeddings, etc.)"})]})}),(0,c.jsx)(eV,{value:"management",label:"Management",children:(0,c.jsxs)("div",{style:{padding:"4px 0"},children:[(0,c.jsx)("div",{style:{fontWeight:500},children:"Management"}),(0,c.jsx)("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"Can call only management routes (user/team/key management)"})]})})]})})]}),!eM&&(0,c.jsx)("div",{className:"mb-8",children:(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",onClick:()=>{ev||(eP(),ey(!0))},children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)(S.Z,{className:"m-0",children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Max Budget (USD)"," ",(0,c.jsx)(V.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.max_budget&&s>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(eE(t.max_budget,4)))}}],children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Reset Budget"," ",(0,c.jsx)(V.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,c.jsx)(eT,{onChange:e=>m.setFieldValue("budget_duration",e)})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,c.jsx)(V.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.tpm_limit&&s>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{className:"mt-4",label:(0,c.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,c.jsx)(V.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&t&&null!==t.rpm_limit&&s>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Expire Key"," ",(0,c.jsx)(V.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:o?"Select existing guardrails or enter new ones":"Premium feature - Upgrade to set guardrails by key",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!o,placeholder:o?"Select or enter guardrails":"Premium feature - Upgrade to set guardrails by key",options:W.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Prompts"," ",(0,c.jsx)(V.Z,{title:"Allow this key to use specific prompt templates",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/prompt_management",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"prompts",className:"mt-4",help:o?"Select existing prompts or enter new ones":"Premium feature - Upgrade to set prompts by key",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!o,placeholder:o?"Select or enter prompts":"Premium feature - Upgrade to set prompts by key",options:Q.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this key can access. If none selected, the key will have access to all available vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-4",help:"Select vector stores this key can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>m.setFieldValue("allowed_vector_store_ids",e),value:m.getFieldValue("allowed_vector_store_ids"),accessToken:r,placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers or access groups this key can access. ",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-4",help:"Select MCP servers or access groups this key can access. ",children:(0,c.jsx)(eO,{onChange:e=>m.setFieldValue("allowed_mcp_servers_and_groups",e),value:m.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:r,placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Tags"," ",(0,c.jsx)(V.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:J})}),o?(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:es,onChange:et,premiumUser:!0,disabledCallbacks:eb,onDisabledCallbacksChange:e_})})})]}):(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Key-level logging settings is an enterprise feature, get in touch -",(0,c.jsx)("a",{href:"https://www.litellm.ai/enterprise",target:"_blank",children:"https://www.litellm.ai/enterprise"})]}),placement:"top",children:(0,c.jsxs)("div",{style:{position:"relative"},children:[(0,c.jsx)("div",{style:{opacity:.5},children:(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:es,onChange:et,premiumUser:!1,disabledCallbacks:eb,onDisabledCallbacksChange:e_})})})]})}),(0,c.jsx)("div",{style:{position:"absolute",inset:0,cursor:"not-allowed"}})]})}),(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Model Aliases"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600 mb-4",children:"Create custom aliases for models that can be used in API calls. This allows you to create shortcuts for specific models."}),(0,c.jsx)(eB,{accessToken:r,initialModelAliases:ew,onAliasUpdate:eS,showExampleConfig:!1})]})})]}),(0,c.jsxs)(N.Z,{className:"mt-4 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("b",{children:"Advanced Settings"}),(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,c.jsx)("a",{href:j.proxyBaseUrl?"".concat(j.proxyBaseUrl,"/#/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,c.jsx)(B.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)(z.Z,{schemaComponent:"GenerateKeyRequest",form:m,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",disabled:eM,style:{opacity:eM?.5:1},children:"Create Key"})})]})}),ei&&(0,c.jsx)(L.Z,{title:"Create New User",visible:ei,onCancel:()=>en(!1),footer:null,width:800,children:(0,c.jsx)(ek,{userID:s,accessToken:r,teams:l,possibleUIRoles:em,onUserCreated:e=>{ed(e),m.setFieldsValue({user_id:e}),en(!1)},isEmbedded:!0})}),h&&(0,c.jsx)(L.Z,{visible:u,onOk:eA,onCancel:eL,footer:null,children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Save your Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,c.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,c.jsx)(v.Z,{numColSpan:1,children:null!=h?(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"API Key:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,c.jsx)(C.CopyToClipboard,{text:h,onCopy:()=>{eo.Z.success("API Key copied to clipboard")},children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,c.jsx)(k.Z,{children:"Key being created, this might take 30s"})})]})})]})},eY=t(7366),eW=t(20577),e$=e=>{let{selectedTeam:s,currentOrg:t,selectedKeyAlias:l,accessToken:a,createClicked:r}=e,[i,n]=(0,d.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,c]=(0,d.useState)(!0),[m,u]=(0,d.useState)(null),x=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}c(!0);let s="number"==typeof e.page?e.page:1,t="number"==typeof e.pageSize?e.pageSize:100,l=await (0,j.keyListCall)(a,null,null,null,null,null,s,t);console.log("data",l),n(l),u(null)}catch(e){u(e instanceof Error?e:Error("An error occurred"))}finally{c(!1)}};return(0,d.useEffect)(()=>{x(),console.log("selectedTeam",s,"currentOrg",t,"accessToken",a,"selectedKeyAlias",l)},[s,t,a,l,r]),{keys:i.keys,isLoading:o,error:m,pagination:{currentPage:i.current_page,totalPages:i.total_pages,totalCount:i.total_count},refresh:x,setKeys:e=>{n(s=>{let t="function"==typeof e?e(s.keys):e;return{...s,keys:t}})}}},eQ=t(27281),eX=t(41649),e0=t(12485),e1=t(18135),e2=t(35242),e4=t(29706),e5=t(77991),e6=t(10900),e3=t(23628),e8=e=>{let{value:s,onChange:t,disabledCallbacks:l=[],onDisabledCallbacksChange:a}=e;return(0,c.jsx)(ea,{value:s,onChange:t,disabledCallbacks:l,onDisabledCallbacksChange:a})};let e7=["logging"],e9=e=>e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(e=>{let[s]=e;return!e7.includes(s)})):{},se=e=>e&&"object"==typeof e&&Array.isArray(e.logging)?e.logging:[],ss=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return JSON.stringify(e9(e),null,s)};var st=e=>{let{onChange:s,value:t,className:l,accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,j.getGuardrailsList)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),i(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,c.jsx)("div",{children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:t,loading:n,className:l,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};function sl(e){var s,t,l,a,r,i,n,o;let{keyData:m,onCancel:u,onSubmit:x,teams:h,accessToken:p,userID:g,userRole:f,premiumUser:v=!1}=e,[y]=A.Z.useForm(),[N,Z]=(0,d.useState)([]),[w,k]=(0,d.useState)([]),S=null==h?void 0:h.find(e=>e.team_id===m.team_id),[C,L]=(0,d.useState)([]),[T,M]=(0,d.useState)([]),[D,F]=(0,d.useState)(!1),[R,z]=(0,d.useState)(Array.isArray(null===(s=m.metadata)||void 0===s?void 0:s.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]);(0,d.useEffect)(()=>{let e=async()=>{if(g&&f&&p)try{if(null===m.team_id){let e=(await (0,j.modelAvailableCall)(p,g,f)).data.map(e=>e.id);L(e)}else if(null==S?void 0:S.team_id){let e=await eG(g,f,p,S.team_id);L(Array.from(new Set([...S.models,...e])))}}catch(e){console.error("Error fetching models:",e)}};(async()=>{if(p)try{let e=await (0,j.getPromptsList)(p);k(e.prompts.map(e=>e.prompt_id))}catch(e){console.error("Failed to fetch prompts:",e)}})(),e()},[g,f,p,S,m.team_id]),(0,d.useEffect)(()=>{y.setFieldValue("disabled_callbacks",R)},[y,R]);let q=e=>e&&({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||null,B={...m,token:m.token||m.token_id,budget_duration:q(m.budget_duration),metadata:ss(m.metadata),guardrails:(null===(t=m.metadata)||void 0===t?void 0:t.guardrails)||[],prompts:(null===(l=m.metadata)||void 0===l?void 0:l.prompts)||[],vector_stores:(null===(a=m.object_permission)||void 0===a?void 0:a.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(r=m.object_permission)||void 0===r?void 0:r.mcp_servers)||[],accessGroups:(null===(i=m.object_permission)||void 0===i?void 0:i.mcp_access_groups)||[]},logging_settings:se(m.metadata),disabled_callbacks:Array.isArray(null===(n=m.metadata)||void 0===n?void 0:n.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]};return(0,d.useEffect)(()=>{var e,s,t,l,a,r;y.setFieldsValue({...m,token:m.token||m.token_id,budget_duration:q(m.budget_duration),metadata:ss(m.metadata),guardrails:(null===(e=m.metadata)||void 0===e?void 0:e.guardrails)||[],prompts:(null===(s=m.metadata)||void 0===s?void 0:s.prompts)||[],vector_stores:(null===(t=m.object_permission)||void 0===t?void 0:t.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(l=m.object_permission)||void 0===l?void 0:l.mcp_servers)||[],accessGroups:(null===(a=m.object_permission)||void 0===a?void 0:a.mcp_access_groups)||[]},logging_settings:se(m.metadata),disabled_callbacks:Array.isArray(null===(r=m.metadata)||void 0===r?void 0:r.litellm_disabled_callbacks)?X(m.metadata.litellm_disabled_callbacks):[]})},[m,y]),console.log("premiumUser:",v),(0,c.jsxs)(A.Z,{form:y,onFinish:x,initialValues:B,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[C.length>0&&(0,c.jsx)(I.default.Option,{value:"all-team-models",children:"All Team Models"}),C.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"daily",children:"Daily"}),(0,c.jsx)(I.default.Option,{value:"weekly",children:"Weekly"}),(0,c.jsx)(I.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,c.jsx)(O,{min:0})}),(0,c.jsx)(A.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,c.jsx)(A.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,c.jsx)(A.Z.Item,{label:"Guardrails",name:"guardrails",children:p&&(0,c.jsx)(st,{onChange:e=>{y.setFieldValue("guardrails",e)},accessToken:p})}),(0,c.jsx)(A.Z.Item,{label:"Prompts",name:"prompts",children:(0,c.jsx)(V.Z,{title:v?"":"Setting prompts by key is a premium feature",placement:"top",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},disabled:!v,placeholder:v?Array.isArray(null===(o=m.metadata)||void 0===o?void 0:o.prompts)&&m.metadata.prompts.length>0?"Current: ".concat(m.metadata.prompts.join(", ")):"Select or enter prompts":"Premium feature - Upgrade to set prompts by key",options:w.map(e=>({value:e,label:e}))})})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>y.setFieldValue("vector_stores",e),value:y.getFieldValue("vector_stores"),accessToken:p||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers / Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>y.setFieldValue("mcp_servers_and_groups",e),value:y.getFieldValue("mcp_servers_and_groups"),accessToken:p||"",placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Team ID",name:"team_id",children:(0,c.jsx)(I.default,{placeholder:"Select team",style:{width:"100%"},children:null==h?void 0:h.map(e=>(0,c.jsx)(I.default.Option,{value:e.team_id,children:"".concat(e.team_alias," (").concat(e.team_id,")")},e.team_id))})}),(0,c.jsx)(A.Z.Item,{label:"Logging Settings",name:"logging_settings",children:(0,c.jsx)(e8,{value:y.getFieldValue("logging_settings"),onChange:e=>y.setFieldValue("logging_settings",e),disabledCallbacks:R,onDisabledCallbacksChange:e=>{z(X(e)),y.setFieldValue("disabled_callbacks",e)}})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:10})}),(0,c.jsx)(A.Z.Item,{name:"token",hidden:!0,children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{name:"disabled_callbacks",hidden:!0,children:(0,c.jsx)(E.default,{})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{onClick:u,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]})}function sa(e){let{selectedToken:s,visible:t,onClose:l,accessToken:a,premiumUser:r,setAccessToken:i,onKeyUpdate:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,N]=(0,d.useState)(!1),[Z,w]=(0,d.useState)(!1),[I,T]=(0,d.useState)(null);(0,d.useEffect)(()=>{t&&s&&a&&(o.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""}),T(a),w(s.key_name===a))},[t,s,o,a]),(0,d.useEffect)(()=>{t||(u(null),N(!1),w(!1),T(null),o.resetFields())},[t,o]);let P=e=>{if(!e)return null;try{let s;let t=new Date;if(e.endsWith("s"))s=(0,eY.Z)(t,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eY.Z)(t,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eY.Z)(t,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}};(0,d.useEffect)(()=>{(null==x?void 0:x.duration)?g(P(x.duration)):g(null)},[null==x?void 0:x.duration]);let E=async()=>{if(s&&I){N(!0);try{let e=await o.validateFields(),t=await (0,j.regenerateKeyCall)(I,s.token||s.token_id,e);u(t.key),eo.Z.success("API Key regenerated successfully"),console.log("Full regenerate response:",t);let l={token:t.token||t.key_id||s.token,key_name:t.key,max_budget:e.max_budget,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,expires:e.duration?P(e.duration):s.expires,...t};console.log("Updated key data with new token:",l),Z&&(T(t.key),i&&i(t.key)),n&&n(l),N(!1)}catch(e){console.error("Error regenerating key:",e),eo.Z.fromBackend(e),N(!1)}}},M=()=>{u(null),N(!1),w(!1),T(null),o.resetFields(),l()};return(0,c.jsx)(L.Z,{title:"Regenerate API Key",open:t,onCancel:M,footer:m?[(0,c.jsx)(b.Z,{onClick:M,children:"Close"},"close")]:[(0,c.jsx)(b.Z,{onClick:M,className:"mr-2",children:"Cancel"},"cancel"),(0,c.jsx)(b.Z,{onClick:E,disabled:f,children:f?"Regenerating...":"Regenerate"},"regenerate")],children:m?(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Regenerated Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons,"," ",(0,c.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,c.jsxs)(v.Z,{numColSpan:1,children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"Key Alias:"}),(0,c.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,c.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,c.jsx)(k.Z,{className:"mt-3",children:"New API Key:"}),(0,c.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,c.jsx)("pre",{className:"break-words whitespace-normal",children:m})}),(0,c.jsx)(C.CopyToClipboard,{text:m,onCopy:()=>eo.Z.success("API Key copied to clipboard"),children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,c.jsxs)(A.Z,{form:o,layout:"vertical",onValuesChange:e=>{"duration"in e&&h(s=>({...s,duration:e.duration}))},children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,c.jsx)(_.Z,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),p&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",p]})]})})}var sr=t(79814),si=function(e){let{vectorStores:s,accessToken:t}=e,[l,a]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(t&&0!==s.length)try{let e=await (0,j.vectorStoreListCall)(t);e.data&&a(e.data.map(e=>({vector_store_id:e.vector_store_id,vector_store_name:e.vector_store_name})))}catch(e){console.error("Error fetching vector stores:",e)}})()},[t,s.length]);let r=e=>{let s=l.find(s=>s.vector_store_id===e);return s?"".concat(s.vector_store_name||s.vector_store_id," (").concat(s.vector_store_id,")"):e};return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sr.Z,{className:"h-4 w-4 text-blue-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Vector Stores"}),(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:s.length})]}),s.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map((e,s)=>(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-blue-50 border border-blue-200 text-blue-800 text-sm font-medium",children:r(e)},s))}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(sr.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No vector stores configured"})]})]})},sn=t(25327),so=function(e){let{mcpServers:s,mcpAccessGroups:l=[],accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(a&&s.length>0)try{let e=await (0,j.fetchMCPServers)(a);e&&Array.isArray(e)?i(e):e.data&&Array.isArray(e.data)&&i(e.data)}catch(e){console.error("Error fetching MCP servers:",e)}})()},[a,s.length]),(0,d.useEffect)(()=>{(async()=>{if(a&&l.length>0)try{let e=await Promise.resolve().then(t.bind(t,19250)).then(e=>e.fetchMCPAccessGroups(a));o(Array.isArray(e)?e:e.data||[])}catch(e){console.error("Error fetching MCP access groups:",e)}})()},[a,l.length]);let m=e=>{let s=r.find(s=>s.server_id===e);if(s){let t=e.length>7?"".concat(e.slice(0,3),"...").concat(e.slice(-4)):e;return"".concat(s.alias," (").concat(t,")")}return e},u=e=>e,x=[...s.map(e=>({type:"server",value:e})),...l.map(e=>({type:"accessGroup",value:e}))],h=x.length;return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sn.Z,{className:"h-4 w-4 text-gray-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"MCP Servers"}),(0,c.jsx)(eX.Z,{color:"gray",size:"xs",children:h})]}),h>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:x.map((e,s)=>"server"===e.type?(0,c.jsx)(V.Z,{title:"Full ID: ".concat(e.value),placement:"top",children:(0,c.jsx)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-blue-50 border border-blue-200 text-blue-800 text-sm font-medium cursor-help",children:m(e.value)})},s):(0,c.jsxs)("div",{className:"inline-flex items-center px-3 py-1.5 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm font-medium",children:[(0,c.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full mr-2"}),u(e.value)," ",(0,c.jsx)("span",{className:"ml-1 text-xs text-green-500",children:"(Access Group)"})]},s))}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(sn.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No MCP servers or access groups configured"})]})]})},sc=function(e){let{objectPermission:s,variant:t="card",className:l="",accessToken:a}=e,r=(null==s?void 0:s.vector_stores)||[],i=(null==s?void 0:s.mcp_servers)||[],n=(null==s?void 0:s.mcp_access_groups)||[],o=(0,c.jsxs)("div",{className:"card"===t?"grid grid-cols-1 md:grid-cols-2 gap-6":"space-y-4",children:[(0,c.jsx)(si,{vectorStores:r,accessToken:a}),(0,c.jsx)(so,{mcpServers:i,mcpAccessGroups:n,accessToken:a})]});return"card"===t?(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6 ".concat(l),children:[(0,c.jsx)("div",{className:"flex items-center gap-2 mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Object Permissions"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500",children:"Access control for Vector Stores and MCP Servers"})]})}),o]}):(0,c.jsxs)("div",{className:"".concat(l),children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900 mb-3",children:"Object Permissions"}),o]})},sd=function(e){let{loggingConfigs:s=[],disabledCallbacks:t=[],variant:l="card",className:a=""}=e,r=e=>{var s;return(null===(s=Object.entries($).find(s=>{let[t,l]=s;return l===e}))||void 0===s?void 0:s[0])||e},i=e=>{switch(e){case"success":return"green";case"failure":return"red";case"success_and_failure":return"blue";default:return"gray"}},n=e=>{switch(e){case"success":return"Success Only";case"failure":return"Failure Only";case"success_and_failure":return"Success & Failure";default:return e}},o=(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(J.Z,{className:"h-4 w-4 text-blue-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Logging Integrations"}),(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:s.length})]}),s.length>0?(0,c.jsx)("div",{className:"space-y-3",children:s.map((e,s)=>{var t;let l=r(e.callback_name),a=null===(t=et[l])||void 0===t?void 0:t.logo;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg bg-blue-50 border border-blue-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[a?(0,c.jsx)("img",{src:a,alt:l,className:"w-5 h-5 object-contain"}):(0,c.jsx)(J.Z,{className:"h-5 w-5 text-gray-400"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-blue-800",children:l}),(0,c.jsxs)(k.Z,{className:"text-xs text-blue-600",children:[Object.keys(e.callback_vars).length," parameters configured"]})]})]}),(0,c.jsx)(eX.Z,{color:i(e.callback_type),size:"sm",children:n(e.callback_type)})]},s)})}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(J.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No logging integrations configured"})]})]}),(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(H.Z,{className:"h-4 w-4 text-red-600"}),(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Disabled Callbacks"}),(0,c.jsx)(eX.Z,{color:"red",size:"xs",children:t.length})]}),t.length>0?(0,c.jsx)("div",{className:"space-y-3",children:t.map((e,s)=>{var t;let l=Q[e]||e,a=null===(t=et[l])||void 0===t?void 0:t.logo;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg bg-red-50 border border-red-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[a?(0,c.jsx)("img",{src:a,alt:l,className:"w-5 h-5 object-contain"}):(0,c.jsx)(H.Z,{className:"h-5 w-5 text-gray-400"}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium text-red-800",children:l}),(0,c.jsx)(k.Z,{className:"text-xs text-red-600",children:"Disabled for this key"})]})]}),(0,c.jsx)(eX.Z,{color:"red",size:"sm",children:"Disabled"})]},s)})}):(0,c.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 border border-gray-200",children:[(0,c.jsx)(H.Z,{className:"h-4 w-4 text-gray-400"}),(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"No callbacks disabled"})]})]})]});return"card"===l?(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-6 ".concat(a),children:[(0,c.jsx)("div",{className:"flex items-center gap-2 mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Logging Settings"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500",children:"Active logging integrations and disabled callbacks for this key"})]})}),o]}):(0,c.jsxs)("div",{className:"".concat(a),children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900 mb-3",children:"Logging Settings"}),o]})},sm=t(30401),su=t(78867),sx=t(85968);function sh(e){var s,t,l,a,r;let{keyId:i,onClose:n,keyData:o,accessToken:m,userID:u,userRole:x,teams:h,onKeyDataUpdate:p,onDelete:g,premiumUser:f,setAccessToken:v,backButtonText:_="Back to Keys"}=e,[N,Z]=(0,d.useState)(!1),[w]=A.Z.useForm(),[C,I]=(0,d.useState)(!1),[L,T]=(0,d.useState)(""),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)({}),[F,R]=(0,d.useState)(o),[z,U]=(0,d.useState)(null),[q,B]=(0,d.useState)(!1);if((0,d.useEffect)(()=>{o&&R(o)},[o]),(0,d.useEffect)(()=>{if(q){let e=setTimeout(()=>{B(!1)},5e3);return()=>clearTimeout(e)}},[q]),!F)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:n,className:"mb-4",children:_}),(0,c.jsx)(k.Z,{children:"Key not found"})]});let K=async e=>{try{var s,t,l,a;if(!m)return;let r=e.token;if(e.key=r,void 0!==e.vector_stores&&(e.object_permission={...F.object_permission,vector_stores:e.vector_stores||[]},delete e.vector_stores),void 0!==e.mcp_servers_and_groups){let{servers:s,accessGroups:t}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};e.object_permission={...F.object_permission,mcp_servers:s||[],mcp_access_groups:t||[]},delete e.mcp_servers_and_groups}if(e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{},...e.logging_settings?{logging:e.logging_settings}:{},...(null===(t=e.disabled_callbacks)||void 0===t?void 0:t.length)>0?{litellm_disabled_callbacks:ee(e.disabled_callbacks)}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),eo.Z.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{},...e.logging_settings?{logging:e.logging_settings}:{},...(null===(a=e.disabled_callbacks)||void 0===a?void 0:a.length)>0?{litellm_disabled_callbacks:ee(e.disabled_callbacks)}:{}};delete e.logging_settings,e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let i=await (0,j.keyUpdateCall)(m,e);R(e=>e?{...e,...i}:void 0),p&&p(i),eo.Z.success("Key updated successfully"),Z(!1)}catch(e){eo.Z.fromBackend((0,sx.O)(e)),console.error("Error updating key:",e)}},H=async()=>{try{if(!m)return;await (0,j.keyDeleteCall)(m,F.token||F.token_id),eo.Z.success("Key deleted successfully"),g&&g(),n()}catch(e){console.error("Error deleting the key:",e),eo.Z.fromBackend(e)}T("")},J=async(e,s)=>{await eM(e)&&(D(e=>({...e,[s]:!0})),setTimeout(()=>{D(e=>({...e,[s]:!1}))},2e3))},Y=e=>{let s=new Date(e),t=s.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),l=s.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return"".concat(t," at ").concat(l)};return(0,c.jsxs)("div",{className:"w-full h-screen p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:n,className:"mb-4",children:_}),(0,c.jsx)(S.Z,{children:F.key_alias||"API Key"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer mb-2 space-y-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-xs text-gray-400 uppercase tracking-wide mt-2",children:"Key ID"}),(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono text-sm",children:F.token_id||F.token})]}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:O["key-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>J(F.token_id||F.token,"key-id"),className:"ml-2 transition-all duration-200".concat(O["key-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]}),(0,c.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-500",children:F.updated_at&&F.updated_at!==F.created_at?"Updated: ".concat(Y(F.updated_at)):"Created: ".concat(Y(F.created_at))}),q&&(0,c.jsx)(eX.Z,{color:"green",size:"xs",className:"animate-pulse",children:"Recently Regenerated"}),z&&(0,c.jsx)(eX.Z,{color:"blue",size:"xs",children:"Regenerated"})]})]}),x&&eI.LQ.includes(x)&&(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(V.Z,{title:f?"":"This is a LiteLLM Enterprise feature, and requires a valid key to use.",children:(0,c.jsx)("span",{className:"inline-block",children:(0,c.jsx)(b.Z,{icon:e3.Z,variant:"secondary",onClick:()=>M(!0),className:"flex items-center",disabled:!f,children:"Regenerate Key"})})}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>I(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,c.jsx)(sa,{selectedToken:F,visible:E,onClose:()=>M(!1),accessToken:m,premiumUser:f,setAccessToken:v,onKeyUpdate:e=>{R(s=>{if(s)return{...s,...e,created_at:new Date().toLocaleString()}}),U(new Date),B(!0),p&&p({...e,created_at:new Date().toLocaleString()})}}),C&&(()=>{let e=(null==F?void 0:F.key_alias)||(null==F?void 0:F.token_id)||"API Key",s=L===e;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Key"}),(0,c.jsx)("button",{onClick:()=>{I(!1),T("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.082 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"Warning: You are about to delete this API key."}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"This action is irreversible and will immediately revoke access for any applications using this key."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to delete this API key?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:e})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:L,onChange:e=>T(e.target.value),placeholder:"Enter key name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{I(!1),T("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:H,disabled:!s,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(s?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Delete Key"})]})]})})})(),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Spend"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(F.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null!==F.max_budget?"$".concat(eE(F.max_budget)):"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",null!==F.tpm_limit?F.tpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",null!==F.rpm_limit?F.rpm_limit:"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:F.models&&F.models.length>0?F.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s)):(0,c.jsx)(k.Z,{children:"No models specified"})})]}),(0,c.jsx)(G.Z,{children:(0,c.jsx)(sc,{objectPermission:F.object_permission,variant:"inline",accessToken:m})}),(0,c.jsx)(sd,{loggingConfigs:se(F.metadata),disabledCallbacks:Array.isArray(null===(s=F.metadata)||void 0===s?void 0:s.litellm_disabled_callbacks)?X(F.metadata.litellm_disabled_callbacks):[],variant:"card"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Key Settings"}),!N&&x&&eI.LQ.includes(x)&&(0,c.jsx)(b.Z,{variant:"light",onClick:()=>Z(!0),children:"Edit Settings"})]}),N?(0,c.jsx)(sl,{keyData:F,onCancel:()=>Z(!1),onSubmit:K,teams:h,accessToken:m,userID:u,userRole:x,premiumUser:f}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Key ID"}),(0,c.jsx)(k.Z,{className:"font-mono",children:F.token_id||F.token})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Key Alias"}),(0,c.jsx)(k.Z,{children:F.key_alias||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Secret Key"}),(0,c.jsx)(k.Z,{className:"font-mono",children:F.key_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)(k.Z,{children:F.team_id||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization"}),(0,c.jsx)(k.Z,{children:F.organization_id||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:Y(F.created_at)})]}),z&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Regenerated"}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(k.Z,{children:Y(z)}),(0,c.jsx)(eX.Z,{color:"green",size:"xs",children:"Recent"})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Expires"}),(0,c.jsx)(k.Z,{children:F.expires?Y(F.expires):"Never"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Spend"}),(0,c.jsxs)(k.Z,{children:["$",eE(F.spend,4)," USD"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget"}),(0,c.jsx)(k.Z,{children:null!==F.max_budget?"$".concat(eE(F.max_budget,2)):"Unlimited"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompts"}),(0,c.jsx)(k.Z,{children:Array.isArray(null===(t=F.metadata)||void 0===t?void 0:t.prompts)&&F.metadata.prompts.length>0?F.metadata.prompts.map((e,s)=>(0,c.jsx)("span",{className:"px-2 mr-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"No prompts specified"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:F.models&&F.models.length>0?F.models.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,c.jsx)(k.Z,{children:"No models specified"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)(k.Z,{children:["TPM: ",null!==F.tpm_limit?F.tpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",null!==F.rpm_limit?F.rpm_limit:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Max Parallel Requests:"," ",null!==F.max_parallel_requests?F.max_parallel_requests:"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Model TPM Limits:"," ",(null===(l=F.metadata)||void 0===l?void 0:l.model_tpm_limit)?JSON.stringify(F.metadata.model_tpm_limit):"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["Model RPM Limits:"," ",(null===(a=F.metadata)||void 0===a?void 0:a.model_rpm_limit)?JSON.stringify(F.metadata.model_rpm_limit):"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:ss(F.metadata)})]}),(0,c.jsx)(sc,{objectPermission:F.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:m}),(0,c.jsx)(sd,{loggingConfigs:se(F.metadata),disabledCallbacks:Array.isArray(null===(r=F.metadata)||void 0===r?void 0:r.litellm_disabled_callbacks)?X(F.metadata.litellm_disabled_callbacks):[],variant:"inline",className:"pt-4 border-t border-gray-200"})]})]})})]})]})]})}var sp=t(2356),sg=e=>{let{options:s,onApplyFilters:t,onResetFilters:l,initialValues:a={},buttonLabel:r="Filters"}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(a),[u,x]=(0,d.useState)({}),[h,p]=(0,d.useState)({}),[g,j]=(0,d.useState)({}),[f,v]=(0,d.useState)({}),y=(0,d.useCallback)(eC()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let t=await s.searchFn(e);x(e=>({...e,[s.name]:t}))}catch(e){console.error("Error searching:",e),x(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),b=(0,d.useCallback)(async e=>{if(e.isSearchable&&e.searchFn&&!f[e.name]){p(s=>({...s,[e.name]:!0})),v(s=>({...s,[e.name]:!0}));try{let s=await e.searchFn("");x(t=>({...t,[e.name]:s}))}catch(s){console.error("Error loading initial options:",s),x(s=>({...s,[e.name]:[]}))}finally{p(s=>({...s,[e.name]:!1}))}}},[f]);(0,d.useEffect)(()=>{i&&s.forEach(e=>{e.isSearchable&&!f[e.name]&&b(e)})},[i,s,b,f]);let _=(e,s)=>{let l={...o,[e]:s};m(l),t(l)},N=(e,s)=>{e&&s.isSearchable&&!f[s.name]&&b(s)};return(0,c.jsxs)("div",{className:"w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(sp.Z,{className:"h-4 w-4"}),onClick:()=>n(!i),className:"flex items-center gap-2",children:r}),(0,c.jsx)(P.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),m(e),l()},children:"Reset Filters"})]}),i&&(0,c.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","End User","Key Hash","Model"].map(e=>{let t=s.find(s=>s.label===e||s.name===e);return t?(0,c.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,c.jsx)("label",{className:"text-sm text-gray-600",children:t.label||t.name}),t.isSearchable?(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(t.label||t.name,"..."),value:o[t.name]||void 0,onChange:e=>_(t.name,e),onDropdownVisibleChange:e=>N(e,t),onSearch:e=>{j(s=>({...s,[t.name]:e})),t.searchFn&&y(e,t)},filterOption:!1,loading:h[t.name],options:u[t.name]||[],allowClear:!0,notFoundContent:h[t.name]?"Loading...":"No results found"}):t.options?(0,c.jsx)(I.default,{className:"w-full",placeholder:"Select ".concat(t.label||t.name,"..."),value:o[t.name]||void 0,onChange:e=>_(t.name,e),allowClear:!0,children:t.options.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,children:e.label},e.value))}):(0,c.jsx)(E.default,{className:"w-full",placeholder:"Enter ".concat(t.label||t.name,"..."),value:o[t.name]||"",onChange:e=>_(t.name,e.target.value),allowClear:!0})]},t.name):null})})]})},sj=t(16593);let sf=async e=>{if(!e)return[];try{let s=[],t=1,l=!0;for(;l;){let a=await (0,j.keyListCall)(e,null,"",null,null,null,t,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],t{if(!e)return[];try{let t=[],l=1,a=!0;for(;a;){let r=await (0,j.teamListCall)(e,s||null,null);t=[...t,...r],l{if(!e)return[];try{let s=[],t=1,l=!0;for(;l;){let a=await (0,j.organizationListCall)(e);s=[...s,...a],t{let[e,s]=(0,d.useState)("http://localhost:4000");return(0,d.useEffect)(()=>{{let{protocol:e,host:t}=window.location;s("".concat(e,"//").concat(t))}},[]),e};var s_=t(71594),sN=t(24525),sZ=t(47323),sw=t(21626),sk=t(97214),sS=t(28241),sC=t(58834),sI=t(69552),sA=t(71876),sL=t(86462),sT=t(47686),sP=t(44633),sE=t(49084);function sM(e){let{keys:s,setKeys:t,isLoading:l=!1,pagination:a,onPageChange:r,pageSize:i=50,teams:n,selectedTeam:o,setSelectedTeam:m,selectedKeyAlias:u,setSelectedKeyAlias:x,accessToken:h,userID:p,userRole:g,organizations:f,setCurrentOrg:v,refresh:y,onSortChange:_,currentSort:N,premiumUser:Z,setAccessToken:w}=e,[S,C]=(0,d.useState)(null),[I,A]=(0,d.useState)([]),[L,T]=d.useState(()=>N?[{id:N.sortBy,desc:"desc"===N.sortOrder}]:[{id:"created_at",desc:!0}]),[P,E]=(0,d.useState)({}),{filters:M,filteredKeys:O,allKeyAliases:D,allTeams:R,allOrganizations:z,handleFilterChange:U,handleFilterReset:q}=function(e){let{keys:s,teams:t,organizations:l,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[i,n]=(0,d.useState)(r),[o,c]=(0,d.useState)(t||[]),[m,u]=(0,d.useState)(l||[]),[x,h]=(0,d.useState)(s),p=(0,d.useRef)(0),g=(0,d.useCallback)(eC()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let t=await (0,j.keyListCall)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&t&&(h(t.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(t)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,d.useEffect)(()=>{if(!s){h([]);return}let e=[...s];i["Team ID"]&&(e=e.filter(e=>e.team_id===i["Team ID"])),i["Organization ID"]&&(e=e.filter(e=>e.organization_id===i["Organization ID"])),h(e)},[s,i]),(0,d.useEffect)(()=>{let e=async()=>{let e=await sv(a);e.length>0&&c(e);let s=await sy(a);s.length>0&&u(s)};a&&e()},[a]);let f=(0,sj.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await sf(a)},enabled:!!a}).data||[];return(0,d.useEffect)(()=>{t&&t.length>0&&c(e=>e.length{l&&l.length>0&&u(e=>e.length{n({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...i,...e})},handleFilterReset:()=>{n(r),g(r)}}}({keys:s,teams:n,organizations:f,accessToken:h});(0,d.useEffect)(()=>{if(h){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{A((await (0,j.userListCall)(h,e,1,100)).users)})()}},[h,s]),(0,d.useEffect)(()=>{if(y){let e=()=>{y()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[y]);let B=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,c.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.getValue(),children:(0,c.jsx)(b.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:()=>C(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,c.jsx)(V.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,c.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:t}=e,l=t(),a=null==n?void 0:n.find(e=>e.team_id===l);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,c.jsx)(V.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),t=I.find(e=>e.user_id===s);return(null==t?void 0:t.user_email)?(0,c.jsx)(V.Z,{title:null==t?void 0:t.user_email,children:(0,c.jsxs)("span",{children:[null==t?void 0:t.user_email.slice(0,20),"..."]})}):"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s&&s.length>15?(0,c.jsx)(V.Z,{title:s,children:(0,c.jsxs)("span",{children:[s.slice(0,7),"..."]})}):s||"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>{let s=e.getValue();return s&&s.length>15?(0,c.jsx)(V.Z,{title:s,children:(0,c.jsxs)("span",{children:[s.slice(0,7),"..."]})}):s}},{id:"updated_at",accessorKey:"updated_at",header:"Updated At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>eE(e.getValue(),4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>{let s=e.getValue();return null===s?"Unlimited":"$".concat(eE(s))}},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,c.jsx)("div",{className:"flex flex-col py-2",children:Array.isArray(s)?(0,c.jsx)("div",{className:"flex flex-col",children:0===s.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[s.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:P[e.row.id]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{E(s=>({...s,[e.row.id]:!s[e.row.id]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[s.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),s.length>3&&!P[e.row.id]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",s.length-3," ",s.length-3==1?"more model":"more models"]})}),P[e.row.id]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:s.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:["TPM: ",null!==t.tpm_limit?t.tpm_limit:"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",null!==t.rpm_limit?t.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let K=(0,s_.b7)({data:O,columns:B.filter(e=>"expander"!==e.id),state:{sorting:L},onSortingChange:e=>{let s="function"==typeof e?e(L):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),T(s),s&&s.length>0){let e=s[0],t=e.id,l=e.desc?"desc":"asc";console.log("sortBy: ".concat(t,", sortOrder: ").concat(l)),U({...M,"Sort By":t,"Sort Order":l}),null==_||_(t,l)}},getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0,manualSorting:!1});return d.useEffect(()=>{N&&T([{id:N.sortBy,desc:"desc"===N.sortOrder}])},[N]),(0,c.jsx)("div",{className:"w-full h-full overflow-hidden",children:S?(0,c.jsx)(sh,{keyId:S,onClose:()=>C(null),keyData:O.find(e=>e.token===S),onKeyDataUpdate:e=>{t(s=>s.map(s=>s.token===e.token?eP(s,e):s)),y&&y()},onDelete:()=>{t(e=>e.filter(e=>e.token!==S)),y&&y()},accessToken:h,userID:p,userRole:g,teams:R,premiumUser:Z,setAccessToken:w}):(0,c.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,c.jsx)("div",{className:"w-full mb-6",children:(0,c.jsx)(sg,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>R&&0!==R.length?R.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>z&&0!==z.length?z.filter(s=>{var t,l;return null!==(l=null===(t=s.organization_id)||void 0===t?void 0:t.toLowerCase().includes(e.toLowerCase()))&&void 0!==l&&l}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>D.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:U,initialValues:M,onResetFilters:q})}),(0,c.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,c.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing"," ",l?"...":"".concat((a.currentPage-1)*i+1," - ").concat(Math.min(a.currentPage*i,a.totalCount))," ","of ",l?"...":a.totalCount," results"]}),(0,c.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",l?"...":a.currentPage," of ",l?"...":a.totalPages]}),(0,c.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:l||1===a.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,c.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:l||a.currentPage===a.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,c.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:K.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:l?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:B.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):O.length>0?K.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("models"===e.column.id&&e.getValue().length>3?"px-0":""),children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:B.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}var sO=e=>{let{userID:s,userRole:t,accessToken:l,selectedTeam:a,setSelectedTeam:r,data:i,setData:n,teams:o,premiumUser:m,currentOrg:u,organizations:x,setCurrentOrg:h,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:f,setAccessToken:N}=e,[Z,w]=(0,d.useState)(!1),[I,T]=(0,d.useState)(!1),[P,E]=(0,d.useState)(null),[M,O]=(0,d.useState)(""),[F,R]=(0,d.useState)(null),[z,U]=(0,d.useState)(null),[q,B]=(0,d.useState)((null==a?void 0:a.team_id)||"");(0,d.useEffect)(()=>{B((null==a?void 0:a.team_id)||"")},[a]);let{keys:V,isLoading:K,error:G,pagination:H,refresh:J,setKeys:Y}=e$({selectedTeam:a||void 0,currentOrg:u,selectedKeyAlias:p,accessToken:l||"",createClicked:f}),[W,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(!1),[ee,es]=(0,d.useState)(null),[et,el]=(0,d.useState)([]),ea=new Set,[er,ei]=(0,d.useState)(!1),[en,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(null),[eu,ex]=(0,d.useState)(null),[eh]=A.Z.useForm(),[ep,eg]=(0,d.useState)(null),[ej,ef]=(0,d.useState)(ea),[ev,ey]=(0,d.useState)([]);(0,d.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",ee),(null==eu?void 0:eu.duration)?eg((e=>{if(!e)return null;try{let s;let t=new Date;if(e.endsWith("s"))s=(0,eY.Z)(t,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eY.Z)(t,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eY.Z)(t,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(eu.duration)):eg(null),console.log("calculateNewExpiryTime:",ep)},[ee,null==eu?void 0:eu.duration]),(0,d.useEffect)(()=>{(async()=>{try{if(null===s||null===t||null===l)return;let e=await D(s,t,l);e&&el(e)}catch(e){eo.Z.error({description:"Error fetching user models"})}})()},[l,s,t]),(0,d.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,t)=>{let l=s.team_id;e.add(l)}),ef(e)}},[o]);let eb=async()=>{if(null!=P&&null!=V){try{if(!l)return;await (0,j.keyDeleteCall)(l,P);let e=V.filter(e=>e.token!==P);Y(e)}catch(e){eo.Z.error({description:"Error deleting the key"})}T(!1),E(null),O("")}},e_=()=>{T(!1),E(null),O("")},eN=(e,s)=>{ex(t=>({...t,[e]:s}))},eZ=async()=>{if(!m){eo.Z.warning({description:"Regenerate API Key is an Enterprise feature. Please upgrade to use this feature."});return}if(null!=ee)try{let e=await eh.validateFields();if(!l)return;let s=await (0,j.regenerateKeyCall)(l,ee.token||ee.token_id,e);if(em(s.key),i){let t=i.map(t=>t.token===(null==ee?void 0:ee.token)?{...t,key_name:s.key_name,...e}:t);n(t)}ec(!1),eh.resetFields(),eo.Z.success({description:"API Key regenerated successfully"})}catch(e){console.error("Error regenerating key:",e),eo.Z.error({description:"Failed to regenerate API Key"})}};return(0,c.jsxs)("div",{children:[(0,c.jsx)(sM,{keys:V,setKeys:Y,isLoading:K,pagination:H,onPageChange:e=>{J({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:l,userID:s,userRole:t,organizations:x,setCurrentOrg:h,refresh:J,selectedKeyAlias:p,setSelectedKeyAlias:g,premiumUser:m,setAccessToken:N}),I&&(()=>{let e=null==V?void 0:V.find(e=>e.token===P),s=(null==e?void 0:e.key_alias)||(null==e?void 0:e.token_id)||P,t=M===s;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Key"}),(0,c.jsx)("button",{onClick:()=>{e_(),O("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.082 16.5c-.77.833.192 2.5 1.732 2.5z"})})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"Warning: You are about to delete this API key."}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"This action is irreversible and will immediately revoke access for any applications using this key."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to delete this API key?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:s})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:M,onChange:e=>O(e.target.value),placeholder:"Enter key name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{e_(),O("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:eb,disabled:!t,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(t?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Delete Key"})]})]})})})(),(0,c.jsx)(L.Z,{title:"Regenerate API Key",visible:en,onCancel:()=>{ec(!1),eh.resetFields()},footer:[(0,c.jsx)(b.Z,{onClick:()=>{ec(!1),eh.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,c.jsx)(b.Z,{onClick:eZ,disabled:!m,children:m?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:m?(0,c.jsxs)(A.Z,{form:eh,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&eN("duration",e.duration)},children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,c.jsx)(_.Z,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,c.jsx)(eW.Z,{style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==ee?void 0:ee.expires)!=null?new Date(ee.expires).toLocaleString():"Never"]}),ep&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",ep]})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,c.jsx)(b.Z,{variant:"primary",className:"mb-2",children:(0,c.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ed&&(0,c.jsx)(L.Z,{visible:!!ed,onCancel:()=>em(null),footer:[(0,c.jsx)(b.Z,{onClick:()=>em(null),children:"Close"},"close")],children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:"Regenerated Key"}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons,"," ",(0,c.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,c.jsxs)(v.Z,{numColSpan:1,children:[(0,c.jsx)(k.Z,{className:"mt-3",children:"Key Alias:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==ee?void 0:ee.key_alias)||"No alias set"})}),(0,c.jsx)(k.Z,{className:"mt-3",children:"New API Key:"}),(0,c.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,c.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ed})}),(0,c.jsx)(C.CopyToClipboard,{text:ed,onCopy:()=>eo.Z.success({description:"API Key copied to clipboard"}),children:(0,c.jsx)(b.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sD=t(12011),sF=t(3914),sR=e=>{let{userID:s,userRole:t,teams:l,keys:a,setUserRole:r,userEmail:i,setUserEmail:n,setTeams:o,setKeys:x,premiumUser:h,organizations:p,addKey:g,createClicked:b}=e,[_,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(null),k=(0,m.useSearchParams)(),S=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),C=k.get("invitation_id"),[I,A]=(0,d.useState)(null),[L,T]=(0,d.useState)(null),[P,E]=(0,d.useState)([]),[M,O]=(0,d.useState)(null),[D,F]=(0,d.useState)(null),[R,z]=(0,d.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,d.useEffect)(()=>{if(S){let e=(0,u.o)(S);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";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:",s),r(s)}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&I&&t&&!a&&!_){let e=sessionStorage.getItem("userModels"+s);e?E(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(Z))),(async()=>{try{let e=await (0,j.getProxyUISettings)(I);O(e);let l=await (0,j.userInfoCall)(I,s,t,!1,null,null);N(l.user_info),console.log("userSpendData: ".concat(JSON.stringify(_))),(null==l?void 0:l.teams[0].keys)?x(l.keys.concat(l.teams.filter(e=>"Admin"===t||e.user_id===s).flatMap(e=>e.keys))):x(l.keys),sessionStorage.setItem("userData"+s,JSON.stringify(l.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(l.user_info));let a=(await (0,j.modelAvailableCall)(I,s,t)).data.map(e=>e.id);console.log("available_model_names:",a),E(a),console.log("userModels:",P),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&U()}})(),f(I,s,t,Z,o))}},[s,S,I,a,t]),(0,d.useEffect)(()=>{I&&(async()=>{try{let e=await (0,j.keyInfoCall)(I,[I]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&U()}})()},[I]),(0,d.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(Z),", accessToken: ").concat(I,", userID: ").concat(s,", userRole: ").concat(t)),I&&(console.log("fetching teams"),f(I,s,t,Z,o))},[Z]),(0,d.useEffect)(()=>{if(null!==a&&null!=D&&null!==D.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))D.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===D.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),T(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;T(e)}},[D]),null!=C)return(0,c.jsx)(sD.default,{});function U(){(0,sF.b)();let e=(0,j.getProxyBaseUrl)();console.log("proxyBaseUrl:",e);let s=e?"".concat(e,"/sso/key/generate"):"/sso/key/generate";return console.log("Full URL:",s),window.location.href=s,null}if(null==S)return console.log("All cookies before redirect:",document.cookie),U(),null;try{let e=(0,u.o)(S);console.log("Decoded token:",e);let s=e.exp,t=Math.floor(Date.now()/1e3);if(s&&t>=s)return console.log("Token expired, redirecting to login"),U(),null}catch(e){return console.error("Error decoding token:",e),(0,sF.b)(),U(),null}if(null==I)return null;if(null==s)return(0,c.jsx)("h1",{children:"User ID is not set"});if(null==t&&r("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",D),console.log("All cookies after redirect:",document.cookie),(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,c.jsx)(eJ,{userID:s,team:D,teams:l,userRole:t,accessToken:I,data:a,addKey:g,premiumUser:h},D?D.team_id:null),(0,c.jsx)(sO,{userID:s,userRole:t,accessToken:I,selectedTeam:D||null,setSelectedTeam:F,selectedKeyAlias:R,setSelectedKeyAlias:z,data:a,setData:x,premiumUser:h,teams:l,currentOrg:Z,setCurrentOrg:w,organizations:p,createClicked:b,setAccessToken:A})]})})})},sz=t(97765),sU=t(42673);let sq=async(e,s,t)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let t=e.custom_llm_provider,l=sU.fK[t]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let t=[];for(let l of s){let s={},a={},r=l.public_name;for(let[t,r]of(s.model=l.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),s.model=l.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==t&&"pricing_model"!==t&&"cache_control"!==t){if("model_name"==t)s.model=r;else if("custom_llm_provider"==t){console.log("custom_llm_provider:",r);let e=sU.fK[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==t)continue;else if("base_model"===t)a[t]=r;else if("team_id"===t)a.team_id=r;else if("model_access_group"===t)a.access_groups=r;else if("mode"==t)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===t)s.model=r;else if("litellm_extra_params"==t){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw eo.Z.fromBackend("Failed to parse LiteLLM Extra Params: "+e),Error("Failed to parse litellm_extra_params: "+e)}for(let[t,l]of Object.entries(e))s[t]=l}}else if("model_info_params"==t){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw eo.Z.fromBackend("Failed to parse LiteLLM Extra Params: "+e),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,t]of Object.entries(e))a[s]=t}}else if("input_cost_per_token"===t||"output_cost_per_token"===t||"input_cost_per_second"===t){r&&(s[t]=Number(r));continue}else s[t]=r}t.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return t}catch(e){eo.Z.fromBackend("Failed to create model: "+e)}},sB=async(e,s,t,l)=>{try{let a=await sq(e,s,t);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:t,modelInfoObj:l,modelName:a}=e,r={model_name:a,litellm_params:t,model_info:l},i=await (0,j.modelCreateCall)(s,r);console.log("response for model create call: ".concat(i.data))}l&&l(),t.resetFields()}catch(e){eo.Z.fromBackend("Failed to add model: "+e)}};var sV=t(53410),sK=t(47451),sG=t(69410);let{Link:sH}=en.default,sJ={[sU.Cl.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[sU.Cl.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[sU.Cl.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[sU.Cl.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[sU.Cl.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Dashscope]:[{key:"api_key",label:"Dashscope API Key",type:"password",required:!0},{key:"api_base",label:"API Base",placeholder:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",defaultValue:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",required:!0,tooltip:"The base URL for your Dashscope server. Defaults to https://dashscope-intl.aliyuncs.com/compatible-mode/v1 if not specified."}],[sU.Cl.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[sU.Cl.SageMaker]:[{key:"aws_access_key_id",label:"AWS Access Key ID",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",type:"password",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!1,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[sU.Cl.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[sU.Cl.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[sU.Cl.Deepgram]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.ElevenLabs]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[sU.Cl.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.AIML]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.GradientAI]:[{key:"api_base",label:"GradientAI Endpoint",placeholder:"https://...",required:!1},{key:"api_key",label:"GradientAI API Key",type:"password",required:!0}],[sU.Cl.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}],[sU.Cl.Hosted_Vllm]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[sU.Cl.Voyage]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.JinaAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.VolcEngine]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[sU.Cl.DeepInfra]:[{key:"api_key",label:"API Key",type:"password",required:!0}]};var sY=e=>{let{selectedProvider:s,uploadProps:t}=e,l=sU.Cl[s],a=A.Z.useFormInstance(),r=d.useMemo(()=>sJ[l]||[],[l]),i={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,c.jsx)(c.Fragment,{children:r.map(e=>{var s;return(0,c.jsxs)(d.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,c.jsx)(I.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,c.jsx)(ed.default,{...i,onChange:s=>{(null==t?void 0:t.onChange)&&t.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(ej.Z,{}),children:"Click to Upload"})}):(0,c.jsx)(_.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,c.jsx)(sK.Z,{children:(0,c.jsx)(sG.Z,{children:(0,c.jsx)(k.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,c.jsx)(sH,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})},sW=t(31283);let{Title:s$,Link:sQ}=en.default;var sX=e=>{let{isVisible:s,onCancel:t,onAddCredential:l,onUpdateCredential:a,uploadProps:r,addOrEdit:i,existingCredential:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(sU.Cl.OpenAI),[x,h]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{n&&(o.setFieldsValue({credential_name:n.credential_name,custom_llm_provider:n.credential_info.custom_llm_provider,api_base:n.credential_values.api_base,api_version:n.credential_values.api_version,base_model:n.credential_values.base_model,api_key:n.credential_values.api_key}),u(n.credential_info.custom_llm_provider))},[n]),(0,c.jsx)(L.Z,{title:"add"===i?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{t(),o.resetFields()},footer:null,width:600,children:(0,c.jsxs)(A.Z,{form:o,onFinish:e=>{let s=Object.entries(e).reduce((e,s)=>{let[t,l]=s;return""!==l&&null!=l&&(e[t]=l),e},{});"add"===i?l(s):a(s),o.resetFields()},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==n?void 0:n.credential_name,children:(0,c.jsx)(sW.o,{placeholder:"Enter a friendly name for these credentials",disabled:null!=n&&!!n.credential_name})}),(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,c.jsx)(I.default,{showSearch:!0,onChange:e=>{u(e),o.setFieldValue("custom_llm_provider",e)},children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(sY,{selectedProvider:m,uploadProps:r}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(sQ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:()=>{t(),o.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"add"===i?"Add Credential":"Update Credential"})]})]})]})})},s0=e=>{let{isVisible:s,onCancel:t,onConfirm:l,credentialName:a}=e,[r,i]=(0,d.useState)(""),n=r===a,o=()=>{i(""),t()};return(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(e_.Z,{className:"h-6 w-6 text-red-600 mr-2"}),"Delete Credential"]}),open:s,footer:null,onCancel:o,closable:!0,destroyOnClose:!0,maskClosable:!1,children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)(e_.Z,{className:"h-5 w-5"})}),(0,c.jsx)("div",{children:(0,c.jsx)("p",{className:"text-base font-medium text-red-600",children:"This action cannot be undone and may break existing integrations."})})]}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsxs)("span",{className:"underline italic",children:["'",a,"'"]})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:r,onChange:e=>i(e.target.value),placeholder:"Enter credential name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(b.Z,{onClick:o,variant:"secondary",className:"mr-2",children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>{n&&(i(""),l())},color:"red",className:"focus:ring-red-500",disabled:!n,children:"Delete Credential"})]})]})})},s1=e=>{let{accessToken:s,uploadProps:t,credentialList:l,fetchCredentials:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p]=A.Z.useForm(),g=["credential_name","custom_llm_provider"],f=async e=>{if(!s)return;let t=Object.entries(e).filter(e=>{let[s]=e;return!g.includes(s)}).reduce((e,s)=>{let[t,l]=s;return{...e,[t]:l}},{}),l={credential_name:e.credential_name,credential_values:t,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,j.credentialUpdateCall)(s,e.credential_name,l),eo.Z.success("Credential updated successfully"),o(!1),a(s)},v=async e=>{if(!s)return;let t=Object.entries(e).filter(e=>{let[s]=e;return!g.includes(s)}).reduce((e,s)=>{let[t,l]=s;return{...e,[t]:l}},{}),l={credential_name:e.credential_name,credential_values:t,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,j.credentialCreateCall)(s,l),eo.Z.success("Credential added successfully"),i(!1),a(s)};(0,d.useEffect)(()=>{s&&a(s)},[s]);let y=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},t=s[e.toLowerCase()]||s.default;return(0,c.jsx)(eX.Z,{color:t,size:"xs",children:e})},_=async e=>{s&&(await (0,j.credentialDeleteCall)(s,e),eo.Z.success("Credential deleted successfully"),h(null),a(s))},N=e=>{h(e)};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(k.Z,{children:"Configured credentials for different AI providers. Add and manage your API credentials."})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Credential Name"}),(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Description"})]})}),(0,c.jsx)(sk.Z,{children:l&&0!==l.length?l.map((e,s)=>{var t,l;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.credential_name}),(0,c.jsx)(sS.Z,{children:y((null===(t=e.credential_info)||void 0===t?void 0:t.custom_llm_provider)||"-")}),(0,c.jsx)(sS.Z,{children:(null===(l=e.credential_info)||void 0===l?void 0:l.description)||"-"}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(b.Z,{icon:sV.Z,variant:"light",size:"sm",onClick:()=>{u(e),o(!0)}}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"light",size:"sm",onClick:()=>N(e.credential_name)})]})]},s)}):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,c.jsx)(b.Z,{onClick:()=>i(!0),className:"mt-4",children:"Add Credential"}),r&&(0,c.jsx)(sX,{onAddCredential:v,isVisible:r,onCancel:()=>i(!1),uploadProps:t,addOrEdit:"add",onUpdateCredential:f,existingCredential:null}),n&&(0,c.jsx)(sX,{onAddCredential:v,isVisible:n,existingCredential:m,onUpdateCredential:f,uploadProps:t,onCancel:()=>o(!1),addOrEdit:"edit"}),x&&(0,c.jsx)(s0,{isVisible:!0,onCancel:()=>{h(null)},onConfirm:()=>_(x),credentialName:x})]})};let s2=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var s4=t(21487),s5=e=>{let{value:s,onValueChange:t,label:l="Select Time Range",className:a="",showTimeRange:r=!0}=e,[i,n]=(0,d.useState)(!1),o=(0,d.useRef)(null),m=(0,d.useCallback)(e=>{n(!0),setTimeout(()=>n(!1),1500),t(e),requestIdleCallback(()=>{if(e.from){let s;let l={...e},a=new Date(e.from);s=new Date(e.to?e.to:e.from),a.toDateString(),s.toDateString(),a.setHours(0,0,0,0),s.setHours(23,59,59,999),l.from=a,l.to=s,t(l)}},{timeout:100})},[t]),u=(0,d.useCallback)((e,s)=>{if(!e||!s)return"";let t=e=>e.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0,timeZoneName:"short"});if(e.toDateString()!==s.toDateString())return"".concat(t(e)," - ").concat(t(s));{let t=e.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),l=e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0}),a=s.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZoneName:"short"});return"".concat(t,": ").concat(l," - ").concat(a)}},[]);return(0,c.jsxs)("div",{className:a,children:[l&&(0,c.jsx)(k.Z,{className:"mb-2",children:l}),(0,c.jsxs)("div",{className:"relative w-fit",children:[(0,c.jsx)("div",{ref:o,children:(0,c.jsx)(s4.Z,{enableSelect:!0,value:s,onValueChange:m,placeholder:"Select date range",enableClear:!1,style:{zIndex:100}})}),i&&(0,c.jsx)("div",{className:"absolute top-1/2 animate-pulse",style:{left:"calc(100% + 8px)",transform:"translateY(-50%)",zIndex:110},children:(0,c.jsxs)("div",{className:"flex items-center gap-1 text-green-600 text-sm font-medium bg-white px-2 py-1 rounded-full border border-green-200 shadow-sm whitespace-nowrap",children:[(0,c.jsx)("div",{className:"w-3 h-3 bg-green-500 text-white rounded-full flex items-center justify-center text-xs",children:"✓"}),(0,c.jsx)("span",{className:"text-xs",children:"Selected"})]})})]}),r&&s.from&&s.to&&(0,c.jsx)(k.Z,{className:"mt-2 text-xs text-gray-500",children:u(s.from,s.to)})]})},s6=t(75105),s3=t(40278),s8=t(79326),s7=t(59664),s9=e=>{let{modelMetrics:s,modelMetricsCategories:t,customTooltip:l,premiumUser:a}=e;return(0,c.jsx)(s7.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:t,colors:["indigo","rose"],connectNulls:!0,customTooltip:l})},te=e=>{let{teamData:s,canEditTeam:t,handleMemberDelete:l,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:i}=e,n=e=>{if(null==e)return"0";if("number"==typeof e){let s=Number(e);return s===Math.floor(s)?s.toString():eE(s,8).replace(/\.?0+$/,"")}return"0"},o=e=>{if(!e)return 0;let t=s.team_memberships.find(s=>s.user_id===e);return(null==t?void 0:t.spend)||0},d=e=>{var t;if(!e)return null;let l=s.team_memberships.find(s=>s.user_id===e);console.log("membership=".concat(l));let a=null==l?void 0:null===(t=l.litellm_budget_table)||void 0===t?void 0:t.max_budget;return null==a?null:n(a)},m=e=>{var t,l;if(!e)return"No Limits";let a=s.team_memberships.find(s=>s.user_id===e),r=null==a?void 0:null===(t=a.litellm_budget_table)||void 0===t?void 0:t.rpm_limit,i=null==a?void 0:null===(l=a.litellm_budget_table)||void 0===l?void 0:l.tpm_limit,o=[r?"".concat(n(r)," RPM"):null,i?"".concat(n(i)," TPM"):null].filter(Boolean);return o.length>0?o.join(" / "):"No Limits"};return(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-auto max-h-[50vh]",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"min-w-full",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"User Email"}),(0,c.jsx)(sI.Z,{children:"Role"}),(0,c.jsxs)(sI.Z,{children:["Team Member Spend (USD)"," ",(0,c.jsx)(V.Z,{title:"This is the amount spent by a user in the team.",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(sI.Z,{children:"Team Member Budget (USD)"}),(0,c.jsxs)(sI.Z,{children:["Team Member Rate Limits"," ",(0,c.jsx)(V.Z,{title:"Rate limits for this member's usage within this team.",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(sI.Z,{className:"sticky right-0 bg-white z-10 border-l border-gray-200",children:"Actions"})]})}),(0,c.jsx)(sk.Z,{children:s.team_info.members_with_roles.map((e,i)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_email?e.user_email:"No Email"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.role})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{className:"font-mono",children:["$",eE(o(e.user_id),4)]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:d(e.user_id)?"$".concat(eE(Number(d(e.user_id)),4)):"No Limit"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:m(e.user_id)})}),(0,c.jsx)(sS.Z,{className:"sticky right-0 bg-white z-10 border-l border-gray-200",children:t&&(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{var t,l,i;let n=s.team_memberships.find(s=>s.user_id===e.user_id);a({...e,max_budget_in_team:(null==n?void 0:null===(t=n.litellm_budget_table)||void 0===t?void 0:t.max_budget)||null,tpm_limit:(null==n?void 0:null===(l=n.litellm_budget_table)||void 0===l?void 0:l.tpm_limit)||null,rpm_limit:(null==n?void 0:null===(i=n.litellm_budget_table)||void 0===i?void 0:i.rpm_limit)||null}),r(!0)},className:"cursor-pointer hover:text-blue-600"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(e),className:"cursor-pointer hover:text-red-600"})]})})]},i))})]})})}),(0,c.jsx)(b.Z,{onClick:()=>i(!0),children:"Add Member"})]})},ts=t(61994),tt=t(85180),tl=t(89245),ta=t(78355);let tr={"/key/generate":"Member can generate a virtual key for this team","/key/service-account/generate":"Member can generate a service account key (not belonging to any user) for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},ti=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",tn=e=>{let s=ti(e),t=tr[e];if(!t){for(let[s,l]of Object.entries(tr))if(e.includes(s)){t=l;break}}return t||(t="Access ".concat(e)),{method:s,endpoint:e,description:t,route:e}};var to=e=>{let{teamId:s,accessToken:t,canEditTeam:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)([]),[o,m]=(0,d.useState)(!0),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),g=async()=>{try{if(m(!0),!t)return;let e=await (0,j.getTeamPermissionsCall)(t,s),l=e.all_available_permissions||[];r(l);let a=e.team_member_permissions||[];n(a),p(!1)}catch(e){eo.Z.fromBackend("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{m(!1)}};(0,d.useEffect)(()=>{g()},[s,t]);let f=(e,s)=>{n(s?[...i,e]:i.filter(s=>s!==e)),p(!0)},v=async()=>{try{if(!t)return;x(!0),await (0,j.teamPermissionsUpdateCall)(t,s,i),eo.Z.success("Permissions updated successfully"),p(!1)}catch(e){eo.Z.fromBackend("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{x(!1)}};if(o)return(0,c.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let y=a.length>0;return(0,c.jsxs)(G.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,c.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,c.jsx)(S.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),l&&h&&(0,c.jsxs)("div",{className:"flex gap-3",children:[(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(tl.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,c.jsxs)(b.Z,{onClick:v,loading:u,className:"flex items-center gap-2",children:[(0,c.jsx)(ta.Z,{})," Save Changes"]})]})]}),(0,c.jsx)(k.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),y?(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:" min-w-full",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Method"}),(0,c.jsx)(sI.Z,{children:"Endpoint"}),(0,c.jsx)(sI.Z,{children:"Description"}),(0,c.jsx)(sI.Z,{className:"sticky right-0 bg-white shadow-[-4px_0_4px_-4px_rgba(0,0,0,0.1)] text-center",children:"Allow Access"})]})}),(0,c.jsx)(sk.Z,{children:a.map(e=>{let s=tn(e);return(0,c.jsxs)(sA.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,c.jsx)(sS.Z,{className:"text-gray-700",children:s.description}),(0,c.jsx)(sS.Z,{className:"sticky right-0 bg-white shadow-[-4px_0_4px_-4px_rgba(0,0,0,0.1)] text-center",children:(0,c.jsx)(ts.Z,{checked:i.includes(e),onChange:s=>f(e,s.target.checked),disabled:!l})})]},e)})})]})}):(0,c.jsx)("div",{className:"py-12",children:(0,c.jsx)(tt.Z,{description:"No permissions available"})})]})},tc=t(42264),td=e=>{var s,t,l;let{visible:a,onCancel:r,onSubmit:i,initialData:n,mode:o,config:m}=e,[u]=A.Z.useForm();console.log("Initial Data:",n),(0,d.useEffect)(()=>{if(a){if("edit"===o&&n){let e={...n,role:n.role||m.defaultRole,max_budget_in_team:n.max_budget_in_team||null,tpm_limit:n.tpm_limit||null,rpm_limit:n.rpm_limit||null};console.log("Setting form values:",e),u.setFieldsValue(e)}else{var e;u.resetFields(),u.setFieldsValue({role:m.defaultRole||(null===(e=m.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,n,o,u,m.defaultRole,m.roleOptions]);let x=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[t,l]=s;if("string"==typeof l){let s=l.trim();return""===s&&("max_budget_in_team"===t||"tpm_limit"===t||"rpm_limit"===t)?{...e,[t]:null}:{...e,[t]:s}}return{...e,[t]:l}},{});console.log("Submitting form data:",s),i(s),u.resetFields()}catch(e){console.error("Form submission error:",e)}},h=e=>{switch(e.type){case"input":return(0,c.jsx)(_.Z,{placeholder:e.placeholder});case"numerical":return(0,c.jsx)(O,{step:e.step||1,min:e.min||0,style:{width:"100%"},placeholder:e.placeholder||"Enter a numerical value"});case"select":var s;return(0,c.jsx)(eQ.Z,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value))});default:return null}};return(0,c.jsx)(L.Z,{title:m.title||("add"===o?"Add Member":"Edit Member"),open:a,width:1e3,footer:null,onCancel:r,children:(0,c.jsxs)(A.Z,{form:u,onFinish:x,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[m.showEmail&&(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,c.jsx)(_.Z,{placeholder:"user@example.com"})}),m.showEmail&&m.showUserId&&(0,c.jsx)("div",{className:"text-center mb-4",children:(0,c.jsx)(k.Z,{children:"OR"})}),m.showUserId&&(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,c.jsx)(_.Z,{placeholder:"user_123"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{children:"Role"}),"edit"===o&&n&&(0,c.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(t=n.role,(null===(l=m.roleOptions.find(e=>e.value===t))||void 0===l?void 0:l.label)||t),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,c.jsx)(eQ.Z,{children:"edit"===o&&n?[...m.roleOptions.filter(e=>e.value===n.role),...m.roleOptions.filter(e=>e.value!==n.role)].map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value)):m.roleOptions.map(e=>(0,c.jsx)(ei.Z,{value:e.value,children:e.label},e.value))})}),null===(s=m.additionalFields)||void 0===s?void 0:s.map(e=>(0,c.jsx)(A.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:h(e)},e.name)),(0,c.jsxs)("div",{className:"text-right mt-6",children:[(0,c.jsx)(P.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,c.jsx)(P.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},tm=e=>{let{isVisible:s,onCancel:t,onSubmit:l,accessToken:a,title:r="Add Team Member",roles:i=[{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:n="user"}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)("user_email"),f=async(e,s)=>{if(!e){u([]);return}h(!0);try{let t=new URLSearchParams;if(t.append(s,e),null==a)return;let l=(await (0,j.userFilterUICall)(a,t)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));u(l)}catch(e){console.error("Error fetching users:",e)}finally{h(!1)}},v=(0,d.useCallback)(eC()((e,s)=>f(e,s),300),[]),y=(e,s)=>{g(s),v(e,s)},b=(e,s)=>{let t=s.user;o.setFieldsValue({user_email:t.user_email,user_id:t.user_id,role:o.getFieldValue("role")})};return(0,c.jsx)(L.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),u([]),t()},footer:null,width:800,children:(0,c.jsxs)(A.Z,{form:o,onFinish:l,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:n},children:[(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>y(e,"user_email"),onSelect:(e,s)=>b(e,s),options:"user_email"===p?m:[],loading:x,allowClear:!0})}),(0,c.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,c.jsx)(I.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>y(e,"user_id"),onSelect:(e,s)=>b(e,s),options:"user_id"===p?m:[],loading:x,allowClear:!0})}),(0,c.jsx)(A.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,c.jsx)(I.default,{defaultValue:n,children:i.map(e=>(0,c.jsx)(I.default.Option,{value:e.value,children:(0,c.jsxs)(V.Z,{title:e.description,children:[(0,c.jsx)("span",{className:"font-medium",children:e.label}),(0,c.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,c.jsx)("div",{className:"text-right mt-4",children:(0,c.jsx)(P.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},tu=e=>{var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f;let{teamId:v,onClose:N,accessToken:Z,is_team_admin:w,is_proxy_admin:C,userModels:L,editTeam:T,premiumUser:M=!1,onUpdate:D}=e,[R,z]=(0,d.useState)(null),[q,K]=(0,d.useState)(!0),[H,J]=(0,d.useState)(!1),[Y]=A.Z.useForm(),[W,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(null),[ee,es]=(0,d.useState)(!1),[et,el]=(0,d.useState)([]),[ea,er]=(0,d.useState)(!1),[ei,en]=(0,d.useState)({}),[ec,ed]=(0,d.useState)([]);console.log("userModels in team info",L);let em=w||C,eu=async()=>{try{if(K(!0),!Z)return;let e=await (0,j.teamInfoCall)(Z,v);z(e)}catch(e){eo.Z.fromBackend("Failed to load team information"),console.error("Error fetching team info:",e)}finally{K(!1)}};(0,d.useEffect)(()=>{eu()},[v,Z]),(0,d.useEffect)(()=>{(async()=>{try{if(!Z)return;let e=(await (0,j.getGuardrailsList)(Z)).guardrails.map(e=>e.guardrail_name);ed(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[Z]);let ex=async e=>{try{if(null==Z)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.teamMemberAddCall)(Z,v,s),eo.Z.success("Team member added successfully"),J(!1),Y.resetFields();let t=await (0,j.teamInfoCall)(Z,v);z(t),D(t)}catch(a){var s,t,l;let e="Failed to add team member";(null==a?void 0:null===(l=a.raw)||void 0===l?void 0:null===(t=l.detail)||void 0===t?void 0:null===(s=t.error)||void 0===s?void 0:s.includes("Assigning team admins is a premium feature"))?e="Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.":(null==a?void 0:a.message)&&(e=a.message),eo.Z.fromBackend(e),console.error("Error adding team member:",a)}},eh=async e=>{try{if(null==Z)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role,max_budget_in_team:e.max_budget_in_team,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit};console.log("Updating member with values:",s),tc.ZP.destroy(),await (0,j.teamMemberUpdateCall)(Z,v,s),eo.Z.success("Team member updated successfully"),$(!1);let t=await (0,j.teamInfoCall)(Z,v);z(t),D(t)}catch(l){var s,t;let e="Failed to update team member";(null==l?void 0:null===(t=l.raw)||void 0===t?void 0:null===(s=t.detail)||void 0===s?void 0:s.includes("Assigning team admins is a premium feature"))?e="Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.":(null==l?void 0:l.message)&&(e=l.message),$(!1),tc.ZP.destroy(),eo.Z.fromBackend(e),console.error("Error updating team member:",l)}},ep=async e=>{try{if(null==Z)return;await (0,j.teamMemberDeleteCall)(Z,v,e),eo.Z.success("Team member removed successfully");let s=await (0,j.teamInfoCall)(Z,v);z(s),D(s)}catch(e){eo.Z.fromBackend("Failed to remove team member"),console.error("Error removing team member:",e)}},eg=async e=>{try{if(!Z)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t=e=>null==e||"string"==typeof e&&""===e.trim()||"number"==typeof e&&Number.isNaN(e)?null:e,l={team_id:v,team_alias:e.team_alias,models:e.models,tpm_limit:t(e.tpm_limit),rpm_limit:t(e.rpm_limit),max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[],logging:e.logging_settings||[]},organization_id:e.organization_id};void 0!==e.team_member_budget&&(l.team_member_budget=Number(e.team_member_budget)),void 0!==e.team_member_key_duration&&(l.team_member_key_duration=e.team_member_key_duration),(void 0!==e.team_member_tpm_limit||void 0!==e.team_member_rpm_limit)&&(l.team_member_tpm_limit=t(e.team_member_tpm_limit),l.team_member_rpm_limit=t(e.team_member_rpm_limit));let{servers:a,accessGroups:r}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};(a&&a.length>0||r&&r.length>0)&&(l.object_permission={},a&&a.length>0&&(l.object_permission.mcp_servers=a),r&&r.length>0&&(l.object_permission.mcp_access_groups=r)),delete e.mcp_servers_and_groups,await (0,j.teamUpdateCall)(Z,l),eo.Z.success("Team settings updated successfully"),es(!1),eu()}catch(e){console.error("Error updating team:",e)}};if(q)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==R?void 0:R.team_info))return(0,c.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:ej}=R,ef=async(e,s)=>{await eM(e)&&(en(e=>({...e,[s]:!0})),setTimeout(()=>{en(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:N,className:"mb-4",children:"Back to Teams"}),(0,c.jsx)(S.Z,{children:ej.team_alias}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:ej.team_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:ei["team-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>ef(ej.team_id,"team-id"),className:"left-2 z-10 transition-all duration-200 ".concat(ei["team-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:T?3:0,children:[(0,c.jsx)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),...em?[(0,c.jsx)(e0.Z,{children:"Members"},"members"),(0,c.jsx)(e0.Z,{children:"Member Permissions"},"member-permissions"),(0,c.jsx)(e0.Z,{children:"Settings"},"settings")]:[]]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Budget Status"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(ej.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null===ej.max_budget?"Unlimited":"$".concat(eE(ej.max_budget,4))]}),ej.budget_duration&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Reset: ",ej.budget_duration]}),(0,c.jsx)("br",{}),ej.team_member_budget_table&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Team Member Budget: $",eE(ej.team_member_budget_table.max_budget,4)]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",ej.tpm_limit||"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",ej.rpm_limit||"Unlimited"]}),ej.max_parallel_requests&&(0,c.jsxs)(k.Z,{children:["Max Parallel Requests: ",ej.max_parallel_requests]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:0===ej.models.length?(0,c.jsx)(eX.Z,{color:"red",children:"All proxy models"}):ej.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{className:"font-semibold text-gray-900",children:"Virtual Keys"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["User Keys: ",R.keys.filter(e=>e.user_id).length]}),(0,c.jsxs)(k.Z,{children:["Service Account Keys: ",R.keys.filter(e=>!e.user_id).length]}),(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Total: ",R.keys.length]})]})]}),(0,c.jsx)(sc,{objectPermission:ej.object_permission,variant:"card",accessToken:Z}),(0,c.jsx)(sd,{loggingConfigs:(null===(s=ej.metadata)||void 0===s?void 0:s.logging)||[],disabledCallbacks:[],variant:"card"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(te,{teamData:R,canEditTeam:em,handleMemberDelete:ep,setSelectedEditMember:X,setIsEditMemberModalVisible:$,setIsAddMemberModalVisible:J})}),em&&(0,c.jsx)(e4.Z,{children:(0,c.jsx)(to,{teamId:v,accessToken:Z,canEditTeam:em})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Team Settings"}),em&&!ee&&(0,c.jsx)(b.Z,{onClick:()=>es(!0),children:"Edit Settings"})]}),ee?(0,c.jsxs)(A.Z,{form:Y,onFinish:eg,initialValues:{...ej,team_alias:ej.team_alias,models:ej.models,tpm_limit:ej.tpm_limit,rpm_limit:ej.rpm_limit,max_budget:ej.max_budget,budget_duration:ej.budget_duration,team_member_tpm_limit:null===(t=ej.team_member_budget_table)||void 0===t?void 0:t.tpm_limit,team_member_rpm_limit:null===(l=ej.team_member_budget_table)||void 0===l?void 0:l.rpm_limit,guardrails:(null===(a=ej.metadata)||void 0===a?void 0:a.guardrails)||[],metadata:ej.metadata?JSON.stringify((e=>{let{logging:s,...t}=e;return t})(ej.metadata),null,2):"",logging_settings:(null===(r=ej.metadata)||void 0===r?void 0:r.logging)||[],organization_id:ej.organization_id,vector_stores:(null===(i=ej.object_permission)||void 0===i?void 0:i.vector_stores)||[],mcp_servers:(null===(n=ej.object_permission)||void 0===n?void 0:n.mcp_servers)||[],mcp_access_groups:(null===(o=ej.object_permission)||void 0===o?void 0:o.mcp_access_groups)||[],mcp_servers_and_groups:{servers:(null===(m=ej.object_permission)||void 0===m?void 0:m.mcp_servers)||[],accessGroups:(null===(u=ej.object_permission)||void 0===u?void 0:u.mcp_access_groups)||[]}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,c.jsx)(E.default,{type:""})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),Array.from(new Set(L)).map((e,s)=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},s))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Budget (USD)",name:"team_member_budget",tooltip:"This is the individual budget for a user in the team.",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Key Duration (eg: 1d, 1mo)",name:"team_member_key_duration",tooltip:"Set a limit to the duration of a team member's key. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days), 1mo (month)",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member TPM Limit",name:"team_member_tpm_limit",tooltip:"Default tokens per minute limit for an individual team member. This limit applies to all requests the user makes within this team. Can be overridden per member.",children:(0,c.jsx)(O,{step:1,style:{width:"100%"},placeholder:"e.g., 1000"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member RPM Limit",name:"team_member_rpm_limit",tooltip:"Default requests per minute limit for an individual team member. This limit applies to all requests the user makes within this team. Can be overridden per member.",children:(0,c.jsx)(O,{step:1,style:{width:"100%"},placeholder:"e.g., 100"})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Setup your first guardrail",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,c.jsx)(I.default,{mode:"tags",placeholder:"Select or enter guardrails",options:ec.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>Y.setFieldValue("vector_stores",e),value:Y.getFieldValue("vector_stores"),accessToken:Z||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers / Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>Y.setFieldValue("mcp_servers_and_groups",e),value:Y.getFieldValue("mcp_servers_and_groups"),accessToken:Z||"",placeholder:"Select MCP servers or access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,c.jsx)(E.default,{type:""})}),(0,c.jsx)(A.Z.Item,{label:"Logging Settings",name:"logging_settings",children:(0,c.jsx)(e8,{value:Y.getFieldValue("logging_settings"),onChange:e=>Y.setFieldValue("logging_settings",e)})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:10})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{htmlType:"button",onClick:()=>es(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team Name"}),(0,c.jsx)("div",{children:ej.team_alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)("div",{className:"font-mono",children:ej.team_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:new Date(ej.created_at).toLocaleString()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:ej.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)("div",{children:["TPM: ",ej.tpm_limit||"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",ej.rpm_limit||"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team Budget"}),(0,c.jsxs)("div",{children:["Max Budget:"," ",null!==ej.max_budget?"$".concat(eE(ej.max_budget,4)):"No Limit"]}),(0,c.jsxs)("div",{children:["Budget Reset: ",ej.budget_duration||"Never"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Team Member Settings"," ",(0,c.jsx)(V.Z,{title:"These are limits on individual team members",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),(0,c.jsxs)("div",{children:["Max Budget:"," ",(null===(x=ej.team_member_budget_table)||void 0===x?void 0:x.max_budget)||"No Limit"]}),(0,c.jsxs)("div",{children:["Key Duration:"," ",(null===(h=ej.metadata)||void 0===h?void 0:h.team_member_key_duration)||"No Limit"]}),(0,c.jsxs)("div",{children:["TPM Limit:"," ",(null===(p=ej.team_member_budget_table)||void 0===p?void 0:p.tpm_limit)||"No Limit"]}),(0,c.jsxs)("div",{children:["RPM Limit:"," ",(null===(g=ej.team_member_budget_table)||void 0===g?void 0:g.rpm_limit)||"No Limit"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization ID"}),(0,c.jsx)("div",{children:ej.organization_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Status"}),(0,c.jsx)(eX.Z,{color:ej.blocked?"red":"green",children:ej.blocked?"Blocked":"Active"})]}),(0,c.jsx)(sc,{objectPermission:ej.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:Z}),(0,c.jsx)(sd,{loggingConfigs:(null===(f=ej.metadata)||void 0===f?void 0:f.logging)||[],disabledCallbacks:[],variant:"inline",className:"pt-4 border-t border-gray-200"})]})]})})]})]}),(0,c.jsx)(td,{visible:W,onCancel:()=>$(!1),onSubmit:eh,initialData:Q,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}],additionalFields:[{name:"max_budget_in_team",label:(0,c.jsxs)("span",{children:["Team Member Budget (USD)"," ",(0,c.jsx)(V.Z,{title:"Maximum amount in USD this member can spend within this team. This is separate from any global user budget limits",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:.01,min:0,placeholder:"Budget limit for this member within this team"},{name:"tpm_limit",label:(0,c.jsxs)("span",{children:["Team Member TPM Limit"," ",(0,c.jsx)(V.Z,{title:"Maximum tokens per minute this member can use within this team. This is separate from any global user TPM limit",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:1,min:0,placeholder:"Tokens per minute limit for this member in this team"},{name:"rpm_limit",label:(0,c.jsxs)("span",{children:["Team Member RPM Limit"," ",(0,c.jsx)(V.Z,{title:"Maximum requests per minute this member can make within this team. This is separate from any global user RPM limit",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),type:"numerical",step:1,min:0,placeholder:"Requests per minute limit for this member in this team"}]}}),(0,c.jsx)(tm,{isVisible:H,onCancel:()=>J(!1),onSubmit:ex,accessToken:Z})]})},tx=t(45589);let{Title:th,Link:tp}=en.default;var tg=e=>{let{isVisible:s,onCancel:t,onAddCredential:l,existingCredential:a,setIsCredentialModalOpen:r}=e,[i]=A.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,c.jsx)(L.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{t(),i.resetFields()},footer:null,width:600,children:(0,c.jsxs)(A.Z,{form:i,onFinish:e=>{l(e),i.resetFields(),r(!1)},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,c.jsx)(sW.o,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,t]=e;return(0,c.jsx)(A.Z.Item,{label:s,name:s,initialValue:t,children:(0,c.jsx)(sW.o,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(tp,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:()=>{t(),i.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},tj=t(63709),tf=t(45246),tv=t(96473);let{Text:ty}=en.default;var tb=e=>{let{form:s,showCacheControl:t,onCacheControlChange:l}=e,a=e=>{let t=s.getFieldValue("litellm_extra_params");try{let l=t?JSON.parse(t):{};e.length>0?l.cache_control_injection_points=e:delete l.cache_control_injection_points,Object.keys(l).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,c.jsx)(tj.Z,{onChange:l,className:"bg-gray-600"})}),t&&(0,c.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,c.jsx)(ty,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,c.jsx)(A.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,t)=>{let{add:l,remove:r}=t;return(0,c.jsxs)(c.Fragment,{children:[e.map((t,l)=>(0,c.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,c.jsx)(A.Z.Item,{...t,label:"Type",name:[t.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,c.jsx)(I.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,c.jsx)(A.Z.Item,{...t,label:"Role",name:[t.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,c.jsx)(I.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,c.jsx)(A.Z.Item,{...t,label:"Index",name:[t.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,c.jsx)(O,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,c.jsx)(tf.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(t.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},t.key)),(0,c.jsx)(A.Z.Item,{children:(0,c.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>l(),children:[(0,c.jsx)(tv.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})},t_=t(44851),tN=t(67960),tZ=t(70464);let{TextArea:tw}=E.default,{Panel:tk}=t_.default;var tS=e=>{let{modelInfo:s,value:t,onChange:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]);(0,d.useEffect)(()=>{if(null==t?void 0:t.routes){let e=t.routes.map((e,s)=>({id:e.id||"route-".concat(s,"-").concat(Date.now()),model:e.name||e.model||"",utterances:e.utterances||[],description:e.description||"",score_threshold:e.score_threshold||.5}));r(e),m(e.map(e=>e.id))}else r([]),m([])},[t]);let u=e=>{let s=a.filter(s=>s.id!==e);r(s),h(s),m(s=>s.filter(s=>s!==e))},x=(e,s,t)=>{let l=a.map(l=>l.id===e?{...l,[s]:t}:l);r(l),h(l)},h=e=>{let s={routes:e.map(e=>({name:e.model,utterances:e.utterances,description:e.description,score_threshold:e.score_threshold}))};null==l||l(s)},p=s.map(e=>({value:e.model_group,label:e.model_group}));return(0,c.jsxs)("div",{className:"w-full max-w-none",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6 w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold",children:"Routes Configuration"}),(0,c.jsx)(V.Z,{title:"Configure routing logic to automatically select the best model based on user input patterns",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(P.ZP,{type:"primary",icon:(0,c.jsx)(tv.Z,{}),onClick:()=>{let e="route-".concat(Date.now()),s=[...a,{id:e,model:"",utterances:[],description:"",score_threshold:.5}];r(s),h(s),m(s=>[...s,e])},className:"bg-blue-600 hover:bg-blue-700",children:"Add Route"})]}),0===a.length?(0,c.jsx)("div",{className:"text-center py-12 text-gray-500 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200 mb-6",children:(0,c.jsx)(k.Z,{children:"No routes configured. Click “Add Route” to get started."})}):(0,c.jsx)("div",{className:"space-y-3 mb-6 w-full",children:a.map((e,s)=>(0,c.jsx)(tN.Z,{className:"border border-gray-200 shadow-sm w-full",bodyStyle:{padding:0},children:(0,c.jsx)(t_.default,{ghost:!0,expandIcon:e=>{let{isActive:s}=e;return(0,c.jsx)(tZ.Z,{rotate:s?180:0})},activeKey:o,onChange:e=>m(Array.isArray(e)?e:[e].filter(Boolean)),items:[{key:e.id,label:(0,c.jsxs)("div",{className:"flex justify-between items-center py-2",children:[(0,c.jsxs)(k.Z,{className:"font-medium text-base",children:["Route ",s+1,": ",e.model||"Unnamed"]}),(0,c.jsx)(P.ZP,{type:"text",danger:!0,icon:(0,c.jsx)(ep.Z,{}),onClick:s=>{s.stopPropagation(),u(e.id)},className:"mr-2"})]}),children:(0,c.jsxs)("div",{className:"px-6 pb-6 w-full",children:[(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-2 block",children:"Model"}),(0,c.jsx)(I.default,{value:e.model,onChange:s=>x(e.id,"model",s),placeholder:"Select model",showSearch:!0,style:{width:"100%"},options:p})]}),(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-2 block",children:"Description"}),(0,c.jsx)(tw,{value:e.description,onChange:s=>x(e.id,"description",s.target.value),placeholder:"Describe when this route should be used...",rows:2,style:{width:"100%"}})]}),(0,c.jsxs)("div",{className:"mb-4 w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium",children:"Score Threshold"}),(0,c.jsx)(V.Z,{title:"Minimum similarity score to route to this model (0-1)",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(eW.Z,{value:e.score_threshold,onChange:s=>x(e.id,"score_threshold",s||0),min:0,max:1,step:.1,style:{width:"100%"},placeholder:"0.5"})]}),(0,c.jsxs)("div",{className:"w-full",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium",children:"Example Utterances"}),(0,c.jsx)(V.Z,{title:"Training examples for this route. Type an utterance and press Enter to add it.",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500 mb-2",children:"Type an utterance and press Enter to add it. You can also paste multiple lines."}),(0,c.jsx)(I.default,{mode:"tags",value:e.utterances,onChange:s=>x(e.id,"utterances",s),placeholder:"Type an utterance and press Enter...",style:{width:"100%"},tokenSeparators:["\n"],maxTagCount:"responsive",allowClear:!0})]})]})}]})},e.id))}),(0,c.jsxs)("div",{className:"border-t pt-6 w-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4 w-full",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold",children:"JSON Preview"}),(0,c.jsx)(P.ZP,{type:"link",onClick:()=>n(!i),className:"text-blue-600 p-0",children:i?"Hide":"Show"})]}),i&&(0,c.jsx)(tN.Z,{className:"bg-gray-50 w-full",children:(0,c.jsx)("pre",{className:"text-sm overflow-auto max-h-64 w-full",children:JSON.stringify({routes:a.map(e=>({name:e.model,utterances:e.utterances,description:e.description,score_threshold:e.score_threshold}))},null,2)})})]})]})},tC=e=>{let{isVisible:s,onCancel:t,onSuccess:l,modelData:a,accessToken:r,userRole:i}=e,[n]=A.Z.useForm(),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)(!1),[b,N]=(0,d.useState)(null);(0,d.useEffect)(()=>{s&&a&&Z()},[s,a]),(0,d.useEffect)(()=>{let e=async()=>{if(r)try{let e=await (0,j.modelAvailableCall)(r,"","",!1,null,!0,!0);x(e.data.map(e=>e.id))}catch(e){console.error("Error fetching model access groups:",e)}},t=async()=>{if(r)try{let e=await eU(r);p(e)}catch(e){console.error("Error fetching model info:",e)}};s&&(e(),t())},[s,r]);let Z=()=>{try{var e,s,t,l,r,i;let o=null;(null===(e=a.litellm_params)||void 0===e?void 0:e.auto_router_config)&&(o="string"==typeof a.litellm_params.auto_router_config?JSON.parse(a.litellm_params.auto_router_config):a.litellm_params.auto_router_config),N(o),n.setFieldsValue({auto_router_name:a.model_name,auto_router_default_model:(null===(s=a.litellm_params)||void 0===s?void 0:s.auto_router_default_model)||"",auto_router_embedding_model:(null===(t=a.litellm_params)||void 0===t?void 0:t.auto_router_embedding_model)||"",model_access_group:(null===(l=a.model_info)||void 0===l?void 0:l.access_groups)||[]});let c=new Set(h.map(e=>e.model_group));f(!c.has(null===(r=a.litellm_params)||void 0===r?void 0:r.auto_router_default_model)),y(!c.has(null===(i=a.litellm_params)||void 0===i?void 0:i.auto_router_embedding_model))}catch(e){console.error("Error parsing auto router config:",e),eo.Z.fromBackend("Error loading auto router configuration")}},w=async()=>{try{m(!0);let e=await n.validateFields(),s={...a.litellm_params,auto_router_config:JSON.stringify(b),auto_router_default_model:e.auto_router_default_model,auto_router_embedding_model:e.auto_router_embedding_model||void 0},i={...a.model_info,access_groups:e.model_access_group||[]},o={model_name:e.auto_router_name,litellm_params:s,model_info:i};await (0,j.modelPatchUpdateCall)(r,o,a.model_info.id);let c={...a,model_name:e.auto_router_name,litellm_params:s,model_info:i};eo.Z.success("Auto router configuration updated successfully"),l(c),t()}catch(e){console.error("Error updating auto router:",e),eo.Z.fromBackend("Failed to update auto router configuration")}finally{m(!1)}},S=h.map(e=>({value:e.model_group,label:e.model_group}));return(0,c.jsx)(L.Z,{title:"Edit Auto Router Configuration",open:s,onCancel:t,footer:[(0,c.jsx)(P.ZP,{onClick:t,children:"Cancel"},"cancel"),(0,c.jsx)(P.ZP,{loading:o,onClick:w,children:"Save Changes"},"submit")],width:1e3,destroyOnClose:!0,children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsx)(k.Z,{className:"text-gray-600",children:"Edit the auto router configuration including routing logic, default models, and access settings."}),(0,c.jsxs)(A.Z,{form:n,layout:"vertical",className:"space-y-4",children:[(0,c.jsx)(A.Z.Item,{label:"Auto Router Name",name:"auto_router_name",rules:[{required:!0,message:"Auto router name is required"}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., auto_router_1, smart_routing"})}),(0,c.jsx)("div",{className:"w-full",children:(0,c.jsx)(tS,{modelInfo:h,value:b,onChange:e=>{N(e)}})}),(0,c.jsx)(A.Z.Item,{label:"Default Model",name:"auto_router_default_model",rules:[{required:!0,message:"Default model is required"}],children:(0,c.jsx)(I.default,{placeholder:"Select a default model",onChange:e=>{f("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model name"}],showSearch:!0})}),(0,c.jsx)(A.Z.Item,{label:"Embedding Model",name:"auto_router_embedding_model",children:(0,c.jsx)(I.default,{placeholder:"Select an embedding model (optional)",onChange:e=>{y("custom"===e)},options:[...S,{value:"custom",label:"Enter custom model name"}],showSearch:!0,allowClear:!0})}),"Admin"===i&&(0,c.jsx)(A.Z.Item,{label:"Model Access Groups",name:"model_access_group",tooltip:"Control who can access this auto router",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:u.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})})]})]})})};function tI(e){var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f,v,N,Z,w,C,T,M,D,F,R,z,U,q;let{modelId:K,onClose:H,modelData:J,accessToken:Y,userID:$,userRole:Q,editModel:X,setEditModalVisible:ee,setSelectedModel:es,onModelUpdate:et,modelAccessGroups:el}=e,[ea]=A.Z.useForm(),[er,ei]=(0,d.useState)(null),[en,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(!1),[eu,ex]=(0,d.useState)(!1),[eh,ep]=(0,d.useState)(!1),[eg,ej]=(0,d.useState)(!1),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(!1),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)(!1),[ek,eS]=(0,d.useState)([]),eC="Admin"===Q||(null==J?void 0:null===(s=J.model_info)||void 0===s?void 0:s.created_by)===$,eI=(null==J?void 0:null===(t=J.litellm_params)||void 0===t?void 0:t.auto_router_config)!=null,eA=(null==J?void 0:null===(l=J.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=null&&(null==J?void 0:null===(a=J.litellm_params)||void 0===a?void 0:a.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",eA),console.log("modelData.litellm_params.litellm_credential_name, ",null==J?void 0:null===(r=J.litellm_params)||void 0===r?void 0:r.litellm_credential_name),(0,d.useEffect)(()=>{let e=async()=>{var e;if(!Y)return;let s=await (0,j.modelInfoV1Call)(Y,K);console.log("modelInfoResponse, ",s);let t=s.data[0];ei(t),(null==t?void 0:null===(e=t.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&eb(!0)},s=async()=>{if(Y)try{let e=(await (0,j.getGuardrailsList)(Y)).guardrails.map(e=>e.guardrail_name);eS(e)}catch(e){console.error("Failed to fetch guardrails:",e)}};(async()=>{if(console.log("accessToken, ",Y),!Y||eA)return;let e=await (0,j.credentialGetCall)(Y,null,K);console.log("existingCredentialResponse, ",e),ev({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e(),s()},[Y,K]);let eL=async e=>{var s;if(console.log("values, ",e),!Y)return;let t={credential_name:e.credential_name,model_id:K,credential_info:{custom_llm_provider:null===(s=er.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};eo.Z.info("Storing credential.."),console.log("credentialResponse, ",await (0,j.credentialCreateCall)(Y,t)),eo.Z.success("Credential stored successfully")},eT=async e=>{try{var s;let t;if(!Y)return;ep(!0),console.log("values.model_name, ",e.model_name);let l={...er.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};e.guardrails&&(l.guardrails=e.guardrails),e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;try{t=e.model_info?JSON.parse(e.model_info):J.model_info,e.model_access_group&&(t={...t,access_groups:e.model_access_group})}catch(e){eo.Z.fromBackend("Invalid JSON in Model Info");return}let a={model_name:e.model_name,litellm_params:l,model_info:t};await (0,j.modelPatchUpdateCall)(Y,a,K);let r={...er,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l,model_info:t};ei(r),et&&et(r),eo.Z.success("Model settings updated successfully"),ex(!1),ej(!1)}catch(e){console.error("Error updating model:",e),eo.Z.fromBackend("Failed to update model settings")}finally{ep(!1)}};if(!J)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:H,className:"mb-4",children:"Back to Models"}),(0,c.jsx)(k.Z,{children:"Model not found"})]});let eP=async()=>{try{if(!Y)return;await (0,j.modelDeleteCall)(Y,K),eo.Z.success("Model deleted successfully"),et&&et({deleted:!0,model_info:{id:K}}),H()}catch(e){console.error("Error deleting the model:",e),eo.Z.fromBackend("Failed to delete model")}},eE=async(e,s)=>{await eM(e)&&(eN(e=>({...e,[s]:!0})),setTimeout(()=>{eN(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:H,className:"mb-4",children:"Back to Models"}),(0,c.jsxs)(S.Z,{children:["Public Model Name: ",s2(J)]}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:J.model_info.id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["model-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eE(J.model_info.id,"model-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["model-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{className:"flex gap-2",children:["Admin"===Q&&(0,c.jsx)(b.Z,{icon:tx.Z,variant:"secondary",onClick:()=>em(!0),className:"flex items-center",children:"Re-use Credentials"}),eC&&(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>ec(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Raw JSON"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Provider"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[J.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(J.provider).logo,alt:"".concat(J.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var l;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===(l=J.provider)||void 0===l?void 0:l.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,c.jsx)(S.Z,{children:J.provider||"Not Set"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"LiteLLM Model"}),(0,c.jsx)("div",{className:"mt-2 overflow-hidden",children:(0,c.jsx)(V.Z,{title:J.litellm_model_name||"Not Set",children:(0,c.jsx)("div",{className:"break-all text-sm font-medium leading-relaxed cursor-pointer",children:J.litellm_model_name||"Not Set"})})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Pricing"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["Input: $",J.input_cost,"/1M tokens"]}),(0,c.jsxs)(k.Z,{children:["Output: $",J.output_cost,"/1M tokens"]})]})]})]}),(0,c.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,c.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"," ",J.model_info.created_at?new Date(J.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,c.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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 ",J.model_info.created_by||"Not Set"]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Model Settings"}),(0,c.jsxs)("div",{className:"flex gap-2",children:[eI&&eC&&!eg&&(0,c.jsx)(b.Z,{variant:"primary",onClick:()=>ew(!0),className:"flex items-center",children:"Edit Auto Router"}),eC&&!eg&&(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>ej(!0),className:"flex items-center",children:"Edit Model"})]})]}),er?(0,c.jsx)(A.Z,{form:ea,onFinish:eT,initialValues:{model_name:er.model_name,litellm_model_name:er.litellm_model_name,api_base:er.litellm_params.api_base,custom_llm_provider:er.litellm_params.custom_llm_provider,organization:er.litellm_params.organization,tpm:er.litellm_params.tpm,rpm:er.litellm_params.rpm,max_retries:er.litellm_params.max_retries,timeout:er.litellm_params.timeout,stream_timeout:er.litellm_params.stream_timeout,input_cost:er.litellm_params.input_cost_per_token?1e6*er.litellm_params.input_cost_per_token:(null===(i=er.model_info)||void 0===i?void 0:i.input_cost_per_token)*1e6||null,output_cost:(null===(n=er.litellm_params)||void 0===n?void 0:n.output_cost_per_token)?1e6*er.litellm_params.output_cost_per_token:(null===(o=er.model_info)||void 0===o?void 0:o.output_cost_per_token)*1e6||null,cache_control:null!==(m=er.litellm_params)&&void 0!==m&&!!m.cache_control_injection_points,cache_control_injection_points:(null===(u=er.litellm_params)||void 0===u?void 0:u.cache_control_injection_points)||[],model_access_group:Array.isArray(null===(x=er.model_info)||void 0===x?void 0:x.access_groups)?er.model_info.access_groups:[],guardrails:Array.isArray(null===(h=er.litellm_params)||void 0===h?void 0:h.guardrails)?er.litellm_params.guardrails:[]},layout:"vertical",onValuesChange:()=>ex(!0),children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Name"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_name",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter model name"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:er.model_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Model Name"}),eg?(0,c.jsx)(A.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter LiteLLM model name"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:er.litellm_model_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),eg?(0,c.jsx)(A.Z.Item,{name:"input_cost",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter input cost"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==er?void 0:null===(p=er.litellm_params)||void 0===p?void 0:p.input_cost_per_token)?((null===(g=er.litellm_params)||void 0===g?void 0:g.input_cost_per_token)*1e6).toFixed(4):(null==er?void 0:null===(f=er.model_info)||void 0===f?void 0:f.input_cost_per_token)?(1e6*er.model_info.input_cost_per_token).toFixed(4):null})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),eg?(0,c.jsx)(A.Z.Item,{name:"output_cost",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter output cost"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==er?void 0:null===(v=er.litellm_params)||void 0===v?void 0:v.output_cost_per_token)?(1e6*er.litellm_params.output_cost_per_token).toFixed(4):(null==er?void 0:null===(N=er.model_info)||void 0===N?void 0:N.output_cost_per_token)?(1e6*er.model_info.output_cost_per_token).toFixed(4):null})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"API Base"}),eg?(0,c.jsx)(A.Z.Item,{name:"api_base",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter API base"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=er.litellm_params)||void 0===Z?void 0:Z.api_base)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Custom LLM Provider"}),eg?(0,c.jsx)(A.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter custom LLM provider"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(w=er.litellm_params)||void 0===w?void 0:w.custom_llm_provider)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization"}),eg?(0,c.jsx)(A.Z.Item,{name:"organization",className:"mb-0",children:(0,c.jsx)(_.Z,{placeholder:"Enter organization"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(C=er.litellm_params)||void 0===C?void 0:C.organization)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),eg?(0,c.jsx)(A.Z.Item,{name:"tpm",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter TPM"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(T=er.litellm_params)||void 0===T?void 0:T.tpm)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),eg?(0,c.jsx)(A.Z.Item,{name:"rpm",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter RPM"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(M=er.litellm_params)||void 0===M?void 0:M.rpm)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Max Retries"}),eg?(0,c.jsx)(A.Z.Item,{name:"max_retries",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter max retries"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(D=er.litellm_params)||void 0===D?void 0:D.max_retries)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Timeout (seconds)"}),eg?(0,c.jsx)(A.Z.Item,{name:"timeout",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter timeout"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(F=er.litellm_params)||void 0===F?void 0:F.timeout)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),eg?(0,c.jsx)(A.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,c.jsx)(O,{placeholder:"Enter stream timeout"})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(R=er.litellm_params)||void 0===R?void 0:R.stream_timeout)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Access Groups"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_access_group",className:"mb-0",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],maxTagCount:"responsive",allowClear:!0,style:{width:"100%"},options:null==el?void 0:el.map(e=>({value:e,label:e}))})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(z=er.model_info)||void 0===z?void 0:z.access_groups)?Array.isArray(er.model_info.access_groups)?er.model_info.access_groups.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:er.model_info.access_groups.map((e,s)=>(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800",children:e},s))}):"No groups assigned":er.model_info.access_groups:"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this model to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),eg?(0,c.jsx)(A.Z.Item,{name:"guardrails",className:"mb-0",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing guardrails or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],maxTagCount:"responsive",allowClear:!0,style:{width:"100%"},options:ek.map(e=>({value:e,label:e}))})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(U=er.litellm_params)||void 0===U?void 0:U.guardrails)?Array.isArray(er.litellm_params.guardrails)?er.litellm_params.guardrails.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:er.litellm_params.guardrails.map((e,s)=>(0,c.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800",children:e},s))}):"No guardrails assigned":er.litellm_params.guardrails:"Not Set"})]}),eg?(0,c.jsx)(tb,{form:ea,showCacheControl:ey,onCacheControlChange:e=>eb(e)}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cache Control"}),(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(q=er.litellm_params)||void 0===q?void 0:q.cache_control_injection_points)?(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"Enabled"}),(0,c.jsx)("div",{className:"mt-2",children:er.litellm_params.cache_control_injection_points.map((e,s)=>(0,c.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,c.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,c.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Model Info"}),eg?(0,c.jsx)(A.Z.Item,{name:"model_info",className:"mb-0",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}',defaultValue:JSON.stringify(J.model_info,null,2)})}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(er.model_info,null,2)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Team ID"}),(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:J.model_info.team_id||"Not Set"})]})]}),eg&&(0,c.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{ea.resetFields(),ex(!1),ej(!1)},children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",onClick:()=>ea.submit(),loading:eh,children:"Save Changes"})]})]})}):(0,c.jsx)(k.Z,{children:"Loading..."})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(G.Z,{children:(0,c.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(J,null,2)})})})]})]}),en&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(P.ZP,{onClick:eP,className:"ml-2",danger:!0,children:"Delete"}),(0,c.jsx)(P.ZP,{onClick:()=>ec(!1),children:"Cancel"})]})]})]})}),ed&&!eA?(0,c.jsx)(tg,{isVisible:ed,onCancel:()=>em(!1),onAddCredential:eL,existingCredential:ef,setIsCredentialModalOpen:em}):(0,c.jsx)(L.Z,{open:ed,onCancel:()=>em(!1),title:"Using Existing Credential",children:(0,c.jsx)(k.Z,{children:J.litellm_params.litellm_credential_name})}),(0,c.jsx)(tC,{isVisible:eZ,onCancel:()=>ew(!1),onSuccess:e=>{ei(e),et&&et(e)},modelData:er||J,accessToken:Y||"",userRole:Q||""})]})}var tA=e=>{let{selectedProvider:s,providerModels:t,getPlaceholder:l}=e,a=A.Z.useFormInstance(),r=e=>{let t=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?s===sU.Cl.Azure?{public_name:t,litellm_model:"azure/".concat(t)}:{public_name:t,litellm_model:t}:e);a.setFieldsValue({model_mappings:l})};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(A.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"The model name LiteLLM will send to the LLM API",className:"mb-0",children:[(0,c.jsx)(A.Z.Item,{name:"model",rules:[{required:!0,message:"Please enter ".concat(s===sU.Cl.Azure?"a deployment name":"at least one model",".")}],noStyle:!0,children:s===sU.Cl.Azure||s===sU.Cl.OpenAI_Compatible||s===sU.Cl.Ollama?(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(_.Z,{placeholder:l(s),onChange:s===sU.Cl.Azure?e=>{let s=e.target.value,t=s?[{public_name:s,litellm_model:"azure/".concat(s)}]:[];a.setFieldsValue({model:s,model_mappings:t})}:void 0})}):t.length>0?(0,c.jsx)(I.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let t=Array.isArray(e)?e:[e];if(t.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(t)){let e=t.map(e=>s===sU.Cl.Azure?{public_name:e,litellm_model:"azure/".concat(e)}:{public_name:e,litellm_model:e});a.setFieldsValue({model:t,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...t.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,c.jsx)(_.Z,{placeholder:l(s)})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:t}=e,l=t("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,c.jsx)(A.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,c.jsx)(_.Z,{placeholder:s===sU.Cl.Azure?"Enter Azure deployment name":"Enter custom model name",onChange:r})})}})]}),(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:14,children:(0,c.jsx)(k.Z,{className:"mb-3 mt-1",children:s===sU.Cl.Azure?"Your deployment name will be saved as the public model name, and LiteLLM will use 'azure/deployment-name' internally":"The model name LiteLLM will send to the LLM API"})})]})]})},tL=t(67187);let tT=e=>{let{content:s,children:t,width:l="auto",className:a=""}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)("top"),m=(0,d.useRef)(null),u=()=>{if(m.current){let e=m.current.getBoundingClientRect(),s=e.top,t=window.innerHeight-e.bottom;s<300&&t>300?o("bottom"):o("top")}};return(0,c.jsxs)("div",{className:"relative inline-block",ref:m,children:[t||(0,c.jsx)(tL.Z,{className:"ml-1 text-gray-500 cursor-help",onMouseEnter:()=>{u(),i(!0)},onMouseLeave:()=>i(!1)}),r&&(0,c.jsxs)("div",{className:"absolute left-1/2 -translate-x-1/2 z-50 bg-black/90 text-white p-2 rounded-md text-sm font-normal shadow-lg ".concat(a),style:{["top"===n?"bottom":"top"]:"100%",width:l,marginBottom:"top"===n?"8px":"0",marginTop:"bottom"===n?"8px":"0"},children:[s,(0,c.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2 w-0 h-0",style:{top:"top"===n?"100%":"auto",bottom:"bottom"===n?"100%":"auto",borderTop:"top"===n?"6px solid rgba(0, 0, 0, 0.9)":"6px solid transparent",borderBottom:"bottom"===n?"6px solid rgba(0, 0, 0, 0.9)":"6px solid transparent",borderLeft:"6px solid transparent",borderRight:"6px solid transparent"}})]})]})};var tP=()=>{let e=A.Z.useFormInstance(),[s,t]=(0,d.useState)(0),l=A.Z.useWatch("model",e)||[],a=Array.isArray(l)?l:[l],r=A.Z.useWatch("custom_model_name",e),i=!a.includes("all-wildcard"),n=A.Z.useWatch("custom_llm_provider",e);if((0,d.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?n===sU.Cl.Azure?{public_name:r,litellm_model:"azure/".concat(r)}:{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),t(e=>e+1)}},[r,a,n,e]),(0,d.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>"custom"===e?"custom"===s.litellm_model||s.litellm_model===r:n===sU.Cl.Azure?s.litellm_model==="azure/".concat(e):s.litellm_model===e))){let s=a.map(e=>"custom"===e&&r?n===sU.Cl.Azure?{public_name:r,litellm_model:"azure/".concat(r)}:{public_name:r,litellm_model:r}:n===sU.Cl.Azure?{public_name:e,litellm_model:"azure/".concat(e)}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),t(e=>e+1)}}},[a,r,n,e]),!i)return null;let o=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mb-2 font-normal",children:"The name you specify in your API calls to LiteLLM Proxy"}),(0,c.jsxs)("div",{className:"mb-2 font-normal",children:[(0,c.jsx)("strong",{children:"Example:"})," If you name your public model ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"example-name"}),", and choose ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"openai/qwen-plus-latest"})," as the LiteLLM model"]}),(0,c.jsxs)("div",{className:"mb-2 font-normal",children:[(0,c.jsx)("strong",{children:"Usage:"})," You make an API call to the LiteLLM proxy with ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:'model = "example-name"'})]}),(0,c.jsxs)("div",{className:"font-normal",children:[(0,c.jsx)("strong",{children:"Result:"})," LiteLLM sends ",(0,c.jsx)("code",{className:"bg-gray-700 px-1 py-0.5 rounded text-xs",children:"qwen-plus-latest"})," to the provider"]})]}),m=(0,c.jsx)("div",{children:"The model name LiteLLM will send to the LLM API"}),u=[{title:(0,c.jsxs)("span",{className:"flex items-center",children:["Public Model Name",(0,c.jsx)(tT,{content:o,width:"500px"})]}),dataIndex:"public_name",key:"public_name",render:(s,t,l)=>(0,c.jsx)(sW.o,{value:s,onChange:s=>{let t=[...e.getFieldValue("model_mappings")];t[l].public_name=s.target.value,e.setFieldValue("model_mappings",t)}})},{title:(0,c.jsxs)("span",{className:"flex items-center",children:["LiteLLM Model Name",(0,c.jsx)(tT,{content:m,width:"360px"})]}),dataIndex:"litellm_model",key:"litellm_model"}];return(0,c.jsx)(c.Fragment,{children:(0,c.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",rules:[{required:!0,validator:async(e,s)=>{if(!s||0===s.length)throw Error("At least one model mapping is required");if(s.filter(e=>!e.public_name||""===e.public_name.trim()).length>0)throw Error("All model mappings must have valid public names")}}],children:(0,c.jsx)(em.Z,{dataSource:e.getFieldValue("model_mappings"),columns:u,pagination:!1,size:"small"},s)})})},tE=t(90464);let{Link:tM}=en.default;var tO=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:t,teams:l,guardrailsList:a}=e,[r]=A.Z.useForm(),[i,n]=d.useState(!1),[o,m]=d.useState("per_token"),[u,x]=d.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),p=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)(N.Z,{className:"mt-2 mb-4",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Advanced Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,c.jsx)(A.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,c.jsx)(tj.Z,{onChange:e=>{n(e),e||r.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails. Go to 'Guardrails' tab to create new guardrails.",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:a.map(e=>({value:e,label:e}))})}),i&&(0,c.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,c.jsx)(A.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,c.jsx)(I.default,{defaultValue:"per_token",onChange:e=>m(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===o?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})})]}):(0,c.jsx)(A.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,c.jsx)(_.Z,{})})]}),(0,c.jsx)(A.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,c.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,c.jsx)(tM,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,c.jsx)(tj.Z,{onChange:e=>{let s=r.getFieldValue("litellm_extra_params");try{let t=s?JSON.parse(s):{};e?t.use_in_pass_through=!0:delete t.use_in_pass_through,Object.keys(t).length>0?r.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):r.setFieldValue("litellm_extra_params","")}catch(s){e?r.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):r.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,c.jsx)(tb,{form:r,showCacheControl:u,onCacheControlChange:e=>{if(x(e),!e){let e=r.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?r.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):r.setFieldValue("litellm_extra_params","")}catch(e){r.setFieldValue("litellm_extra_params","")}}}}),(0,c.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:p}],children:(0,c.jsx)(tE.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,c.jsxs)(sK.Z,{className:"mb-4",children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,c.jsx)(tM,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,c.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:p}],children:(0,c.jsx)(tE.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},tD=t(29),tF=t.n(tD),tR=t(23639);let{Text:tz}=en.default;var tU=e=>{let{formValues:s,accessToken:t,testMode:l,modelName:a="this model",onClose:r,onTestComplete:i}=e,[n,o]=d.useState(null),[m,u]=d.useState(null),[x,h]=d.useState(null),[p,g]=d.useState(!0),[f,v]=d.useState(!1),[y,b]=d.useState(!1),_=async()=>{g(!0),b(!1),o(null),u(null),h(null),v(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sq(s,t,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),v(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:i,modelName:n}=a[0],c=await (0,j.testConnectionRequest)(t,r,null==i?void 0:i.mode);if("success"===c.status)eo.Z.success("Connection test successful!"),o(null),v(!0);else{var e,l;let s=(null===(e=c.result)||void 0===e?void 0:e.error)||c.message||"Unknown error";o(s),u(r),h(null===(l=c.result)||void 0===l?void 0:l.raw_request_typed_dict),v(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),v(!1)}finally{g(!1),i&&i()}};d.useEffect(()=>{let e=setTimeout(()=>{_()},200);return()=>clearTimeout(e)},[]);let N=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",Z="string"==typeof n?N(n):(null==n?void 0:n.message)?N(n.message):"Unknown error",w=x?((e,s,t)=>{let l=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(t).map(e=>{let[s,t]=e;return"-H '".concat(s,": ").concat(t,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(l,"\n }'")})(x.raw_request_api_base,x.raw_request_body,x.raw_request_headers||{}):"";return(0,c.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,c.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,c.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,c.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,c.jsxs)(tz,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,c.jsx)(tF(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):f?(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"32px 20px"},children:[(0,c.jsx)("div",{style:{color:"#52c41a",fontSize:"24px",display:"flex",alignItems:"center"},children:(0,c.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,c.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,c.jsxs)(tz,{type:"success",style:{fontSize:"18px",fontWeight:500,marginLeft:"10px"},children:["Connection to ",a," successful!"]})]}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,c.jsx)(eg.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,c.jsxs)(tz,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,c.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,c.jsx)(tz,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:Z}),n&&(0,c.jsx)("div",{style:{marginTop:"12px"},children:(0,c.jsx)(P.ZP,{type:"link",onClick:()=>b(!y),style:{paddingLeft:0,height:"auto"},children:y?"Hide Details":"Show Details"})})]}),y&&(0,c.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,c.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof n?n:JSON.stringify(n,null,2)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(tz,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,c.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,c.jsx)(P.ZP,{style:{marginTop:"8px"},icon:(0,c.jsx)(tR.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),eo.Z.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,c.jsx)(K.Z,{style:{margin:"24px 0 16px"}}),(0,c.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,c.jsx)(P.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,c.jsx)(B.Z,{}),children:"View Documentation"})})]})};let tq=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"},{value:"batch",label:"Batch - /batch"}];var tB=t(92858);let tV=async(e,s,t,l)=>{try{console.log("=== AUTO ROUTER SUBMIT HANDLER CALLED ==="),console.log("handling auto router submit for formValues:",e),console.log("Access token:",s?"Present":"Missing"),console.log("Form:",t?"Present":"Missing"),console.log("Callback:",l?"Present":"Missing");let a={model_name:e.auto_router_name,litellm_params:{model:"auto_router/".concat(e.auto_router_name),auto_router_config:JSON.stringify(e.auto_router_config),auto_router_default_model:e.auto_router_default_model},model_info:{}};e.auto_router_embedding_model&&"custom"!==e.auto_router_embedding_model?a.litellm_params.auto_router_embedding_model=e.auto_router_embedding_model:e.custom_embedding_model&&(a.litellm_params.auto_router_embedding_model=e.custom_embedding_model),e.team_id&&(a.model_info.team_id=e.team_id),e.model_access_group&&e.model_access_group.length>0&&(a.model_info.access_groups=e.model_access_group),console.log("Auto router configuration to be created:",a),console.log("Auto router config (stringified):",a.litellm_params.auto_router_config),console.log("Calling modelCreateCall with:",{accessToken:s?"Present":"Missing",config:a});let r=await (0,j.modelCreateCall)(s,a);console.log("response for auto router create call:",r),t.resetFields()}catch(e){console.error("Failed to add auto router:",e),eo.Z.fromBackend("Failed to add auto router: "+e)}},{Title:tK,Link:tG}=en.default;var tH=e=>{let{form:s,handleOk:t,accessToken:l,userRole:a}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)([]),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1),[N,Z]=(0,d.useState)(null);(0,d.useEffect)(()=>{(async()=>{h((await (0,j.modelAvailableCall)(l,"","",!1,null,!0,!0)).data.map(e=>e.id))})()},[l]),(0,d.useEffect)(()=>{(async()=>{try{let e=await eU(l);console.log("Fetched models for auto router:",e),g(e)}catch(e){console.error("Error fetching model info for auto router:",e)}})()},[l]);let w=eI.ZL.includes(a),S=async()=>{o(!0),u("test-".concat(Date.now())),i(!0)},C=()=>{console.log("Auto router submit triggered!"),console.log("Router config:",N);let e=s.getFieldsValue();if(console.log("Form values:",e),!e.auto_router_name){eo.Z.fromBackend("Please enter an Auto Router Name");return}if(!e.auto_router_default_model){eo.Z.fromBackend("Please select a Default Model");return}if(s.setFieldsValue({custom_llm_provider:"auto_router",model:e.auto_router_name,api_key:"not_required_for_auto_router"}),!N||!N.routes||0===N.routes.length){eo.Z.fromBackend("Please configure at least one route for the auto router");return}if(N.routes.filter(e=>!e.name||!e.description||0===e.utterances.length).length>0){eo.Z.fromBackend("Please ensure all routes have a target model, description, and at least one utterance");return}s.validateFields().then(e=>{console.log("Form validation passed, submitting with values:",e);let a={...e,auto_router_config:N};console.log("Final submit values:",a),tV(a,l,s,t)}).catch(e=>{console.error("Validation failed:",e);let s=e.errorFields||[];if(s.length>0){let e=s.map(e=>{let s=e.name[0];return({auto_router_name:"Auto Router Name",auto_router_default_model:"Default Model",auto_router_embedding_model:"Embedding Model"})[s]||s});eo.Z.fromBackend("Please fill in the following required fields: ".concat(e.join(", ")))}else eo.Z.fromBackend("Please fill in all required fields")})};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(tK,{level:2,children:"Add Auto Router"}),(0,c.jsx)(k.Z,{className:"text-gray-600 mb-6",children:"Create an auto router with intelligent routing logic that automatically selects the best model based on user input patterns and semantic matching."}),(0,c.jsx)(tN.Z,{children:(0,c.jsxs)(A.Z,{form:s,onFinish:C,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Auto router name is required"}],label:"Auto Router Name",name:"auto_router_name",tooltip:"Unique name for this auto router configuration",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(_.Z,{placeholder:"e.g., auto_router_1, smart_routing"})}),(0,c.jsx)("div",{className:"w-full mb-4",children:(0,c.jsx)(tS,{modelInfo:p,value:N,onChange:e=>{Z(e),s.setFieldValue("auto_router_config",e)}})}),(0,c.jsx)(A.Z.Item,{rules:[{required:!0,message:"Default model is required"}],label:"Default Model",name:"auto_router_default_model",tooltip:"Fallback model to use when auto routing logic cannot determine the best model",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(I.default,{placeholder:"Select a default model",onChange:e=>{v("custom"===e)},options:[...Array.from(new Set(p.map(e=>e.model_group))).map(e=>({value:e,label:e})),{value:"custom",label:"Enter custom model name"}],style:{width:"100%"},showSearch:!0})}),(0,c.jsx)(A.Z.Item,{label:"Embedding Model",name:"auto_router_embedding_model",tooltip:"Optional: Embedding model to use for semantic routing decisions",labelCol:{span:10},labelAlign:"left",children:(0,c.jsx)(I.default,{value:s.getFieldValue("auto_router_embedding_model"),placeholder:"Select an embedding model (optional)",onChange:e=>{b("custom"===e),s.setFieldValue("auto_router_embedding_model",e)},options:[...Array.from(new Set(p.map(e=>e.model_group))).map(e=>({value:e,label:e})),{value:"custom",label:"Enter custom model name"}],style:{width:"100%"},showSearch:!0,allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Additional Settings"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),w&&(0,c.jsx)(A.Z.Item,{label:"Model Access Group",name:"model_access_group",className:"mb-4",tooltip:"Use model access groups to control who can access this auto router",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:x.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})}),(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(en.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{className:"space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:S,loading:n,children:"Test Connect"}),(0,c.jsx)(P.ZP,{onClick:()=>{console.log("Add Auto Router button clicked!"),console.log("Current router config:",N),console.log("Current form values:",s.getFieldsValue()),C()},children:"Add Auto Router"})]})]})]})}),(0,c.jsx)(L.Z,{title:"Connection Test Results",open:r,onCancel:()=>{i(!1),o(!1)},footer:[(0,c.jsx)(P.ZP,{onClick:()=>{i(!1),o(!1)},children:"Close"},"close")],width:700,children:r&&(0,c.jsx)(tU,{formValues:s.getFieldsValue(),accessToken:l,testMode:"chat",modelName:s.getFieldValue("auto_router_name"),onClose:()=>{i(!1),o(!1)},onTestComplete:()=>o(!1)},m)})]})};let{Title:tJ,Link:tY}=en.default;var tW=e=>{let{form:s,handleOk:t,selectedProvider:l,setSelectedProvider:a,providerModels:r,setProviderModelsFn:i,getPlaceholder:n,uploadProps:o,showAdvancedSettings:m,setShowAdvancedSettings:u,teams:x,credentials:h,accessToken:p,userRole:g,premiumUser:f}=e,[v]=A.Z.useForm(),[y,b]=(0,d.useState)("chat"),[_,N]=(0,d.useState)(!1),[Z,w]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[T,E]=(0,d.useState)("");(0,d.useEffect)(()=>{(async()=>{try{let e=(await (0,j.getGuardrailsList)(p)).guardrails.map(e=>e.guardrail_name);C(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[p]);let M=async()=>{w(!0),E("test-".concat(Date.now())),N(!0)},[O,D]=(0,d.useState)(!1),[F,R]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{R((await (0,j.modelAvailableCall)(p,"","",!1,null,!0,!0)).data.map(e=>e.id))})()},[p]);let z=eI.ZL.includes(g);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(e1.Z,{className:"w-full",children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Add Model"}),(0,c.jsx)(e0.Z,{children:"Add Auto Router"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(tJ,{level:2,children:"Add Model"}),(0,c.jsx)(tN.Z,{children:(0,c.jsx)(A.Z,{form:s,onFinish:e=>{console.log("\uD83D\uDD25 Form onFinish triggered with values:",e),t()},onFinishFailed:e=>{console.log("\uD83D\uDCA5 Form onFinishFailed triggered:",e)},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(I.default,{showSearch:!0,value:l,onChange:e=>{a(e),i(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(tA,{selectedProvider:l,providerModels:r,getPlaceholder:n}),(0,c.jsx)(tP,{}),(0,c.jsx)(A.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,c.jsx)(I.default,{style:{width:"100%"},value:y,onChange:e=>b(e),options:tq})}),(0,c.jsxs)(sK.Z,{children:[(0,c.jsx)(sG.Z,{span:10}),(0,c.jsx)(sG.Z,{span:10,children:(0,c.jsxs)(k.Z,{className:"mb-5 mt-1",children:[(0,c.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,c.jsx)(tY,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(en.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,c.jsx)(A.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...h.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,t=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",t),t)?(0,c.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,c.jsx)(sY,{selectedProvider:l,uploadProps:o})}}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Additional Model Info Settings"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{label:"Team-BYOK Model",tooltip:"Only use this model + credential combination for this team. Useful when teams want to onboard their own OpenAI keys.",className:"mb-4",children:(0,c.jsx)(V.Z,{title:f?"":"This is an enterprise-only feature. Upgrade to premium to restrict model+credential combinations to a specific team.",placement:"top",children:(0,c.jsx)(tB.Z,{checked:O,onChange:e=>{D(e),e||s.setFieldValue("team_id",void 0)},disabled:!f})})}),O&&(0,c.jsx)(A.Z.Item,{label:"Select Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team will be able to call this model.",rules:[{required:O&&!z,message:"Please select a team."}],children:(0,c.jsx)(q,{teams:x,disabled:!f})}),z&&(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(A.Z.Item,{label:"Model Access Group",name:"model_access_group",className:"mb-4",tooltip:"Use model access groups to give users access to select models, and add new ones to the group over time.",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"children",tokenSeparators:[","],options:F.map(e=>({value:e,label:e})),maxTagCount:"responsive",allowClear:!0})})}),(0,c.jsx)(tO,{showAdvancedSettings:m,setShowAdvancedSettings:u,teams:x,guardrailsList:S}),(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(V.Z,{title:"Get help on our github",children:(0,c.jsx)(en.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,c.jsxs)("div",{className:"space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:M,loading:Z,children:"Test Connect"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(tH,{form:v,handleOk:()=>{v.validateFields().then(e=>{tV(e,p,v,t)}).catch(e=>{console.error("Validation failed:",e)})},accessToken:p,userRole:g})})]})]}),(0,c.jsx)(L.Z,{title:"Connection Test Results",open:_,onCancel:()=>{N(!1),w(!1)},footer:[(0,c.jsx)(P.ZP,{onClick:()=>{N(!1),w(!1)},children:"Close"},"close")],width:700,children:_&&(0,c.jsx)(tU,{formValues:s.getFieldsValue(),accessToken:p,testMode:y,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{N(!1),w(!1)},onTestComplete:()=>w(!1)},T)})]})},t$=t(8048);let tQ=(e,s,t,l,a,r,i,n,o,d,m)=>[{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model ID"}),accessorKey:"model_info.id",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.model_info.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>l(t.model_info.id),children:t.model_info.id})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model Information"}),accessorKey:"model_name",size:250,cell:e=>{let{row:s}=e,t=s.original,l=r(s.original)||"-",a=(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"Provider:"})," ",t.provider||"-"]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"Public Model Name:"})," ",l]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"LiteLLM Model Name:"})," ",t.litellm_model_name||"-"]})]});return(0,c.jsx)(V.Z,{title:a,children:(0,c.jsxs)("div",{className:"flex items-start space-x-2 min-w-0 w-full max-w-[250px]",children:[(0,c.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:t.provider?(0,c.jsx)("img",{src:(0,sU.dr)(t.provider).logo,alt:"".concat(t.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(e,s)}}}):(0,c.jsx)("div",{className:"w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",children:"-"})}),(0,c.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,c.jsx)("div",{className:"text-xs font-medium text-gray-900 truncate max-w-[210px]",children:l}),(0,c.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5 max-w-[210px]",children:t.litellm_model_name||"-"})]})]})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Credentials"}),accessorKey:"litellm_credential_name",size:180,cell:e=>{var s;let{row:t}=e,l=null===(s=t.original.litellm_params)||void 0===s?void 0:s.litellm_credential_name;return l?(0,c.jsx)(V.Z,{title:"Credential: ".concat(l),children:(0,c.jsxs)("div",{className:"flex items-center space-x-2 max-w-[180px]",children:[(0,c.jsx)(tx.Z,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),(0,c.jsx)("span",{className:"text-xs truncate",title:l,children:l})]})}):(0,c.jsxs)("div",{className:"flex items-center space-x-2 max-w-[180px]",children:[(0,c.jsx)(tx.Z,{className:"w-4 h-4 text-gray-300 flex-shrink-0"}),(0,c.jsx)("span",{className:"text-xs text-gray-400",children:"No credentials"})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Created By"}),accessorKey:"model_info.created_by",sortingFn:"datetime",size:160,cell:e=>{let{row:s}=e,t=s.original,l=t.model_info.created_by,a=t.model_info.created_at?new Date(t.model_info.created_at).toLocaleDateString():null;return(0,c.jsxs)("div",{className:"flex flex-col min-w-0 max-w-[160px]",children:[(0,c.jsx)("div",{className:"text-xs font-medium text-gray-900 truncate",title:l||"Unknown",children:l||"Unknown"}),(0,c.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",title:a||"Unknown date",children:a||"Unknown date"})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Updated At"}),accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.model_info.updated_at?new Date(t.model_info.updated_at).toLocaleDateString():"-"})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Costs"}),accessorKey:"input_cost",size:120,cell:e=>{let{row:s}=e,t=s.original,l=t.input_cost,a=t.output_cost;return l||a?(0,c.jsx)(V.Z,{title:"Cost per 1M tokens",children:(0,c.jsxs)("div",{className:"flex flex-col min-w-0 max-w-[120px]",children:[l&&(0,c.jsxs)("div",{className:"text-xs font-medium text-gray-900 truncate",children:["In: $",l]}),a&&(0,c.jsxs)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:["Out: $",a]})]})}):(0,c.jsx)("div",{className:"max-w-[120px]",children:(0,c.jsx)("span",{className:"text-xs text-gray-400",children:"-"})})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Team ID"}),accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,t=s.original;return t.model_info.team_id?(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:t.model_info.team_id,children:(0,c.jsxs)(b.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:()=>a(t.model_info.team_id),children:[t.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Model Access Group"}),accessorKey:"model_info.model_access_group",enableSorting:!1,cell:e=>{let{row:s}=e,t=s.original,l=t.model_info.access_groups;if(!l||0===l.length)return"-";let a=t.model_info.id,r=d.has(a),i=l.length>1,n=()=>{let e=new Set(d);r?e.delete(a):e.add(a),m(e)};return(0,c.jsxs)("div",{className:"flex items-center gap-1 overflow-hidden",children:[(0,c.jsx)(eX.Z,{size:"xs",color:"blue",className:"text-xs px-1.5 py-0.5 h-5 leading-tight flex-shrink-0",children:l[0]}),(r||!i&&2===l.length)&&l.slice(1).map((e,s)=>(0,c.jsx)(eX.Z,{size:"xs",color:"blue",className:"text-xs px-1.5 py-0.5 h-5 leading-tight flex-shrink-0",children:e},s+1)),i&&(0,c.jsx)("button",{onClick:e=>{e.stopPropagation(),n()},className:"text-xs text-blue-600 hover:text-blue-800 px-1 py-0.5 rounded hover:bg-blue-50 h-5 leading-tight flex-shrink-0 whitespace-nowrap",children:r?"−":"+".concat(l.length-1)})]})}},{header:()=>(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Status"}),accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(t.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:t.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:t=>{var a;let{row:r}=t,i=r.original,n="Admin"===e||(null===(a=i.model_info)||void 0===a?void 0:a.created_by)===s;return(0,c.jsx)("div",{className:"flex items-center justify-end gap-2 pr-4",children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>{n&&(l(i.model_info.id),o(!1))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"})})}}];var tX=t(93142),t0=t(867),t1=t(3810),t2=t(5540),t4=t(8881);let{Text:t5}=en.default;var t6=e=>{let{accessToken:s,onReloadSuccess:t,buttonText:l="Reload Price Data",showIcon:a=!0,size:r="middle",type:i="primary",className:n=""}=e,[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)(6),[b,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(!1);(0,d.useEffect)(()=>{w();let e=setInterval(()=>{w()},3e4);return()=>clearInterval(e)},[s]);let w=async()=>{if(s){Z(!0);try{console.log("Fetching reload status...");let e=await (0,j.getModelCostMapReloadStatus)(s);console.log("Received status:",e),_(e)}catch(e){console.error("Failed to fetch reload status:",e),_({scheduled:!1,interval_hours:null,last_run:null,next_run:null})}finally{Z(!1)}}},k=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}m(!0);try{let e=await (0,j.reloadModelCostMap)(s);"success"===e.status?(eo.Z.success("Price data reloaded successfully! ".concat(e.models_count||0," models updated.")),null==t||t(),await w()):eo.Z.fromBackend("Failed to reload price data")}catch(e){console.error("Error reloading price data:",e),eo.Z.fromBackend("Failed to reload price data. Please try again.")}finally{m(!1)}},S=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}if(v<=0){eo.Z.fromBackend("Hours must be greater than 0");return}x(!0);try{let e=await (0,j.scheduleModelCostMapReload)(s,v);"success"===e.status?(eo.Z.success("Periodic reload scheduled for every ".concat(v," hours")),f(!1),await w()):eo.Z.fromBackend("Failed to schedule periodic reload")}catch(e){console.error("Error scheduling reload:",e),eo.Z.fromBackend("Failed to schedule periodic reload. Please try again.")}finally{x(!1)}},C=async()=>{if(!s){eo.Z.fromBackend("No access token available");return}p(!0);try{let e=await (0,j.cancelModelCostMapReload)(s);"success"===e.status?(eo.Z.success("Periodic reload cancelled successfully"),await w()):eo.Z.fromBackend("Failed to cancel periodic reload")}catch(e){console.error("Error cancelling reload:",e),eo.Z.fromBackend("Failed to cancel periodic reload. Please try again.")}finally{p(!1)}},I=e=>{if(!e)return"Never";try{return new Date(e).toLocaleString()}catch(s){return e}};return(0,c.jsxs)("div",{className:n,children:[(0,c.jsxs)(tX.Z,{direction:"horizontal",size:"middle",style:{marginBottom:16},children:[(0,c.jsx)(t0.Z,{title:"Hard Refresh Price Data",description:"This will immediately fetch the latest pricing information from the remote source. Continue?",onConfirm:k,okText:"Yes",cancelText:"No",okButtonProps:{style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem",transition:"all 0.2s ease-in-out"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#4f46e5"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1"}},children:(0,c.jsx)(P.ZP,{type:i,size:r,loading:o,icon:a?(0,c.jsx)(tl.Z,{}):void 0,style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem",transition:"all 0.2s ease-in-out"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#4f46e5"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1"},children:l})}),(null==b?void 0:b.scheduled)?(0,c.jsx)(P.ZP,{type:"default",size:r,danger:!0,icon:(0,c.jsx)(t4.Z,{}),loading:h,onClick:C,style:{borderColor:"#ff4d4f",color:"#ff4d4f",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem"},children:"Cancel Periodic Reload"}):(0,c.jsx)(P.ZP,{type:"default",size:r,icon:(0,c.jsx)(t2.Z,{}),onClick:()=>f(!0),style:{borderColor:"#d9d9d9",color:"#6366f1",fontWeight:"500",borderRadius:"0.375rem",padding:"0.375rem 0.75rem",height:"auto",fontSize:"0.875rem",lineHeight:"1.25rem"},children:"Set Up Periodic Reload"})]}),b&&(0,c.jsx)(tN.Z,{size:"small",style:{backgroundColor:"#f8f9fa",border:"1px solid #e9ecef",borderRadius:8},children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"small",style:{width:"100%"},children:[b.scheduled?(0,c.jsx)("div",{children:(0,c.jsxs)(t1.Z,{color:"green",icon:(0,c.jsx)(t2.Z,{}),children:["Scheduled every ",b.interval_hours," hours"]})}):(0,c.jsx)(t5,{type:"secondary",children:"No periodic reload scheduled"}),(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Last run:"}),(0,c.jsx)(t5,{style:{fontSize:"12px"},children:I(b.last_run)})]}),b.scheduled&&(0,c.jsxs)(c.Fragment,{children:[b.next_run&&(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Next run:"}),(0,c.jsx)(t5,{style:{fontSize:"12px"},children:I(b.next_run)})]}),(0,c.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsx)(t5,{type:"secondary",style:{fontSize:"12px"},children:"Status:"}),(0,c.jsx)(t1.Z,{color:(null==b?void 0:b.scheduled)?b.last_run?"success":"processing":"default",children:(null==b?void 0:b.scheduled)?b.last_run?"Active":"Ready":"Not scheduled"})]})]})]})}),(0,c.jsxs)(L.Z,{title:"Set Up Periodic Reload",open:g,onOk:S,onCancel:()=>f(!1),confirmLoading:u,okText:"Schedule",cancelText:"Cancel",okButtonProps:{style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white"}},children:[(0,c.jsx)("div",{style:{marginBottom:16},children:(0,c.jsx)(t5,{children:"Set up automatic reload of price data every:"})}),(0,c.jsx)("div",{style:{marginBottom:16},children:(0,c.jsx)(eW.Z,{min:1,max:168,value:v,onChange:e=>y(e||6),addonAfter:"hours",style:{width:"100%"}})}),(0,c.jsx)("div",{children:(0,c.jsxs)(t5,{type:"secondary",children:["This will automatically fetch the latest pricing data from the remote source every ",v," hours."]})})]})]})},t3=t(15731),t8=t(91126);let t7=(e,s,t,l,a,r,i,n,o,d,m)=>[{header:()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(ts.Z,{checked:t,indeterminate:s.length>0&&!t,onChange:e=>a(e.target.checked),onClick:e=>e.stopPropagation()}),(0,c.jsx)("span",{children:"Model ID"})]}),accessorKey:"model_info.id",enableSorting:!0,sortingFn:"alphanumeric",cell:e=>{let{row:t}=e,a=t.original,r=a.model_name,i=s.includes(r);return(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(ts.Z,{checked:i,onChange:e=>l(r,e.target.checked),onClick:e=>e.stopPropagation()}),(0,c.jsx)(V.Z,{title:a.model_info.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>m&&m(a.model_info.id),children:a.model_info.id})})]})}},{header:"Model Name",accessorKey:"model_name",enableSorting:!0,sortingFn:"alphanumeric",cell:e=>{let{row:s}=e,t=s.original,l=n(t)||t.model_name;return(0,c.jsx)("div",{className:"font-medium text-sm",children:(0,c.jsx)(V.Z,{title:l,children:(0,c.jsx)("div",{className:"truncate max-w-[200px]",children:l})})})}},{header:"Health Status",accessorKey:"health_status",enableSorting:!0,sortingFn:(e,s,t)=>{var l,a;let r=e.getValue("health_status")||"unknown",i=s.getValue("health_status")||"unknown",n={healthy:0,checking:1,unknown:2,unhealthy:3};return(null!==(l=n[r])&&void 0!==l?l:4)-(null!==(a=n[i])&&void 0!==a?a:4)},cell:s=>{var t;let{row:l}=s,a=l.original,r={status:a.health_status,loading:a.health_loading,error:a.health_error};if(r.loading)return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse"}),(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse",style:{animationDelay:"0.2s"}}),(0,c.jsx)("div",{className:"w-2 h-2 bg-indigo-500 rounded-full animate-pulse",style:{animationDelay:"0.4s"}})]}),(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:"Checking..."})]});let n=a.model_name,o="healthy"===r.status&&(null===(t=e[n])||void 0===t?void 0:t.successResponse);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[i(r.status),o&&d&&(0,c.jsx)(V.Z,{title:"View response details",placement:"top",children:(0,c.jsx)("button",{onClick:()=>{var s;return d(n,null===(s=e[n])||void 0===s?void 0:s.successResponse)},className:"p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded cursor-pointer transition-colors",children:(0,c.jsx)(t3.Z,{className:"h-4 w-4"})})})]})}},{header:"Error Details",accessorKey:"health_error",enableSorting:!1,cell:s=>{let{row:t}=s,l=t.original.model_name,a=e[l];if(!(null==a?void 0:a.error))return(0,c.jsx)(k.Z,{className:"text-gray-400 text-sm",children:"No errors"});let r=a.error,i=a.fullError||a.error;return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"max-w-[200px]",children:(0,c.jsx)(V.Z,{title:r,placement:"top",children:(0,c.jsx)(k.Z,{className:"text-red-600 text-sm truncate",children:r})})}),o&&i!==r&&(0,c.jsx)(V.Z,{title:"View full error details",placement:"top",children:(0,c.jsx)("button",{onClick:()=>o(l,r,i),className:"p-1 text-red-600 hover:text-red-800 hover:bg-red-50 rounded cursor-pointer transition-colors",children:(0,c.jsx)(t3.Z,{className:"h-4 w-4"})})})]})}},{header:"Last Check",accessorKey:"last_check",enableSorting:!0,sortingFn:(e,s,t)=>{let l=e.getValue("last_check")||"Never checked",a=s.getValue("last_check")||"Never checked";if("Never checked"===l&&"Never checked"===a)return 0;if("Never checked"===l)return 1;if("Never checked"===a)return -1;if("Check in progress..."===l&&"Check in progress..."===a)return 0;if("Check in progress..."===l)return -1;if("Check in progress..."===a)return 1;let r=new Date(l),i=new Date(a);return isNaN(r.getTime())&&isNaN(i.getTime())?0:isNaN(r.getTime())?1:isNaN(i.getTime())?-1:i.getTime()-r.getTime()},cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:t.health_loading?"Check in progress...":t.last_check})}},{header:"Last Success",accessorKey:"last_success",enableSorting:!0,sortingFn:(e,s,t)=>{let l=e.getValue("last_success")||"Never succeeded",a=s.getValue("last_success")||"Never succeeded";if("Never succeeded"===l&&"Never succeeded"===a)return 0;if("Never succeeded"===l)return 1;if("Never succeeded"===a)return -1;if("None"===l&&"None"===a)return 0;if("None"===l)return 1;if("None"===a)return -1;let r=new Date(l),i=new Date(a);return isNaN(r.getTime())&&isNaN(i.getTime())?0:isNaN(r.getTime())?1:isNaN(i.getTime())?-1:i.getTime()-r.getTime()},cell:s=>{let{row:t}=s,l=e[t.original.model_name],a=(null==l?void 0:l.lastSuccess)||"None";return(0,c.jsx)(k.Z,{className:"text-gray-600 text-sm",children:a})}},{header:"Actions",id:"actions",cell:e=>{let{row:s}=e,t=s.original,l=t.model_name,a=t.health_status&&"none"!==t.health_status,i=t.health_loading?"Checking...":a?"Re-run Health Check":"Run Health Check";return(0,c.jsx)(V.Z,{title:i,placement:"top",children:(0,c.jsx)("button",{className:"p-2 rounded-md transition-colors ".concat(t.health_loading?"text-gray-400 cursor-not-allowed bg-gray-100":"text-indigo-600 hover:text-indigo-700 hover:bg-indigo-50"),onClick:()=>{t.health_loading||r(l)},disabled:t.health_loading,children:t.health_loading?(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse"}),(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"0.2s"}}),(0,c.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"0.4s"}})]}):a?(0,c.jsx)(e3.Z,{className:"h-4 w-4"}):(0,c.jsx)(t8.Z,{className:"h-4 w-4"})})})},enableSorting:!1}],t9=[{pattern:/Missing .* API Key/i,replacement:"Missing API Key"},{pattern:/Connection timeout/i,replacement:"Connection timeout"},{pattern:/Network.*not.*ok/i,replacement:"Network connection failed"},{pattern:/403.*Forbidden/i,replacement:"Access forbidden - check API key permissions"},{pattern:/401.*Unauthorized/i,replacement:"Unauthorized - invalid API key"},{pattern:/429.*rate limit/i,replacement:"Rate limit exceeded"},{pattern:/500.*Internal Server Error/i,replacement:"Provider internal server error"},{pattern:/litellm\.AuthenticationError/i,replacement:"Authentication failed"},{pattern:/litellm\.RateLimitError/i,replacement:"Rate limit exceeded"},{pattern:/litellm\.APIError/i,replacement:"API error"}];var le=e=>{let{accessToken:s,modelData:t,all_models_on_proxy:l,getDisplayModelName:a,setSelectedModelId:r}=e,[i,n]=(0,d.useState)({}),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(null),[v,y]=(0,d.useState)(!1),[_,N]=(0,d.useState)(null),Z=(0,d.useRef)(null);(0,d.useEffect)(()=>{s&&(null==t?void 0:t.data)&&(async()=>{let e={};t.data.forEach(s=>{e[s.model_name]={status:"none",lastCheck:"None",lastSuccess:"None",loading:!1,error:void 0,fullError:void 0,successResponse:void 0}});try{let l=await (0,j.latestHealthChecksCall)(s);l&&l.latest_health_checks&&"object"==typeof l.latest_health_checks&&Object.entries(l.latest_health_checks).forEach(s=>{let[l,a]=s;if(!a)return;let r=null,i=t.data.find(e=>e.model_name===l);if(i)r=i.model_name;else{let e=t.data.find(e=>e.model_info&&e.model_info.id===l);if(e)r=e.model_name;else if(a.model_name){let e=t.data.find(e=>e.model_name===a.model_name);e&&(r=e.model_name)}}if(r){let s=a.error_message||void 0;e[r]={status:a.status||"unknown",lastCheck:a.checked_at?new Date(a.checked_at).toLocaleString():"None",lastSuccess:"healthy"===a.status&&a.checked_at?new Date(a.checked_at).toLocaleString():"None",loading:!1,error:s?w(s):void 0,fullError:s,successResponse:"healthy"===a.status?a:void 0}}})}catch(e){console.warn("Failed to load health check history (using default states):",e)}n(e)})()},[s,t]);let w=e=>{var s;if(!e)return"Health check failed";let t="string"==typeof e?e:JSON.stringify(e),l=t.match(/(\w+Error):\s*(\d{3})/i);if(l)return"".concat(l[1],": ").concat(l[2]);let a=t.match(/(AuthenticationError|RateLimitError|BadRequestError|InternalServerError|TimeoutError|NotFoundError|ForbiddenError|ServiceUnavailableError|BadGatewayError|ContentPolicyViolationError|\w+Error)/i),r=t.match(/\b(400|401|403|404|408|429|500|502|503|504)\b/);if(a&&r)return"".concat(a[1],": ").concat(r[1]);if(r){let e=r[1];return"".concat({400:"BadRequestError",401:"AuthenticationError",403:"ForbiddenError",404:"NotFoundError",408:"TimeoutError",429:"RateLimitError",500:"InternalServerError",502:"BadGatewayError",503:"ServiceUnavailableError",504:"GatewayTimeoutError"}[e],": ").concat(e)}if(a){let e=a[1],s={AuthenticationError:"401",RateLimitError:"429",BadRequestError:"400",InternalServerError:"500",TimeoutError:"408",NotFoundError:"404",ForbiddenError:"403",ServiceUnavailableError:"503",BadGatewayError:"502",GatewayTimeoutError:"504",ContentPolicyViolationError:"400"}[e];return s?"".concat(e,": ").concat(s):e}for(let{pattern:e,replacement:s}of t9)if(e.test(t))return s;if(/missing.*api.*key|invalid.*key|unauthorized/i.test(t))return"AuthenticationError: 401";if(/rate.*limit|too.*many.*requests/i.test(t))return"RateLimitError: 429";if(/timeout|timed.*out/i.test(t))return"TimeoutError: 408";if(/not.*found/i.test(t))return"NotFoundError: 404";if(/forbidden|access.*denied/i.test(t))return"ForbiddenError: 403";if(/internal.*server.*error/i.test(t))return"InternalServerError: 500";let i=t.replace(/[\n\r]+/g," ").replace(/\s+/g," ").trim(),n=null===(s=i.split(/[.!?]/)[0])||void 0===s?void 0:s.trim();return n&&n.length>0?n.length>100?n.substring(0,97)+"...":n:i.length>100?i.substring(0,97)+"...":i},C=async e=>{if(s){n(s=>({...s,[e]:{...s[e],loading:!0,status:"checking"}}));try{var l,a;let r=await (0,j.individualModelHealthCheckCall)(s,e),i=new Date().toLocaleString();if(r.unhealthy_count>0&&r.unhealthy_endpoints&&r.unhealthy_endpoints.length>0){let s=(null===(l=r.unhealthy_endpoints[0])||void 0===l?void 0:l.error)||"Health check failed",t=w(s);n(l=>{var a;return{...l,[e]:{status:"unhealthy",lastCheck:i,lastSuccess:(null===(a=l[e])||void 0===a?void 0:a.lastSuccess)||"None",loading:!1,error:t,fullError:s}}})}else n(s=>({...s,[e]:{status:"healthy",lastCheck:i,lastSuccess:i,loading:!1,successResponse:r}}));try{let l=await (0,j.latestHealthChecksCall)(s),r=t.data.find(s=>s.model_name===e);if(r){let s=r.model_info.id,t=null===(a=l.latest_health_checks)||void 0===a?void 0:a[s];if(t){let s=t.error_message||void 0;n(l=>{var a,r,i,n,o,c,d;return{...l,[e]:{status:t.status||(null===(a=l[e])||void 0===a?void 0:a.status)||"unknown",lastCheck:t.checked_at?new Date(t.checked_at).toLocaleString():(null===(r=l[e])||void 0===r?void 0:r.lastCheck)||"None",lastSuccess:"healthy"===t.status?t.checked_at?new Date(t.checked_at).toLocaleString():(null===(i=l[e])||void 0===i?void 0:i.lastSuccess)||"None":(null===(n=l[e])||void 0===n?void 0:n.lastSuccess)||"None",loading:!1,error:s?w(s):null===(o=l[e])||void 0===o?void 0:o.error,fullError:s||(null===(c=l[e])||void 0===c?void 0:c.fullError),successResponse:"healthy"===t.status?t:null===(d=l[e])||void 0===d?void 0:d.successResponse}}})}}}catch(e){console.debug("Could not fetch updated status from database (non-critical):",e)}}catch(a){let s=new Date().toLocaleString(),t=a instanceof Error?a.message:String(a),l=w(t);n(a=>{var r;return{...a,[e]:{status:"unhealthy",lastCheck:s,lastSuccess:(null===(r=a[e])||void 0===r?void 0:r.lastSuccess)||"None",loading:!1,error:l,fullError:t}}})}}},I=async()=>{let e=o.length>0?o:l,a=e.reduce((e,s)=>(e[s]={...i[s],loading:!0,status:"checking"},e),{});n(e=>({...e,...a}));let r={},c=e.map(async e=>{if(s)try{let l=await (0,j.individualModelHealthCheckCall)(s,e);r[e]=l;let a=new Date().toLocaleString();if(l.unhealthy_count>0&&l.unhealthy_endpoints&&l.unhealthy_endpoints.length>0){var t;let s=(null===(t=l.unhealthy_endpoints[0])||void 0===t?void 0:t.error)||"Health check failed",r=w(s);n(t=>{var l;return{...t,[e]:{status:"unhealthy",lastCheck:a,lastSuccess:(null===(l=t[e])||void 0===l?void 0:l.lastSuccess)||"None",loading:!1,error:r,fullError:s}}})}else n(s=>({...s,[e]:{status:"healthy",lastCheck:a,lastSuccess:a,loading:!1,successResponse:l}}))}catch(a){console.error("Health check failed for ".concat(e,":"),a);let s=new Date().toLocaleString(),t=a instanceof Error?a.message:String(a),l=w(t);n(a=>{var r;return{...a,[e]:{status:"unhealthy",lastCheck:s,lastSuccess:(null===(r=a[e])||void 0===r?void 0:r.lastSuccess)||"None",loading:!1,error:l,fullError:t}}})}});await Promise.allSettled(c);try{if(!s)return;let l=await (0,j.latestHealthChecksCall)(s);l.latest_health_checks&&Object.entries(l.latest_health_checks).forEach(s=>{let[l,a]=s,r=t.data.find(e=>e.model_info.id===l);if(r&&e.includes(r.model_name)&&a){let e=r.model_name,s=a.error_message||void 0;n(t=>{let l=t[e];return{...t,[e]:{status:a.status||(null==l?void 0:l.status)||"unknown",lastCheck:a.checked_at?new Date(a.checked_at).toLocaleString():(null==l?void 0:l.lastCheck)||"None",lastSuccess:"healthy"===a.status&&a.checked_at?new Date(a.checked_at).toLocaleString():(null==l?void 0:l.lastSuccess)||"None",loading:!1,error:s?w(s):null==l?void 0:l.error,fullError:s||(null==l?void 0:l.fullError),successResponse:"healthy"===a.status?a:null==l?void 0:l.successResponse}}})}})}catch(e){console.warn("Failed to fetch updated health statuses from database (non-critical):",e)}},A=e=>{x(e),e?m(l):m([])},T=()=>{p(!1),f(null)},E=()=>{y(!1),N(null)};return(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"mb-6",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Model Health Status"}),(0,c.jsx)(k.Z,{className:"text-gray-600 mt-1",children:"Run health checks on individual models to verify they are working correctly"})]}),(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[o.length>0&&(0,c.jsx)(b.Z,{size:"sm",variant:"light",onClick:()=>A(!1),className:"px-3 py-1 text-sm",children:"Clear Selection"}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:I,disabled:Object.values(i).some(e=>e.loading),className:"px-3 py-1 text-sm",children:o.length>0&&o.length{s?m(s=>[...s,e]):(m(s=>s.filter(s=>s!==e)),x(!1))},A,C,e=>{switch(e){case"healthy":return(0,c.jsx)(eX.Z,{color:"emerald",children:"healthy"});case"unhealthy":return(0,c.jsx)(eX.Z,{color:"red",children:"unhealthy"});case"checking":return(0,c.jsx)(eX.Z,{color:"blue",children:"checking"});case"none":return(0,c.jsx)(eX.Z,{color:"gray",children:"none"});default:return(0,c.jsx)(eX.Z,{color:"gray",children:"unknown"})}},a,(e,s,t)=>{f({modelName:e,cleanedError:s,fullError:t}),p(!0)},(e,s)=>{N({modelName:e,response:s}),y(!0)},r),data:t.data.map(e=>{let s=i[e.model_name]||{status:"none",lastCheck:"None",loading:!1};return{model_name:e.model_name,model_info:e.model_info,provider:e.provider,litellm_model_name:e.litellm_model_name,health_status:s.status,last_check:s.lastCheck,last_success:s.lastSuccess||"None",health_loading:s.loading,health_error:s.error,health_full_error:s.fullError}}),isLoading:!1,table:Z})}),(0,c.jsx)(L.Z,{title:g?"Health Check Error - ".concat(g.modelName):"Error Details",open:h,onCancel:T,footer:[(0,c.jsx)(P.ZP,{onClick:T,children:"Close"},"close")],width:800,children:g&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Error:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-red-50 border border-red-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-red-800",children:g.cleanedError})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Full Error Details:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md max-h-96 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:g.fullError})})]})]})}),(0,c.jsx)(L.Z,{title:_?"Health Check Response - ".concat(_.modelName):"Response Details",open:v,onCancel:E,footer:[(0,c.jsx)(P.ZP,{onClick:E,children:"Close"},"close")],width:800,children:_&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Status:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-green-50 border border-green-200 rounded-md",children:(0,c.jsx)(k.Z,{className:"text-green-800",children:"Health check passed successfully"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Response Details:"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md max-h-96 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:JSON.stringify(_.response,null,2)})})]})]})})]})},ls=t(61778),lt=t(12660),ll=e=>{let{value:s={},onChange:t}=e,[l,a]=(0,d.useState)(Object.entries(s)),r=e=>{let s=l.filter((s,t)=>t!==e);a(s),null==t||t(Object.fromEntries(s))},i=(e,s,r)=>{let i=[...l];i[e]=[s,r],a(i),null==t||t(Object.fromEntries(i))};return(0,c.jsxs)("div",{children:[l.map((e,s)=>{let[t,l]=e;return(0,c.jsxs)(tX.Z,{style:{display:"flex",marginBottom:8},align:"center",children:[(0,c.jsx)(sW.o,{placeholder:"Header Name",value:t,onChange:e=>i(s,e.target.value,l)}),(0,c.jsx)(sW.o,{placeholder:"Header Value",value:l,onChange:e=>i(s,t,e.target.value)}),(0,c.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%"},children:(0,c.jsx)(tf.Z,{onClick:()=>r(s),style:{cursor:"pointer"}})})]},s)}),(0,c.jsx)(P.ZP,{type:"dashed",onClick:()=>{a([...l,["",""]])},icon:(0,c.jsx)(tv.Z,{}),children:"Add Header"})]})},la=t(77565),lr=e=>{let{pathValue:s,targetValue:t,includeSubpath:l}=e,a=(0,j.getProxyBaseUrl)();return s&&t?(0,c.jsxs)(G.Z,{className:"p-5",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Route Preview"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-5",children:"How your requests will be routed"}),(0,c.jsxs)("div",{className:"space-y-5",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-semibold text-gray-900 mb-3",children:"Basic routing:"}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Your endpoint"}),(0,c.jsx)("code",{className:"font-mono text-sm text-gray-900",children:s?"".concat(a).concat(s):""})]}),(0,c.jsx)("div",{className:"text-gray-400",children:(0,c.jsx)(la.Z,{className:"text-lg"})}),(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Forwards to"}),(0,c.jsx)("code",{className:"font-mono text-sm text-gray-900",children:t})]})]})]}),l&&(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-semibold text-gray-900 mb-3",children:"With subpaths:"}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Your endpoint + subpath"}),(0,c.jsxs)("code",{className:"font-mono text-sm text-gray-900",children:[s&&"".concat(a).concat(s),(0,c.jsx)("span",{className:"text-blue-600",children:"/v1/text-to-image/base/model"})]})]}),(0,c.jsx)("div",{className:"text-gray-400",children:(0,c.jsx)(la.Z,{className:"text-lg"})}),(0,c.jsxs)("div",{className:"flex-1 bg-gray-50 border border-gray-200 rounded-lg p-3",children:[(0,c.jsx)("div",{className:"text-sm text-gray-600 mb-2",children:"Forwards to"}),(0,c.jsxs)("code",{className:"font-mono text-sm text-gray-900",children:[t,(0,c.jsx)("span",{className:"text-blue-600",children:"/v1/text-to-image/base/model"})]})]})]}),(0,c.jsxs)("div",{className:"mt-3 text-sm text-gray-600",children:["Any path after ",s," will be appended to the target URL"]})]})}),!l&&(0,c.jsx)("div",{className:"mt-4 p-3 bg-blue-50 rounded-md border border-blue-200",children:(0,c.jsxs)("div",{className:"flex items-start",children:[(0,c.jsx)(B.Z,{className:"text-blue-500 mt-0.5 mr-2 flex-shrink-0"}),(0,c.jsxs)("div",{className:"text-sm text-blue-700",children:[(0,c.jsx)("span",{className:"font-medium",children:"Not seeing the routing you wanted?"})," Try enabling - Include Subpaths - above - this allows subroutes like ",(0,c.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded font-mono text-xs",children:"/api/v1/models"})," to be forwarded automatically."]})]})})]})]}):null};let{Option:li}=I.default;var ln=e=>{let{accessToken:s,setPassThroughItems:t,passThroughItems:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)(""),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(!0),y=()=>{a.resetFields(),h(""),g(""),v(!0),i(!1)},N=e=>{let s=e;e&&!e.startsWith("/")&&(s="/"+e),h(s),a.setFieldsValue({path:s})},Z=async e=>{console.log("addPassThrough called with:",e),o(!0);try{console.log("formValues: ".concat(JSON.stringify(e)));let r=(await (0,j.createPassThroughEndpoint)(s,e)).endpoints[0],n=[...l,r];t(n),eo.Z.success("Pass-through endpoint created successfully"),a.resetFields(),h(""),g(""),v(!0),i(!1)}catch(e){eo.Z.fromBackend("Error creating pass-through endpoint: "+e)}finally{o(!1)}};return(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{className:"mx-auto mb-4 mt-4",onClick:()=>i(!0),children:"+ Add Pass-Through Endpoint"}),(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:[(0,c.jsx)(lt.Z,{className:"text-xl text-blue-500"}),(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Pass-Through Endpoint"})]}),open:r,width:1e3,onCancel:y,footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsxs)("div",{className:"mt-6",children:[(0,c.jsx)(ls.Z,{message:"What is a Pass-Through Endpoint?",description:"Route requests from your LiteLLM proxy to any external API. Perfect for custom models, image generation APIs, or any service you want to proxy through LiteLLM.",type:"info",showIcon:!0,className:"mb-6"}),(0,c.jsxs)(A.Z,{form:a,onFinish:Z,layout:"vertical",className:"space-y-6",initialValues:{include_subpath:!0,path:x,target:p},children:[(0,c.jsxs)(G.Z,{className:"p-5",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Route Configuration"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-5",children:"Configure how requests to your domain will be forwarded to the target API"}),(0,c.jsxs)("div",{className:"space-y-5",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Path Prefix"}),name:"path",rules:[{required:!0,message:"Path is required",pattern:/^\//}],extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:"Example: /bria, /adobe-photoshop, /elasticsearch"}),className:"mb-4",children:(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)(_.Z,{placeholder:"bria",value:x,onChange:e=>N(e.target.value),className:"flex-1"})})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Target URL"}),name:"target",rules:[{required:!0,message:"Target URL is required"},{type:"url",message:"Please enter a valid URL"}],extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:"Example:https://engine.prod.bria-api.com"}),className:"mb-4",children:(0,c.jsx)(_.Z,{placeholder:"https://engine.prod.bria-api.com",value:p,onChange:e=>{g(e.target.value),a.setFieldsValue({target:e.target.value})}})}),(0,c.jsxs)("div",{className:"flex items-center justify-between py-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-700",children:"Include Subpaths"}),(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-0.5",children:"Forward all subpaths to the target API (recommended for REST APIs)"})]}),(0,c.jsx)(A.Z.Item,{name:"include_subpath",valuePropName:"checked",className:"mb-0",children:(0,c.jsx)(tB.Z,{checked:f,onChange:v})})]})]})]}),(0,c.jsx)(lr,{pathValue:x,targetValue:p,includeSubpath:f}),(0,c.jsxs)(G.Z,{className:"p-6",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Headers"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-6",children:"Add headers that will be sent with every request to the target API"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Authentication Headers",(0,c.jsx)(V.Z,{title:"Authentication and other headers to forward with requests",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"headers",rules:[{required:!0,message:"Please configure the headers"}],extra:(0,c.jsxs)("div",{className:"text-xs text-gray-500 mt-2",children:[(0,c.jsx)("div",{className:"font-medium mb-1",children:"Add authentication tokens and other required headers"}),(0,c.jsx)("div",{children:"Common examples: auth_token, Authorization, x-api-key"})]}),children:(0,c.jsx)(ll,{})})]}),(0,c.jsxs)(G.Z,{className:"p-6",children:[(0,c.jsx)(S.Z,{className:"text-lg font-semibold text-gray-900 mb-2",children:"Billing"}),(0,c.jsx)(sz.Z,{className:"text-gray-600 mb-6",children:"Optional cost tracking for this endpoint"}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Cost Per Request (USD)",(0,c.jsx)(V.Z,{title:"Optional: Track costs for requests to this endpoint",children:(0,c.jsx)(B.Z,{className:"ml-2 text-gray-400 hover:text-gray-600"})})]}),name:"cost_per_request",extra:(0,c.jsx)("div",{className:"text-xs text-gray-500 mt-2",children:"The cost charged for each request through this endpoint"}),children:(0,c.jsx)(O,{min:0,step:.001,precision:4,placeholder:"2.0000",size:"large"})})]}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:y,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",loading:n,onClick:()=>{console.log("Submit button clicked"),a.submit()},children:n?"Creating...":"Add Pass-Through Endpoint"})]})]})]})})]})},lo=t(87769),lc=t(42208);let ld=e=>{let{value:s}=e,[t,l]=(0,d.useState)(!1),a=JSON.stringify(s,null,2);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("pre",{className:"font-mono text-xs bg-gray-50 p-2 rounded max-w-md overflow-auto",children:t?a:"••••••••"}),(0,c.jsx)("button",{onClick:()=>l(!t),className:"p-1 hover:bg-gray-100 rounded",type:"button",children:t?(0,c.jsx)(lo.Z,{className:"w-4 h-4 text-gray-500"}):(0,c.jsx)(lc.Z,{className:"w-4 h-4 text-gray-500"})})]})};var lm=e=>{let{endpointData:s,onClose:t,accessToken:l,isAdmin:a,onEndpointUpdated:r}=e,[i,n]=(0,d.useState)(s),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(!1),[h]=A.Z.useForm(),p=async e=>{try{if(!l||!(null==i?void 0:i.id))return;let s={};if(e.headers)try{s="string"==typeof e.headers?JSON.parse(e.headers):e.headers}catch(e){eo.Z.fromBackend("Invalid JSON format for headers");return}let t={path:i.path,target:e.target,headers:s,include_subpath:e.include_subpath,cost_per_request:e.cost_per_request};await (0,j.updatePassThroughEndpoint)(l,i.id,t),n({...i,...t}),x(!1),r&&r()}catch(e){console.error("Error updating endpoint:",e),eo.Z.fromBackend("Failed to update pass through endpoint")}},g=async()=>{try{if(!l||!(null==i?void 0:i.id))return;await (0,j.deletePassThroughEndpointsCall)(l,i.id),eo.Z.success("Pass through endpoint deleted successfully"),t(),r&&r()}catch(e){console.error("Error deleting endpoint:",e),eo.Z.fromBackend("Failed to delete pass through endpoint")}};return o?(0,c.jsx)("div",{className:"p-4",children:"Loading..."}):i?(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(P.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,c.jsxs)(S.Z,{children:["Pass Through Endpoint: ",i.path]}),(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:i.id})]})}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),a?(0,c.jsx)(e0.Z,{children:"Settings"},"settings"):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Path"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{className:"font-mono",children:i.path})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Target"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{children:i.target})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Configuration"}),(0,c.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,c.jsx)("div",{children:(0,c.jsx)(eX.Z,{color:i.include_subpath?"green":"gray",children:i.include_subpath?"Include Subpath":"Exact Path"})}),void 0!==i.cost_per_request&&(0,c.jsx)("div",{children:(0,c.jsxs)(k.Z,{children:["Cost per request: $",i.cost_per_request]})})]})]})]}),(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsx)(lr,{pathValue:i.path,targetValue:i.target,includeSubpath:i.include_subpath||!1})}),i.headers&&Object.keys(i.headers).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Headers"}),(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(i.headers).length," headers configured"]})]}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(ld,{value:i.headers})})]})]}),a&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Pass Through Endpoint Settings"}),(0,c.jsx)("div",{className:"space-x-2",children:!u&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(b.Z,{onClick:()=>x(!0),children:"Edit Settings"}),(0,c.jsx)(b.Z,{onClick:g,variant:"secondary",color:"red",children:"Delete Endpoint"})]})})]}),u?(0,c.jsxs)(A.Z,{form:h,onFinish:p,initialValues:{target:i.target,headers:i.headers?JSON.stringify(i.headers,null,2):"",include_subpath:i.include_subpath||!1,cost_per_request:i.cost_per_request},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Target URL",name:"target",rules:[{required:!0,message:"Please input a target URL"}],children:(0,c.jsx)(_.Z,{placeholder:"https://api.example.com"})}),(0,c.jsx)(A.Z.Item,{label:"Headers (JSON)",name:"headers",children:(0,c.jsx)(E.default.TextArea,{rows:5,placeholder:'{"Authorization": "Bearer your-token", "Content-Type": "application/json"}'})}),(0,c.jsx)(A.Z.Item,{label:"Include Subpath",name:"include_subpath",valuePropName:"checked",children:(0,c.jsx)(tj.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Cost per Request",name:"cost_per_request",children:(0,c.jsx)(eW.Z,{min:0,step:.01,precision:2,placeholder:"0.00",addonBefore:"$"})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,c.jsx)(P.ZP,{onClick:()=>x(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{children:"Save Changes"})]})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Path"}),(0,c.jsx)("div",{className:"font-mono",children:i.path})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Target URL"}),(0,c.jsx)("div",{children:i.target})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Include Subpath"}),(0,c.jsx)(eX.Z,{color:i.include_subpath?"green":"gray",children:i.include_subpath?"Yes":"No"})]}),void 0!==i.cost_per_request&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cost per Request"}),(0,c.jsxs)("div",{children:["$",i.cost_per_request]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Headers"}),i.headers&&Object.keys(i.headers).length>0?(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(ld,{value:i.headers})}):(0,c.jsx)("div",{className:"text-gray-500",children:"No headers configured"})]})]})]})})]})]})]}):(0,c.jsx)("div",{className:"p-4",children:"Pass through endpoint not found"})},lu=t(19130);function lx(e){let{data:s=[],columns:t,getRowCanExpand:l,renderSubComponent:a,isLoading:r=!1,loadingMessage:i="\uD83D\uDE85 Loading logs...",noDataMessage:n="No logs found"}=e,o=(0,s_.b7)({data:s,columns:t,getRowCanExpand:l,getRowId:(e,s)=>{var t;return null!==(t=null==e?void 0:e.request_id)&&void 0!==t?t:String(s)},getCoreRowModel:(0,sN.sC)(),getExpandedRowModel:(0,sN.rV)()});return(0,c.jsx)("div",{className:"rounded-lg custom-border overflow-x-auto w-full max-w-full box-border",children:(0,c.jsxs)(lu.iA,{className:"[&_td]:py-0.5 [&_th]:py-1 table-fixed w-full box-border",style:{minWidth:"800px"},children:[(0,c.jsx)(lu.ss,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(lu.SC,{children:e.headers.map(e=>(0,c.jsx)(lu.xs,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,c.jsx)(lu.RM,{children:r?(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:t.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:i})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsxs)(d.Fragment,{children:[(0,c.jsx)(lu.SC,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(lu.pj,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:e.getVisibleCells().length,className:"p-0",children:(0,c.jsx)("div",{className:"w-full max-w-full overflow-hidden box-border",children:a({row:e})})})})]},e.id)):(0,c.jsx)(lu.SC,{children:(0,c.jsx)(lu.pj,{colSpan:t.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:n})})})})})]})})}let lh=e=>{let{value:s}=e,[t,l]=(0,d.useState)(!1),a=JSON.stringify(s);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"font-mono text-xs",children:t?a:"••••••••"}),(0,c.jsx)("button",{onClick:()=>l(!t),className:"p-1 hover:bg-gray-100 rounded",type:"button",children:t?(0,c.jsx)(lo.Z,{className:"w-4 h-4 text-gray-500"}):(0,c.jsx)(lc.Z,{className:"w-4 h-4 text-gray-500"})})]})};var lp=e=>{let{accessToken:s,userRole:t,userID:l,modelData:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null);(0,d.useEffect)(()=>{s&&t&&l&&(0,j.getPassThroughEndpointsCall)(s).then(e=>{i(e.endpoints)})},[s,t,l]);let p=async e=>{h(e),u(!0)},g=async()=>{if(null!=x&&s){try{await (0,j.deletePassThroughEndpointsCall)(s,x);let e=r.filter(e=>e.id!==x);i(e),eo.Z.success("Endpoint deleted successfully.")}catch(e){console.error("Error deleting the endpoint:",e),eo.Z.fromBackend("Error deleting the endpoint: "+e)}u(!1),h(null)}},f=(e,s)=>{p(e)},v=[{header:"ID",accessorKey:"id",cell:e=>(0,c.jsx)(V.Z,{title:e.row.original.id,children:(0,c.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>e.row.original.id&&o(e.row.original.id),children:e.row.original.id})})},{header:"Path",accessorKey:"path"},{header:"Target",accessorKey:"target",cell:e=>(0,c.jsx)(k.Z,{children:e.getValue()})},{header:"Headers",accessorKey:"headers",cell:e=>(0,c.jsx)(lh,{value:e.getValue()||{}})},{header:"Actions",id:"actions",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex space-x-1",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>s.original.id&&o(s.original.id),title:"Edit"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>f(s.original.id,s.index),title:"Delete"})]})}}];if(!s)return null;if(n){console.log("selectedEndpointId",n),console.log("generalSettings",r);let e=r.find(e=>e.id===n);return e?(0,c.jsx)(lm,{endpointData:e,onClose:()=>o(null),accessToken:s,isAdmin:"Admin"===t||"admin"===t,onEndpointUpdated:()=>{s&&(0,j.getPassThroughEndpointsCall)(s).then(e=>{i(e.endpoints)})}}):(0,c.jsx)("div",{children:"Endpoint not found"})}return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Pass Through Endpoints"}),(0,c.jsx)(k.Z,{className:"text-tremor-content",children:"Configure and manage your pass-through endpoints"})]}),(0,c.jsx)(ln,{accessToken:s,setPassThroughItems:i,passThroughItems:r}),(0,c.jsx)(lx,{data:r,columns:v,renderSubComponent:()=>(0,c.jsx)("div",{}),getRowCanExpand:()=>!1,isLoading:!1,noDataMessage:"No pass-through endpoints configured"}),m&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Pass-Through Endpoint"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this pass-through endpoint? This action cannot be undone."})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:g,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{u(!1),h(null)},children:"Cancel"})]})]})]})})]})},lg=e=>{let{accessToken:s,initialModelGroupAlias:t={},onAliasUpdate:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)({aliasName:"",targetModelGroup:""}),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!0);(0,d.useEffect)(()=>{r(Object.entries(t).map((e,s)=>{let[t,l]=e;return{id:"".concat(s,"-").concat(t),aliasName:t,targetModelGroup:l}}))},[t]);let h=async e=>{if(!s)return console.error("Access token is missing"),!1;try{let t={};return e.forEach(e=>{t[e.aliasName]=e.targetModelGroup}),console.log("Saving model group alias:",t),await (0,j.setCallbacksCall)(s,{router_settings:{model_group_alias:t}}),l&&l(t),!0}catch(e){return console.error("Failed to save model group alias settings:",e),eo.Z.fromBackend("Failed to save model group alias settings"),!1}},p=async()=>{if(!i.aliasName||!i.targetModelGroup){eo.Z.fromBackend("Please provide both alias name and target model group");return}if(a.some(e=>e.aliasName===i.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=[...a,{id:"".concat(Date.now(),"-").concat(i.aliasName),aliasName:i.aliasName,targetModelGroup:i.targetModelGroup}];await h(e)&&(r(e),n({aliasName:"",targetModelGroup:""}),eo.Z.success("Alias added successfully"))},g=e=>{m({...e})},f=async()=>{if(!o)return;if(!o.aliasName||!o.targetModelGroup){eo.Z.fromBackend("Please provide both alias name and target model group");return}if(a.some(e=>e.id!==o.id&&e.aliasName===o.aliasName)){eo.Z.fromBackend("An alias with this name already exists");return}let e=a.map(e=>e.id===o.id?o:e);await h(e)&&(r(e),m(null),eo.Z.success("Alias updated successfully"))},v=()=>{m(null)},y=async e=>{let s=a.filter(s=>s.id!==e);await h(s)&&(r(s),eo.Z.success("Alias deleted successfully"))},b=a.reduce((e,s)=>(e[s.aliasName]=s.targetModelGroup,e),{});return(0,c.jsxs)(eR.Zb,{className:"mb-6",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>x(!u),children:[(0,c.jsxs)("div",{className:"flex flex-col",children:[(0,c.jsx)(eR.Dx,{className:"mb-0",children:"Model Group Alias Settings"}),(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Create aliases for your model groups to simplify API calls. For example, you can create an alias 'gpt-4o' that points to 'gpt-4o-mini-openai' model group."})]}),(0,c.jsx)("div",{className:"flex items-center",children:u?(0,c.jsx)(sL.Z,{className:"w-5 h-5 text-gray-500"}):(0,c.jsx)(sT.Z,{className:"w-5 h-5 text-gray-500"})})]}),u&&(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Add New Alias"}),(0,c.jsxs)("div",{className:"grid grid-cols-3 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Alias Name"}),(0,c.jsx)("input",{type:"text",value:i.aliasName,onChange:e=>n({...i,aliasName:e.target.value}),placeholder:"e.g., gpt-4o",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Target Model Group"}),(0,c.jsx)("input",{type:"text",value:i.targetModelGroup,onChange:e=>n({...i,targetModelGroup:e.target.value}),placeholder:"e.g., gpt-4o-mini-openai",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),(0,c.jsx)("div",{className:"flex items-end",children:(0,c.jsxs)("button",{onClick:p,disabled:!i.aliasName||!i.targetModelGroup,className:"flex items-center px-4 py-2 rounded-md text-sm ".concat(i.aliasName&&i.targetModelGroup?"bg-green-600 text-white hover:bg-green-700":"bg-gray-300 text-gray-500 cursor-not-allowed"),children:[(0,c.jsx)(eD.Z,{className:"w-4 h-4 mr-1"}),"Add Alias"]})})]})]}),(0,c.jsx)(eR.xv,{className:"text-sm font-medium text-gray-700 mb-2",children:"Manage Existing Aliases"}),(0,c.jsx)("div",{className:"rounded-lg custom-border relative mb-6",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(eR.iA,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(eR.ss,{children:(0,c.jsxs)(eR.SC,{children:[(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Alias Name"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Target Model Group"}),(0,c.jsx)(eR.xs,{className:"py-1 h-8",children:"Actions"})]})}),(0,c.jsxs)(eR.RM,{children:[a.map(e=>(0,c.jsx)(eR.SC,{className:"h-8",children:o&&o.id===e.id?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:o.aliasName,onChange:e=>m({...o,aliasName:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5",children:(0,c.jsx)("input",{type:"text",value:o.targetModelGroup,onChange:e=>m({...o,targetModelGroup:e.target.value}),className:"w-full px-2 py-1 border border-gray-300 rounded-md text-sm"})}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:f,className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:"Save"}),(0,c.jsx)("button",{onClick:v,className:"text-xs bg-gray-50 text-gray-600 px-2 py-1 rounded hover:bg-gray-100",children:"Cancel"})]})})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-900",children:e.aliasName}),(0,c.jsx)(eR.pj,{className:"py-0.5 text-sm text-gray-500",children:e.targetModelGroup}),(0,c.jsx)(eR.pj,{className:"py-0.5 whitespace-nowrap",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>g(e),className:"text-xs bg-blue-50 text-blue-600 px-2 py-1 rounded hover:bg-blue-100",children:(0,c.jsx)(eF.Z,{className:"w-3 h-3"})}),(0,c.jsx)("button",{onClick:()=>y(e.id),className:"text-xs bg-red-50 text-red-600 px-2 py-1 rounded hover:bg-red-100",children:(0,c.jsx)(W.Z,{className:"w-3 h-3"})})]})})]})},e.id)),0===a.length&&(0,c.jsx)(eR.SC,{children:(0,c.jsx)(eR.pj,{colSpan:3,className:"py-0.5 text-sm text-gray-500 text-center",children:"No aliases added yet. Add a new alias above."})})]})]})})}),(0,c.jsxs)(eR.Zb,{children:[(0,c.jsx)(eR.Dx,{className:"mb-4",children:"Configuration Example"}),(0,c.jsx)(eR.xv,{className:"text-gray-600 mb-4",children:"Here's how your current aliases would look in the config.yaml:"}),(0,c.jsx)("div",{className:"bg-gray-100 rounded-lg p-4 font-mono text-sm",children:(0,c.jsxs)("div",{className:"text-gray-700",children:["router_settings:",(0,c.jsx)("br",{}),"\xa0\xa0model_group_alias:",0===Object.keys(b).length?(0,c.jsxs)("span",{className:"text-gray-500",children:[(0,c.jsx)("br",{}),"\xa0\xa0\xa0\xa0# No aliases configured yet"]}):Object.entries(b).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[(0,c.jsx)("br",{}),'\xa0\xa0\xa0\xa0"',s,'": "',t,'"']},s)})]})})]})]})]})};let lj={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lf=e=>{let{accessToken:s,token:t,userRole:l,userID:a,modelData:r={data:[]},keys:i,setModelData:n,premiumUser:o,teams:m}=e,[u]=A.Z.useForm(),[x]=A.Z.useForm(),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(""),[_,N]=(0,d.useState)([]),[Z,w]=(0,d.useState)([]),[C,I]=(0,d.useState)(sU.Cl.OpenAI),[L,T]=(0,d.useState)(null),[P,E]=(0,d.useState)(!1),[M,O]=(0,d.useState)(!1),[D,F]=(0,d.useState)(null),[R,z]=(0,d.useState)([]),[U,q]=(0,d.useState)([]),[V,K]=(0,d.useState)(null),[H,J]=(0,d.useState)([]),[Y,W]=(0,d.useState)([]),[$,Q]=(0,d.useState)([]),[X,ee]=(0,d.useState)([]),[es,et]=(0,d.useState)([]),[el,ea]=(0,d.useState)([]),[er,ec]=(0,d.useState)([]),[ed,em]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[eu,ex]=(0,d.useState)(null),[eh,ep]=(0,d.useState)(null),[eg,ej]=(0,d.useState)(0),[ef,ev]=(0,d.useState)({}),[ey,eb]=(0,d.useState)([]),[e_,eN]=(0,d.useState)(!1),[eZ,ew]=(0,d.useState)(null),[ek,eS]=(0,d.useState)(null),[eC,eA]=(0,d.useState)([]),[eL,eT]=(0,d.useState)([]),[eP,eE]=(0,d.useState)({}),[eM,eO]=(0,d.useState)(!1),[eD,eF]=(0,d.useState)(null),[eR,ez]=(0,d.useState)(!1),[eU,eq]=(0,d.useState)(null),[eB,eV]=(0,d.useState)(null),[eK,eG]=(0,d.useState)(null),[eH,eJ]=(0,d.useState)(null),[eY,e$]=(0,d.useState)(""),[eX,e6]=(0,d.useState)("personal"),[e8,e7]=(0,d.useState)("current_team"),[e9,se]=(0,d.useState)(!1),[ss,st]=(0,d.useState)(!1),[sl,sa]=(0,d.useState)(!1),[sr,si]=(0,d.useState)(new Set),sn=(0,d.useRef)(null),so=(0,d.useRef)(null),[sc,sd]=(0,d.useState)({pageIndex:0,pageSize:50}),[sm,su]=(0,d.useState)(0),sx=(0,d.useMemo)(()=>r&&r.data&&0!==r.data.length?r.data.filter(e=>{var s,t,l,a,r;let i=""===eY||e.model_name.toLowerCase().includes(eY.toLowerCase()),n="all"===V||e.model_name===V||!V||"wildcard"===V&&(null===(s=e.model_name)||void 0===s?void 0:s.includes("*")),o="all"===eH||(null===(t=e.model_info.access_groups)||void 0===t?void 0:t.includes(eH))||!eH,c=!0;return"current_team"===e8&&(c="personal"===eX?(null===(l=e.model_info)||void 0===l?void 0:l.direct_access)===!0:(null===(r=e.model_info)||void 0===r?void 0:null===(a=r.access_via_team_ids)||void 0===a?void 0:a.includes(eX))===!0),i&&n&&o&&c}):[],[r,eY,V,eH,eX,e8]),sh=(0,d.useMemo)(()=>{let e=sc.pageIndex*sc.pageSize,s=e+sc.pageSize;return sx.slice(e,s)},[sx,sc.pageIndex,sc.pageSize]);(0,d.useEffect)(()=>{sd(e=>({...e,pageIndex:0}))},[eY,V,eH,eX,e8]);let sg=async(e,t,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!l||!t||!r)return;console.log("inside updateModelMetrics - startTime:",t,"endTime:",r),K(e);let i=null==eZ?void 0:eZ.token;void 0===i&&(i=null);let n=ek;void 0===n&&(n=null);try{let o=await (0,j.modelMetricsCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);console.log("Model metrics response:",o),J(o.data),W(o.all_api_bases);let c=await (0,j.streamingModelMetricsCall)(s,e,t.toISOString(),r.toISOString());Q(c.data),ee(c.all_api_bases);let d=await (0,j.modelExceptionsCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);console.log("Model exceptions response:",d),et(d.data),ea(d.exception_types);let m=await (0,j.modelMetricsSlowResponsesCall)(s,a,l,e,t.toISOString(),r.toISOString(),i,n);if(console.log("slowResponses:",m),ec(m),e){let l=await (0,j.adminGlobalActivityExceptions)(s,null==t?void 0:t.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ev(l);let a=await (0,j.adminGlobalActivityExceptionsPerDeployment)(s,null==t?void 0:t.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);eb(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},sj=async e=>{try{let s=await (0,j.credentialListCall)(e);console.log("credentials: ".concat(JSON.stringify(s))),eT(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,d.useEffect)(()=>{sg(V,ed.from,ed.to)},[eZ,ek,eB]),(0,d.useEffect)(()=>{let e=e=>{sn.current&&!sn.current.contains(e.target)&&sa(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sf={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),u.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",u.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",u.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?eo.Z.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&eo.Z.fromBackend("".concat(e.file.name," file upload failed."))}},sv=()=>{f(new Date().toLocaleString())},sy=async()=>{if(!s){console.error("Access token is missing");return}try{let e={router_settings:{}};"global"===V?(console.log("Saving global retry policy:",eh),eh&&(e.router_settings.retry_policy=eh),eo.Z.success("Global retry settings saved successfully")):(console.log("Saving model group retry policy for",V,":",eu),eu&&(e.router_settings.model_group_retry_policy=eu),eo.Z.success("Retry settings saved successfully for ".concat(V))),await (0,j.setCallbacksCall)(s,e)}catch(e){console.error("Failed to save retry settings:",e),eo.Z.fromBackend("Failed to save retry settings")}};if((0,d.useEffect)(()=>{if(!s||!t||!l||!a)return;let e=async()=>{try{var e,t,r,i,o,c,d,m,u,x,h,p;let g=await (0,j.modelInfoCall)(s,a,l);console.log("Model data response:",g.data),n(g);let f=await (0,j.modelSettingsCall)(s);f&&w(f);let v=new Set;for(let e=0;e0&&(_=y[y.length-1],console.log("_initial_model_group:",_)),console.log("selectedModelGroup:",V);let N=await (0,j.modelMetricsCall)(s,a,l,_,null===(e=ed.from)||void 0===e?void 0:e.toISOString(),null===(t=ed.to)||void 0===t?void 0:t.toISOString(),null==eZ?void 0:eZ.token,ek);console.log("Model metrics response:",N),J(N.data),W(N.all_api_bases);let Z=await (0,j.streamingModelMetricsCall)(s,_,null===(r=ed.from)||void 0===r?void 0:r.toISOString(),null===(i=ed.to)||void 0===i?void 0:i.toISOString());Q(Z.data),ee(Z.all_api_bases);let k=await (0,j.modelExceptionsCall)(s,a,l,_,null===(o=ed.from)||void 0===o?void 0:o.toISOString(),null===(c=ed.to)||void 0===c?void 0:c.toISOString(),null==eZ?void 0:eZ.token,ek);console.log("Model exceptions response:",k),et(k.data),ea(k.exception_types);let S=await (0,j.modelMetricsSlowResponsesCall)(s,a,l,_,null===(d=ed.from)||void 0===d?void 0:d.toISOString(),null===(m=ed.to)||void 0===m?void 0:m.toISOString(),null==eZ?void 0:eZ.token,ek),C=await (0,j.adminGlobalActivityExceptions)(s,null===(u=ed.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(x=ed.to)||void 0===x?void 0:x.toISOString().split("T")[0],_);ev(C);let I=await (0,j.adminGlobalActivityExceptionsPerDeployment)(s,null===(h=ed.from)||void 0===h?void 0:h.toISOString().split("T")[0],null===(p=ed.to)||void 0===p?void 0:p.toISOString().split("T")[0],_);eb(I),console.log("dailyExceptions:",C),console.log("dailyExceptionsPerDeplyment:",I),console.log("slowResponses:",S),ec(S);let A=await (0,j.allEndUsersCall)(s);eA(null==A?void 0:A.end_users);let L=(await (0,j.getCallbacksCall)(s,a,l)).router_settings;console.log("routerSettingsInfo:",L);let T=L.model_group_retry_policy,P=L.num_retries;console.log("model_group_retry_policy:",T),console.log("default_retries:",P),ex(T),ep(L.retry_policy),ej(P);let E=L.model_group_alias||{};eE(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&t&&l&&a&&e();let r=async()=>{let e=await (0,j.modelCostMap)(s);console.log("received model cost map data: ".concat(Object.keys(e))),p(e)};null==h&&r(),sv()},[s,t,l,a,h,g,eB]),!r||!s||!t||!l||!a)return(0,c.jsx)("div",{children:"Loading..."});let sb=[],s_=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(h)),null!=h&&"object"==typeof h&&e in h)?h[e].litellm_provider:"openai";if(t){let e=t.split("/"),s=e[0];(i=l)||(i=1===e.length?u(t):s)}else i="-";a&&(n=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,c=null==a?void 0:a.max_tokens,d=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=i,r.data[e].input_cost=n,r.data[e].output_cost=o,r.data[e].litellm_model_name=t,s_.push(i),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=c,r.data[e].max_input_tokens=d,r.data[e].api_base=null==s?void 0:null===(sT=s.litellm_params)||void 0===sT?void 0:sT.api_base,r.data[e].cleanedLitellmParams=m,sb.push(s.model_name),console.log(r.data[e])}if(l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sP=(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mb-1",children:"Select API Key Name"}),o?(0,c.jsxs)("div",{children:[(0,c.jsxs)(eQ.Z,{defaultValue:"all-keys",children:[(0,c.jsx)(ei.Z,{value:"all-keys",onClick:()=>{ew(null)},children:"All Keys"},"all-keys"),null==i?void 0:i.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,c.jsx)(ei.Z,{value:String(s),onClick:()=>{ew(e)},children:e.key_alias},s):null)]}),(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Customer Name"}),(0,c.jsxs)(eQ.Z,{defaultValue:"all-customers",children:[(0,c.jsx)(ei.Z,{value:"all-customers",onClick:()=>{eS(null)},children:"All Customers"},"all-customers"),null==eC?void 0:eC.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>{eS(e)},children:e},s))]}),(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Team"}),(0,c.jsxs)(eQ.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eK?eK:"all",onValueChange:e=>eG("all"===e?null:e),children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Teams"}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-1",children:"Select Team"}),(0,c.jsxs)(eQ.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eK?eK:"all",onValueChange:e=>eG("all"===e?null:e),children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Teams"}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sE=e=>{var s,t;let{payload:l,active:a}=e;if(!a||!l)return null;let r=null===(t=l[0])||void 0===t?void 0:null===(s=t.payload)||void 0===s?void 0:s.date,i=l.sort((e,s)=>s.value-e.value);if(i.length>5){let e=i.length-5;(i=i.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:l.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,c.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,c.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),i.map((e,s)=>{let t=parseFloat(e.value.toFixed(5)),l=0===t&&e.value>0?"<0.00001":t.toFixed(5);return(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,c.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,c.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:l})]},s)})]})};console.log("selectedProvider: ".concat(C)),console.log("providerModels.length: ".concat(_.length));let sM=Object.keys(sU.Cl).find(e=>sU.Cl[e]===C);return(sM&&Z&&Z.find(e=>e.name===sU.fK[sM]),eU)?(0,c.jsx)("div",{className:"w-full h-full",children:(0,c.jsx)(tu,{teamId:eU,onClose:()=>eq(null),accessToken:s,is_team_admin:"Admin"===l,is_proxy_admin:"Proxy Admin"===l,userModels:sb,editTeam:!1,onUpdate:sv})}):(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("h2",{className:"text-lg font-semibold",children:"Model Management"}),eI.ZL.includes(l)?(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"Add and manage models for the proxy"}):(0,c.jsx)("p",{className:"text-sm text-gray-600",children:"Add models for teams you are an admin for."})]})}),eD?(0,c.jsx)(tI,{modelId:eD,editModel:!0,onClose:()=>{eF(null),ez(!1)},modelData:r.data.find(e=>e.model_info.id===eD),accessToken:s,userID:a,userRole:l,setEditModalVisible:O,setSelectedModel:F,onModelUpdate:e=>{n({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sv()},modelAccessGroups:U}):(0,c.jsxs)(e1.Z,{index:sm,onIndexChange:su,className:"gap-2 h-[75vh] w-full ",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[eI.ZL.includes(l)?(0,c.jsx)(e0.Z,{children:"All Models"}):(0,c.jsx)(e0.Z,{children:"Your Models"}),(0,c.jsx)(e0.Z,{children:"Add Model"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"LLM Credentials"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Pass-Through Endpoints"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Health Status"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Analytics"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Retry Settings"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Model Group Alias"}),eI.ZL.includes(l)&&(0,c.jsx)(e0.Z,{children:"Price Data Reload"})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[g&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",g]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sv})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(y.Z,{children:(0,c.jsx)("div",{className:"flex flex-col space-y-4",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"border-b px-6 py-4 bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"Current Team:"}),(0,c.jsxs)(eQ.Z,{className:"w-80",defaultValue:"personal",value:eX,onValueChange:e=>e6(e),children:[(0,c.jsx)(ei.Z,{value:"personal",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Personal"})]})}),null==m?void 0:m.filter(e=>e.team_id).map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e.team_alias?"".concat(e.team_alias.slice(0,30),"..."):"Team ".concat(e.team_id.slice(0,30),"...")})]})},e.team_id))]})]}),(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"View:"}),(0,c.jsxs)(eQ.Z,{className:"w-64",defaultValue:"current_team",value:e8,onValueChange:e=>e7(e),children:[(0,c.jsx)(ei.Z,{value:"current_team",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-purple-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Current Team Models"})]})}),(0,c.jsx)(ei.Z,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-gray-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"All Available Models"})]})})]})]})]}),"current_team"===e8&&(0,c.jsxs)("div",{className:"flex items-start gap-2 mt-3",children:[(0,c.jsx)(B.Z,{className:"text-gray-400 mt-0.5 flex-shrink-0 text-xs"}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:"personal"===eX?(0,c.jsxs)("span",{children:["To access these models: Create a Virtual Key without selecting a team on the"," ",(0,c.jsx)("a",{href:"/?login=success&page=api-keys",className:"text-gray-600 hover:text-gray-800 underline",children:"Virtual Keys page"})]}):(0,c.jsxs)("span",{children:['To access these models: Create a Virtual Key and select Team as "',eX,'" on the'," ",(0,c.jsx)("a",{href:"/?login=success&page=api-keys",className:"text-gray-600 hover:text-gray-800 underline",children:"Virtual Keys page"})]})})]})]}),(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search model names...",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:eY,onChange:e=>e$(e.target.value)}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(e9?"bg-gray-100":""),onClick:()=>se(!e9),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters"]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{e$(""),K("all"),eJ(null),e6("personal"),e7("current_team"),sd({pageIndex:0,pageSize:50})},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),e9&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsx)("div",{className:"w-64",children:(0,c.jsxs)(eQ.Z,{value:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),placeholder:"Filter by Public Model Name",children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Models"}),(0,c.jsx)(ei.Z,{value:"wildcard",children:"Wildcard Models (*)"}),R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,children:e},s))]})}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsxs)(eQ.Z,{value:null!=eH?eH:"all",onValueChange:e=>eJ("all"===e?null:e),placeholder:"Filter by Model Access Group",children:[(0,c.jsx)(ei.Z,{value:"all",children:"All Model Access Groups"}),U.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,children:e},s))]})})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-sm text-gray-700",children:sx.length>0?"Showing ".concat(sc.pageIndex*sc.pageSize+1," - ").concat(Math.min((sc.pageIndex+1)*sc.pageSize,sx.length)," of ").concat(sx.length," results"):"Showing 0 results"}),sx.length>sc.pageSize&&(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("button",{onClick:()=>sd(e=>({...e,pageIndex:e.pageIndex-1})),disabled:0===sc.pageIndex,className:"px-3 py-1 text-sm border rounded-md ".concat(0===sc.pageIndex?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,c.jsx)("button",{onClick:()=>sd(e=>({...e,pageIndex:e.pageIndex+1})),disabled:sc.pageIndex>=Math.ceil(sx.length/sc.pageSize)-1,className:"px-3 py-1 text-sm border rounded-md ".concat(sc.pageIndex>=Math.ceil(sx.length/sc.pageSize)-1?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,c.jsx)(t$.C,{columns:tQ(l,a,o,eF,eq,s2,e=>{F(e),O(!0)},sv,ez,sr,si),data:sh,isLoading:!1,table:so})]})})})}),(0,c.jsx)(e4.Z,{className:"h-full",children:(0,c.jsx)(tW,{form:u,handleOk:()=>{console.log("\uD83D\uDE80 handleOk called from model dashboard!"),console.log("Current form values:",u.getFieldsValue()),u.validateFields().then(e=>{console.log("✅ Validation passed, submitting:",e),sB(e,s,u,sv)}).catch(e=>{var s;console.error("❌ Validation failed:",e),console.error("Form errors:",e.errorFields);let t=(null===(s=e.errorFields)||void 0===s?void 0:s.map(e=>"".concat(e.name.join("."),": ").concat(e.errors.join(", "))).join(" | "))||"Unknown validation error";eo.Z.fromBackend("Please fill in the following required fields: ".concat(t))})},selectedProvider:C,setSelectedProvider:I,providerModels:_,setProviderModelsFn:e=>{let s=(0,sU.bK)(e,h);N(s),console.log("providerModels: ".concat(s))},getPlaceholder:sU.ph,uploadProps:sf,showAdvancedSettings:eM,setShowAdvancedSettings:eO,teams:m,credentials:eL,accessToken:s,userRole:l,premiumUser:o})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(s1,{accessToken:s,uploadProps:sf,credentialList:eL,fetchCredentials:sj})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lp,{accessToken:s,userRole:l,userID:a,modelData:r})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(le,{accessToken:s,modelData:r,all_models_on_proxy:sb,getDisplayModelName:s2,setSelectedModelId:eF})}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:ed,className:"mr-2",onValueChange:e=>{em(e),sg(V,e.from,e.to)}})}),(0,c.jsxs)(v.Z,{className:"ml-2",children:[(0,c.jsx)(k.Z,{children:"Select Model Group"}),(0,c.jsx)(eQ.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>sg(e,ed.from,ed.to),children:e},s))})]}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(s8.Z,{trigger:"click",content:sP,overlayStyle:{width:"20vw"},children:(0,c.jsx)(b.Z,{icon:sp.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(G.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Avg. Latency per Token"}),(0,c.jsx)(e0.Z,{value:"2",children:"Time to first token"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,c.jsx)(k.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),H&&Y&&(0,c.jsx)(s6.Z,{title:"Model Latency",className:"h-72",data:H,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sE})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(s9,{modelMetrics:$,modelMetricsCategories:X,customTooltip:sE,premiumUser:o})})]})]})})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(G.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Deployment"}),(0,c.jsx)(sI.Z,{children:"Success Responses"}),(0,c.jsxs)(sI.Z,{children:["Slow Responses ",(0,c.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,c.jsx)(sk.Z,{children:er.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.api_base}),(0,c.jsx)(sS.Z,{children:e.total_count}),(0,c.jsx)(sS.Z,{children:e.slow_count})]},s))})]})})})]}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["All Exceptions for ",V]}),(0,c.jsx)(s3.Z,{className:"h-60",data:es,index:"model",categories:el,stack:!0,yAxisWidth:30})]})}),(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,c.jsxs)(y.Z,{numItems:1,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,c.jsx)(v.Z,{})]})]}),o?(0,c.jsx)(c.Fragment,{children:ey.map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,c.jsx)(c.Fragment,{children:ey&&ey.length>0&&ey.slice(0,1).map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,c.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,c.jsx)(b.Z,{variant:"primary",className:"mb-2",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.api_base}),(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"flex items-center gap-4 mb-6",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(k.Z,{children:"Retry Policy Scope:"}),(0,c.jsxs)(eQ.Z,{className:"ml-2 w-48",defaultValue:"global",value:"global"===V?"global":V||R[0],onValueChange:e=>K(e),children:[(0,c.jsx)(ei.Z,{value:"global",children:"Global Default"}),R.map((e,s)=>(0,c.jsx)(ei.Z,{value:e,onClick:()=>K(e),children:e},s))]})]})}),"global"===V?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(S.Z,{children:"Global Retry Policy"}),(0,c.jsx)(k.Z,{className:"mb-6",children:"Default retry settings applied to all model groups unless overridden"})]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(S.Z,{children:["Retry Policy for ",V]}),(0,c.jsx)(k.Z,{className:"mb-6",children:"Model-specific retry settings. Falls back to global defaults if not set."})]}),lj&&(0,c.jsx)("table",{children:(0,c.jsx)("tbody",{children:Object.entries(lj).map((e,s)=>{var t,l,a,r;let i,[n,o]=e;if("global"===V)i=null!==(t=null==eh?void 0:eh[o])&&void 0!==t?t:eg;else{let e=null==eu?void 0:null===(l=eu[V])||void 0===l?void 0:l[o];i=null!=e?e:null!==(a=null==eh?void 0:eh[o])&&void 0!==a?a:eg}return(0,c.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,c.jsxs)("td",{children:[(0,c.jsx)(k.Z,{children:n}),"global"!==V&&(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500 ml-2",children:["(Global: ",null!==(r=null==eh?void 0:eh[o])&&void 0!==r?r:eg,")"]})]}),(0,c.jsx)("td",{children:(0,c.jsx)(eW.Z,{className:"ml-5",value:i,min:0,step:1,onChange:e=>{"global"===V?ep(s=>null==e?s:{...null!=s?s:{},[o]:e}):ex(s=>{var t;let l=null!==(t=null==s?void 0:s[V])&&void 0!==t?t:{};return{...null!=s?s:{},[V]:{...l,[o]:e}}})}})})]},s)})})}),(0,c.jsx)(b.Z,{className:"mt-6 mr-8",onClick:sy,children:"Save"})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lg,{accessToken:s,initialModelGroupAlias:eP,onAliasUpdate:eE})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"p-6",children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"Price Data Management"}),(0,c.jsx)(k.Z,{className:"text-tremor-content",children:"Manage model pricing data and configure automatic reload schedules"})]}),(0,c.jsx)(t6,{accessToken:s,onReloadSuccess:()=>{(async()=>{p(await (0,j.modelCostMap)(s))})()},buttonText:"Reload Price Data",size:"middle",type:"primary",className:"w-full"})]})})]})]})]})})})},lv=e=>{let{visible:s,possibleUIRoles:t,onCancel:l,user:a,onSubmit:r}=e,[i,n]=(0,d.useState)(a),[o]=A.Z.useForm();(0,d.useEffect)(()=>{o.resetFields()},[a]);let m=async()=>{o.resetFields(),l()},u=async e=>{r(e),o.resetFields(),l()};return a?(0,c.jsx)(L.Z,{visible:s,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,c.jsx)(A.Z,{form:o,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"User Role",name:"user_role",children:(0,c.jsx)(I.default,{children:t&&Object.entries(t).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.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,c.jsx)(eW.Z,{min:0,step:.01})}),(0,c.jsx)(A.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,c.jsx)(O,{min:0,step:.01})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsx)(eT,{})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},ly=t(16853);function lb(e){let{userData:s,onCancel:t,onSubmit:l,teams:a,accessToken:r,userID:i,userRole:n,userModels:o,possibleUIRoles:m,isBulkEdit:u=!1}=e,[x]=A.Z.useForm();return d.useEffect(()=>{var e,t,l,a,r,i;x.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(t=s.user_info)||void 0===t?void 0:t.user_role,models:(null===(l=s.user_info)||void 0===l?void 0:l.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,budget_duration:null===(r=s.user_info)||void 0===r?void 0:r.budget_duration,metadata:(null===(i=s.user_info)||void 0===i?void 0:i.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,x]),(0,c.jsxs)(A.Z,{form:x,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}l(e)},layout:"vertical",children:[!u&&(0,c.jsx)(A.Z.Item,{label:"User ID",name:"user_id",children:(0,c.jsx)(_.Z,{disabled:!0})}),!u&&(0,c.jsx)(A.Z.Item,{label:"Email",name:"user_email",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Global Proxy Role"," ",(0,c.jsx)(V.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,c.jsx)(B.Z,{})})]}),name:"user_role",children:(0,c.jsx)(I.default,{children:m&&Object.entries(m).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(ei.Z,{value:s,title:t,children:(0,c.jsxs)("div",{className:"flex",children:[t," ",(0,c.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:l})]})},s)})})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Personal Models"," ",(0,c.jsx)(V.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eI.ZL.includes(n||""),children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),(0,c.jsx)(I.default.Option,{value:"no-default-models",children:"No Default Models"},"no-default-models"),o.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsx)(eT,{})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(ly.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",type:"button",onClick:t,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})]})}let{Text:l_,Title:lN}=en.default;var lZ=e=>{let{visible:s,onCancel:t,selectedUsers:l,possibleUIRoles:a,accessToken:r,onSuccess:i,teams:n,userRole:o,userModels:m,allowAllUsers:u=!1}=e,[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(!1),[_,N]=(0,d.useState)(!1),Z=()=>{g([]),v(null),b(!1),N(!1),t()},w=d.useMemo(()=>({user_id:"bulk_edit",user_info:{user_email:"",user_role:"",teams:[],models:[],max_budget:null,spend:0,metadata:{},created_at:null,updated_at:null},keys:[],teams:n||[]}),[n,s]),k=async e=>{if(console.log("formValues",e),!r){eo.Z.fromBackend("Access token not found");return}h(!0);try{let s=l.map(e=>e.user_id),a={};e.user_role&&""!==e.user_role&&(a.user_role=e.user_role),null!==e.max_budget&&void 0!==e.max_budget&&(a.max_budget=e.max_budget),e.models&&e.models.length>0&&(a.models=e.models),e.budget_duration&&""!==e.budget_duration&&(a.budget_duration=e.budget_duration),e.metadata&&Object.keys(e.metadata).length>0&&(a.metadata=e.metadata);let n=Object.keys(a).length>0,o=y&&p.length>0;if(!n&&!o){eo.Z.fromBackend("Please modify at least one field or select teams to add users to");return}let c=[];if(n){if(_){let e=await (0,j.userBulkUpdateUserCall)(r,a,void 0,!0);c.push("Updated all users (".concat(e.total_requested," total)"))}else await (0,j.userBulkUpdateUserCall)(r,a,s),c.push("Updated ".concat(s.length," user(s)"))}if(o){let e=[];for(let s of p)try{let t=null;_?t=null:l.map(e=>({user_id:e.user_id,role:"user",user_email:e.user_email||null}));let a=await (0,j.teamBulkMemberAddCall)(r,s,t||null,f||void 0,_);console.log("result",a),e.push({teamId:s,success:!0,successfulAdditions:a.successful_additions,failedAdditions:a.failed_additions})}catch(t){console.error("Failed to add users to team ".concat(s,":"),t),e.push({teamId:s,success:!1,error:t})}let s=e.filter(e=>e.success),t=e.filter(e=>!e.success);if(s.length>0){let e=s.reduce((e,s)=>e+s.successfulAdditions,0);c.push("Added users to ".concat(s.length," team(s) (").concat(e," total additions)"))}t.length>0&&tc.ZP.warning("Failed to add users to ".concat(t.length," team(s)"))}c.length>0&&eo.Z.success(c.join(". ")),g([]),v(null),b(!1),N(!1),i(),t()}catch(e){console.error("Bulk operation failed:",e),eo.Z.fromBackend("Failed to perform bulk operations")}finally{h(!1)}};return(0,c.jsxs)(L.Z,{visible:s,onCancel:Z,footer:null,title:_?"Bulk Edit All Users":"Bulk Edit ".concat(l.length," User(s)"),width:800,children:[u&&(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsx)(ts.Z,{checked:_,onChange:e=>N(e.target.checked),children:(0,c.jsx)(l_,{strong:!0,children:"Update ALL users in the system"})}),_&&(0,c.jsx)("div",{style:{marginTop:8},children:(0,c.jsx)(l_,{type:"warning",style:{fontSize:"12px"},children:"⚠️ This will apply changes to ALL users in the system, not just the selected ones."})})]}),!_&&(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsxs)(lN,{level:5,children:["Selected Users (",l.length,"):"]}),(0,c.jsx)(em.Z,{size:"small",bordered:!0,dataSource:l,pagination:!1,scroll:{y:200},rowKey:"user_id",columns:[{title:"User ID",dataIndex:"user_id",key:"user_id",width:"30%",render:e=>(0,c.jsx)(l_,{strong:!0,style:{fontSize:"12px"},children:e.length>20?"".concat(e.slice(0,20),"..."):e})},{title:"Email",dataIndex:"user_email",key:"user_email",width:"25%",render:e=>(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:e||"No email"})},{title:"Current Role",dataIndex:"user_role",key:"user_role",width:"25%",render:e=>{var s;return(0,c.jsx)(l_,{style:{fontSize:"12px"},children:(null==a?void 0:null===(s=a[e])||void 0===s?void 0:s.ui_label)||e})}},{title:"Budget",dataIndex:"max_budget",key:"max_budget",width:"20%",render:e=>(0,c.jsx)(l_,{style:{fontSize:"12px"},children:null!==e?"$".concat(e):"Unlimited"})}]})]}),(0,c.jsx)(K.Z,{}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsxs)(l_,{children:[(0,c.jsx)("strong",{children:"Instructions:"})," Fill in the fields below with the values you want to apply to all selected users. You can bulk edit: role, budget, models, and metadata. You can also add users to teams."]})}),(0,c.jsx)(tN.Z,{title:"Team Management",size:"small",className:"mb-4",style:{backgroundColor:"#fafafa"},children:(0,c.jsxs)(tX.Z,{direction:"vertical",style:{width:"100%"},children:[(0,c.jsx)(ts.Z,{checked:y,onChange:e=>b(e.target.checked),children:"Add selected users to teams"}),y&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(l_,{strong:!0,children:"Select Teams:"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select teams to add users to",value:p,onChange:g,style:{width:"100%",marginTop:8},options:(null==n?void 0:n.map(e=>({label:e.team_alias||e.team_id,value:e.team_id})))||[]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(l_,{strong:!0,children:"Team Budget (Optional):"}),(0,c.jsx)(eW.Z,{placeholder:"Max budget per user in team",value:f,onChange:e=>v(e),style:{width:"100%",marginTop:8},min:0,step:.01,precision:2}),(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:"Leave empty for unlimited budget within team limits"})]}),(0,c.jsx)(l_,{type:"secondary",style:{fontSize:"12px"},children:'Users will be added with "user" role by default. All users will be added to each selected team.'})]})]})}),(0,c.jsx)(lb,{userData:w,onCancel:Z,onSubmit:k,teams:n,accessToken:r,userID:"bulk_edit",userRole:o,userModels:m,possibleUIRoles:a,isBulkEdit:!0}),x&&(0,c.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,c.jsxs)(l_,{children:["Updating ",_?"all users":l.length," user(s)..."]})})]})};let lw=(e,s,t,l,a,r)=>{let i=[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,c.jsx)(V.Z,{title:s.original.user_id,children:(0,c.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var t;let{row:l}=s;return(0,c.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(t=e[l.original.user_role])||void 0===t?void 0:t.ui_label)||"-"})}},{header:"Spend (USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.spend?eE(s.original.spend,4):"-"})}},{header:"Budget (USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{children:"SSO ID"}),(0,c.jsx)(V.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,c.jsx)(t3.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,c.jsx)(y.Z,{numItems:2,children:s.original.key_count>0?(0,c.jsxs)(eX.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,c.jsx)(eX.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,c.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(V.Z,{title:"Edit user details",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>a(s.original.user_id,!0)})}),(0,c.jsx)(V.Z,{title:"Delete user",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>t(s.original.user_id)})}),(0,c.jsx)(V.Z,{title:"Reset Password",zIndex:9999,children:(0,c.jsx)(sZ.Z,{icon:e3.Z,size:"sm",onClick:()=>l(s.original.user_id)})})]})}}];if(r){let{onSelectUser:e,onSelectAll:s,isUserSelected:t,isAllSelected:l,isIndeterminate:a}=r;return[{id:"select",header:()=>(0,c.jsx)(ts.Z,{indeterminate:a,checked:l,onChange:e=>s(e.target.checked),onClick:e=>e.stopPropagation()}),cell:s=>{let{row:l}=s;return(0,c.jsx)(ts.Z,{checked:t(l.original),onChange:s=>e(l.original,s.target.checked),onClick:e=>e.stopPropagation()})}},...i]}return i};function lk(e){var s,t,l,a,r,i,n,o,m,u,x,h,p,g,f,v,_,N,Z,w,C,I,A,L,T,E,M,O,D,F,R,z,U,q,B,V,K;let{userId:H,onClose:J,accessToken:Y,userRole:$,onDelete:Q,possibleUIRoles:X,initialTab:ee=0,startInEditMode:es=!1}=e,[et,el]=(0,d.useState)(null),[ea,er]=(0,d.useState)(!1),[ei,en]=(0,d.useState)(!0),[ed,em]=(0,d.useState)(es),[eu,ex]=(0,d.useState)([]),[eh,ep]=(0,d.useState)(!1),[eg,ej]=(0,d.useState)(null),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(ee),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)(!1);d.useEffect(()=>{ev((0,j.getProxyBaseUrl)())},[]),d.useEffect(()=>{console.log("userId: ".concat(H,", userRole: ").concat($,", accessToken: ").concat(Y)),(async()=>{try{if(!Y)return;let e=await (0,j.userInfoCall)(Y,H,$||"",!1,null,null,!0);el(e);let s=(await (0,j.modelAvailableCall)(Y,H,$||"")).data.map(e=>e.id);ex(s)}catch(e){console.error("Error fetching user data:",e),eo.Z.fromBackend("Failed to fetch user data")}finally{en(!1)}})()},[Y,H,$]);let ek=async()=>{if(!Y){eo.Z.fromBackend("Access token not found");return}try{eo.Z.success("Generating password reset link...");let e=await (0,j.invitationCreateCall)(Y,H);ej(e),ep(!0)}catch(e){eo.Z.fromBackend("Failed to generate password reset link")}},eS=async()=>{try{if(!Y)return;await (0,j.userDeleteCall)(Y,[H]),eo.Z.success("User deleted successfully"),Q&&Q(),J()}catch(e){console.error("Error deleting user:",e),eo.Z.fromBackend("Failed to delete user")}},eC=async e=>{try{if(!Y||!et)return;await (0,j.userUpdateUserCall)(Y,e,null),el({...et,user_info:{...et.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:e.metadata}}),eo.Z.success("User updated successfully"),em(!1)}catch(e){console.error("Error updating user:",e),eo.Z.fromBackend("Failed to update user")}};if(ei)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(k.Z,{children:"Loading user data..."})]});if(!et)return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(k.Z,{children:"User not found"})]});let eA=async(e,s)=>{await eM(e)&&(eN(e=>({...e,[s]:!0})),setTimeout(()=>{eN(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:J,className:"mb-4",children:"Back to Users"}),(0,c.jsx)(S.Z,{children:(null===(s=et.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:et.user_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["user-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eA(et.user_id,"user-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["user-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),$&&eI.LQ.includes($)&&(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)(b.Z,{icon:e3.Z,variant:"secondary",onClick:ek,className:"flex items-center",children:"Reset Password"}),(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>er(!0),className:"flex items-center",children:"Delete User"})]})]}),ea&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:eS,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>er(!1),children:"Cancel"})]})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:ey,onIndexChange:eb,children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Details"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Spend"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE((null===(t=et.user_info)||void 0===t?void 0:t.spend)||0,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",(null===(l=et.user_info)||void 0===l?void 0:l.max_budget)!==null?"$".concat(eE(et.user_info.max_budget,4)):"Unlimited"]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Teams"}),(0,c.jsx)("div",{className:"mt-2",children:(null===(a=et.teams)||void 0===a?void 0:a.length)&&(null===(r=et.teams)||void 0===r?void 0:r.length)>0?(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[null===(i=et.teams)||void 0===i?void 0:i.slice(0,eZ?et.teams.length:20).map((e,s)=>(0,c.jsx)(eX.Z,{color:"blue",title:e.team_alias,children:e.team_alias},s)),!eZ&&(null===(n=et.teams)||void 0===n?void 0:n.length)>20&&(0,c.jsxs)(eX.Z,{color:"gray",className:"cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!0),children:["+",et.teams.length-20," more"]}),eZ&&(null===(o=et.teams)||void 0===o?void 0:o.length)>20&&(0,c.jsx)(eX.Z,{color:"gray",className:"cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!1),children:"Show Less"})]}):(0,c.jsx)(k.Z,{children:"No teams"})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"API Keys"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsxs)(k.Z,{children:[(null===(m=et.keys)||void 0===m?void 0:m.length)||0," keys"]})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Personal Models"}),(0,c.jsx)("div",{className:"mt-2",children:(null===(x=et.user_info)||void 0===x?void 0:null===(u=x.models)||void 0===u?void 0:u.length)&&(null===(p=et.user_info)||void 0===p?void 0:null===(h=p.models)||void 0===h?void 0:h.length)>0?null===(f=et.user_info)||void 0===f?void 0:null===(g=f.models)||void 0===g?void 0:g.map((e,s)=>(0,c.jsx)(k.Z,{children:e},s)):(0,c.jsx)(k.Z,{children:"All proxy models"})})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"User Settings"}),!ed&&$&&eI.LQ.includes($)&&(0,c.jsx)(b.Z,{variant:"light",onClick:()=>em(!0),children:"Edit Settings"})]}),ed&&et?(0,c.jsx)(lb,{userData:et,onCancel:()=>em(!1),onSubmit:eC,teams:et.teams,accessToken:Y,userID:H,userRole:$,userModels:eu,possibleUIRoles:X}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"User ID"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"font-mono",children:et.user_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:e_["user-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>eA(et.user_id,"user-id"),className:"left-2 z-10 transition-all duration-200 ".concat(e_["user-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Email"}),(0,c.jsx)(k.Z,{children:(null===(v=et.user_info)||void 0===v?void 0:v.user_email)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Global Proxy Role"}),(0,c.jsx)(k.Z,{children:(null===(_=et.user_info)||void 0===_?void 0:_.user_role)||"Not Set"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:(null===(N=et.user_info)||void 0===N?void 0:N.created_at)?new Date(et.user_info.created_at).toLocaleString():"Unknown"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(k.Z,{children:(null===(Z=et.user_info)||void 0===Z?void 0:Z.updated_at)?new Date(et.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Teams"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(w=et.teams)||void 0===w?void 0:w.length)&&(null===(C=et.teams)||void 0===C?void 0:C.length)>0?(0,c.jsxs)(c.Fragment,{children:[null===(I=et.teams)||void 0===I?void 0:I.slice(0,eZ?et.teams.length:20).map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",title:e.team_alias||e.team_id,children:e.team_alias||e.team_id},s)),!eZ&&(null===(A=et.teams)||void 0===A?void 0:A.length)>20&&(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded text-xs cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!0),children:["+",et.teams.length-20," more"]}),eZ&&(null===(L=et.teams)||void 0===L?void 0:L.length)>20&&(0,c.jsx)("span",{className:"px-2 py-1 bg-gray-100 rounded text-xs cursor-pointer hover:bg-gray-200 transition-colors",onClick:()=>ew(!1),children:"Show Less"})]}):(0,c.jsx)(k.Z,{children:"No teams"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Personal Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(E=et.user_info)||void 0===E?void 0:null===(T=E.models)||void 0===T?void 0:T.length)&&(null===(O=et.user_info)||void 0===O?void 0:null===(M=O.models)||void 0===M?void 0:M.length)>0?null===(F=et.user_info)||void 0===F?void 0:null===(D=F.models)||void 0===D?void 0:D.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,c.jsx)(k.Z,{children:"All proxy models"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"API Keys"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(R=et.keys)||void 0===R?void 0:R.length)&&(null===(z=et.keys)||void 0===z?void 0:z.length)>0?et.keys.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,c.jsx)(k.Z,{children:"No API keys"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Max Budget"}),(0,c.jsx)(k.Z,{children:(null===(U=et.user_info)||void 0===U?void 0:U.max_budget)!==null&&(null===(q=et.user_info)||void 0===q?void 0:q.max_budget)!==void 0?"$".concat(eE(et.user_info.max_budget,4)):"Unlimited"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget Reset"}),(0,c.jsx)(k.Z,{children:eL(null!==(K=null===(B=et.user_info)||void 0===B?void 0:B.budget_duration)&&void 0!==K?K:null)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(V=et.user_info)||void 0===V?void 0:V.metadata)||{},null,2)})]})]})]})})]})]}),(0,c.jsx)(ec,{isInvitationLinkModalVisible:eh,setIsInvitationLinkModalVisible:ep,baseUrl:ef||"",invitationLinkData:eg,modalType:"resetPassword"})]})}function lS(e){let{data:s=[],columns:t,isLoading:l=!1,onSortChange:a,currentSort:r,accessToken:i,userRole:n,possibleUIRoles:o,handleEdit:m,handleDelete:u,handleResetPassword:x,selectedUsers:h=[],onSelectionChange:p,enableSelection:g=!1,filters:j,updateFilters:f,initialFilters:v,teams:y,userListResponse:b,currentPage:_,handlePageChange:N}=e,[Z,w]=d.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[k,S]=d.useState(null),[C,I]=d.useState(!1),[A,L]=d.useState(!1),T=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];S(e),I(s)},P=(e,s)=>{p&&(s?p([...h,e]):p(h.filter(s=>s.user_id!==e.user_id)))},E=e=>{p&&(e?p(s):p([]))},M=e=>h.some(s=>s.user_id===e.user_id),O=s.length>0&&h.length===s.length,D=h.length>0&&h.lengtho?lw(o,m,u,x,T,g?{selectedUsers:h,onSelectUser:P,onSelectAll:E,isUserSelected:M,isAllSelected:O,isIndeterminate:D}:void 0):t,[o,m,u,x,T,t,g,h,O,D]),R=(0,s_.b7)({data:s,columns:F,state:{sorting:Z},onSortingChange:e=>{if(w(e),e.length>0){let s=e[0],t=s.id,l=s.desc?"desc":"asc";null==a||a(t,l)}},getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(d.useEffect(()=>{r&&w([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),k)?(0,c.jsx)(lk,{userId:k,onClose:()=>{S(null),I(!1)},accessToken:i,userRole:n,possibleUIRoles:o,initialTab:C?1:0,startInEditMode:C}):(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search by email...",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:j.email,onChange:e=>f({email:e.target.value})}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(A?"bg-gray-100":""),onClick:()=>L(!A),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters",(j.user_id||j.user_role||j.team)&&(0,c.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{f(v)},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),A&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Filter by User 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:j.user_id,onChange:e=>f({user_id:e.target.value})}),(0,c.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,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:j.user_role,onValueChange:e=>f({user_role:e}),placeholder:"Select Role",children:o&&Object.entries(o).map(e=>{let[s,t]=e;return(0,c.jsx)(ei.Z,{value:s,children:t.ui_label},s)})})}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:j.team,onValueChange:e=>f({team:e}),placeholder:"Select Team",children:null==y?void 0:y.map(e=>(0,c.jsx)(ei.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,c.jsx)("div",{className:"relative w-64",children:(0,c.jsx)("input",{type:"text",placeholder:"Filter by SSO 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:j.sso_user_id,onChange:e=>f({sso_user_id:e.target.value})})})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",b&&b.users&&b.users.length>0?(b.page-1)*b.page_size+1:0," ","-"," ",b&&b.users?Math.min(b.page*b.page_size,b.total):0," ","of ",b?b.total:0," results"]}),(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>N(_-1),disabled:1===_,className:"px-3 py-1 text-sm border rounded-md ".concat(1===_?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,c.jsx)("button",{onClick:()=>N(_+1),disabled:!b||_>=b.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!b||_>=b.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,c.jsx)("div",{className:"overflow-auto",children:(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:R.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:l?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:F.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?R.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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)]":""),onClick:()=>{"user_id"===e.column.id&&T(e.getValue(),!1)},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:F.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No users found"})})})})})]})})})})]})}var lC=t(67982),lI=t(87908),lA=e=>{var s;let{accessToken:t,possibleUIRoles:l,userID:a,userRole:r}=e,[i,n]=(0,d.useState)(!0),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)({}),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),{Paragraph:N}=en.default,{Option:Z}=I.default;(0,d.useEffect)(()=>{(async()=>{if(!t){n(!1);return}try{let e=await (0,j.getInternalUserSettings)(t);if(m(e),p(e.values||{}),t)try{let e=await (0,j.modelAvailableCall)(t,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);y(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),eo.Z.fromBackend("Failed to fetch SSO settings")}finally{n(!1)}})()},[t]);let w=async()=>{if(t){f(!0);try{let e=Object.entries(h).reduce((e,s)=>{let[t,l]=s;return e[t]=""===l?null:l,e},{}),s=await (0,j.updateInternalUserSettings)(t,e);m({...o,values:s.settings}),x(!1)}catch(e){console.error("Error updating SSO settings:",e),eo.Z.fromBackend("Failed to update settings: "+e)}finally{f(!1)}}},C=(e,s)=>{p(t=>({...t,[e]:s}))},A=e=>e&&Array.isArray(e)?e.map(e=>"string"==typeof e?{team_id:e,user_role:"user"}:"object"==typeof e&&e.team_id?{team_id:e.team_id,max_budget_in_team:e.max_budget_in_team,user_role:e.user_role||"user"}:{team_id:"",user_role:"user"}):[],L=e=>{let s=A(e),t=(e,t,l)=>{let a=[...s];a[e]={...a[e],[t]:l},C("teams",a)},l=e=>{C("teams",s.filter((s,t)=>t!==e))};return(0,c.jsxs)("div",{className:"space-y-3",children:[s.map((e,s)=>(0,c.jsxs)("div",{className:"border rounded-lg p-4 bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["Team ",s+1]}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",icon:ep.Z,onClick:()=>l(s),className:"text-red-500 hover:text-red-700",children:"Remove"})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"Team ID"}),(0,c.jsx)(_.Z,{value:e.team_id,onChange:e=>t(s,"team_id",e.target.value),placeholder:"Enter team ID"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"Max Budget in Team"}),(0,c.jsx)(eW.Z,{style:{width:"100%"},value:e.max_budget_in_team,onChange:e=>t(s,"max_budget_in_team",e),placeholder:"Optional",min:0,step:.01,precision:2})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium mb-1",children:"User Role"}),(0,c.jsxs)(I.default,{style:{width:"100%"},value:e.user_role,onChange:e=>t(s,"user_role",e),children:[(0,c.jsx)(Z,{value:"user",children:"User"}),(0,c.jsx)(Z,{value:"admin",children:"Admin"})]})]})]})]},s)),(0,c.jsx)(b.Z,{variant:"secondary",icon:tv.Z,onClick:()=>{C("teams",[...s,{team_id:"",user_role:"user"}])},className:"w-full",children:"Add Team"})]})},T=(e,s,t)=>{var a;let r=s.type;if("teams"===e)return(0,c.jsx)("div",{className:"mt-2",children:L(h[e]||[])});if("user_role"===e&&l)return(0,c.jsx)(I.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>C(e,s),className:"mt-2",children:Object.entries(l).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:t,description:l}]=e;return(0,c.jsx)(Z,{value:s,children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{children:t}),(0,c.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:l})]})},s)})});if("budget_duration"===e)return(0,c.jsx)(eT,{value:h[e]||null,onChange:s=>C(e,s),className:"mt-2"});if("boolean"===r)return(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(tj.Z,{checked:!!h[e],onChange:s=>C(e,s)})});if("array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum))return(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>C(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,c.jsx)(Z,{value:e,children:e},e))});if("models"===e)return(0,c.jsxs)(I.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>C(e,s),className:"mt-2",children:[(0,c.jsx)(Z,{value:"no-default-models",children:"No Default Models"}),v.map(e=>(0,c.jsx)(Z,{value:e,children:F(e)},e))]});if("string"===r&&s.enum)return(0,c.jsx)(I.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>C(e,s),className:"mt-2",children:s.enum.map(e=>(0,c.jsx)(Z,{value:e,children:e},e))});else return(0,c.jsx)(_.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>C(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},P=(e,s)=>{if(null==s)return(0,c.jsx)("span",{className:"text-gray-400",children:"Not set"});if("teams"===e&&Array.isArray(s)){if(0===s.length)return(0,c.jsx)("span",{className:"text-gray-400",children:"No teams assigned"});let e=A(s);return(0,c.jsx)("div",{className:"space-y-2 mt-1",children:e.map((e,s)=>(0,c.jsx)("div",{className:"border rounded-lg p-3 bg-white",children:(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 text-sm",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Team ID:"}),(0,c.jsx)("p",{className:"text-gray-900",children:e.team_id||"Not specified"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Max Budget:"}),(0,c.jsx)("p",{className:"text-gray-900",children:void 0!==e.max_budget_in_team?"$".concat(eE(e.max_budget_in_team,4)):"No limit"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium text-gray-600",children:"Role:"}),(0,c.jsx)("p",{className:"text-gray-900 capitalize",children:e.user_role})]})]})},s))})}if("user_role"===e&&l&&l[s]){let{ui_label:e,description:t}=l[s];return(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-medium",children:e}),t&&(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:t})]})}return"budget_duration"===e?(0,c.jsx)("span",{children:eL(s)}):"boolean"==typeof s?(0,c.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:F(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,c.jsx)("span",{children:String(s)})};return i?(0,c.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,c.jsx)(lI.Z,{size:"large"})}):o?(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Default User Settings"}),!i&&o&&(u?(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{x(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:w,loading:g,children:"Save Changes"})]}):(0,c.jsx)(b.Z,{onClick:()=>x(!0),children:"Edit Settings"}))]}),(null==o?void 0:null===(s=o.field_schema)||void 0===s?void 0:s.description)&&(0,c.jsx)(N,{className:"mb-4",children:o.field_schema.description}),(0,c.jsx)(lC.Z,{}),(0,c.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,field_schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[t,l]=s,a=e[t],r=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,c.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,c.jsx)(k.Z,{className:"font-medium text-lg",children:r}),(0,c.jsx)(N,{className:"text-sm text-gray-500 mt-1",children:l.description||"No description available"}),u?(0,c.jsx)("div",{className:"mt-2",children:T(t,l,a)}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:P(t,a)})]},t)}):(0,c.jsx)(k.Z,{children:"No schema information available"})})()})]}):(0,c.jsx)(G.Z,{children:(0,c.jsx)(k.Z,{children:"No settings available or you do not have permission to view them."})})},lL=t(19616);let lT={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lP=e=>{var s;let{accessToken:t,token:l,userRole:a,userID:r,teams:i}=e,n=(0,h.NL)(),[o,m]=(0,d.useState)(1),[u,x]=(0,d.useState)(!1),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!1),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)("users"),[w,k]=(0,d.useState)(lT),[S,C,I]=(0,lL.G)(w,{wait:300}),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(null),[E,M]=(0,d.useState)(null),[O,D]=(0,d.useState)([]),[F,R]=(0,d.useState)(!1),[z,U]=(0,d.useState)(!1),[q,B]=(0,d.useState)([]),V=e=>{_(e),v(!0)};(0,d.useEffect)(()=>()=>{I.cancel()},[I]),(0,d.useEffect)(()=>{M((0,j.getProxyBaseUrl)())},[]),(0,d.useEffect)(()=>{(async()=>{try{if(!r||!a||!t)return;let e=(await (0,j.modelAvailableCall)(t,r,a)).data.map(e=>e.id);console.log("available_model_names:",e),B(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,a]);let K=e=>{k(s=>{let t={...s,...e};return C(t),t})},G=async e=>{if(!t){eo.Z.fromBackend("Access token not found");return}try{eo.Z.success("Generating password reset link...");let s=await (0,j.invitationCreateCall)(t,e);P(s),L(!0)}catch(e){eo.Z.fromBackend("Failed to generate password reset link")}},H=async()=>{if(y&&t)try{await (0,j.userDeleteCall)(t,[y]),n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==y);return{...e,users:s}}),eo.Z.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),eo.Z.fromBackend("Failed to delete user")}v(!1),_(null)},J=async()=>{g(null),x(!1)},Y=async e=>{if(console.log("inside handleEditSubmit:",e),t&&l&&a&&r){try{let s=await (0,j.userUpdateUserCall)(t,e,null);n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let t=e.users.map(e=>e.user_id===s.data.user_id?eP(e,s.data):e);return{...e,users:t}}),eo.Z.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}g(null),x(!1)}},W=async e=>{m(e)},$=(0,sj.a)({queryKey:["userList",{debouncedFilter:S,currentPage:o}],queryFn:async()=>{if(!t)throw Error("Access token required");return await (0,j.userListCall)(t,S.user_id?[S.user_id]:null,o,25,S.email||null,S.user_role||null,S.team||null,S.sso_user_id||null,S.sort_by,S.sort_order)},enabled:!!(t&&l&&a&&r),placeholderData:e=>e}),Q=$.data,X=(0,sj.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!t)throw Error("Access token required");return await (0,j.getPossibleUserRoles)(t)},enabled:!!(t&&l&&a&&r)}).data;if($.isLoading||!t||!l||!a||!r)return(0,c.jsx)("div",{children:"Loading..."});let ee=lw(X,e=>{g(e),x(!0)},V,G,()=>{});return(0,c.jsxs)("div",{className:"w-full p-8 overflow-hidden",children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,c.jsxs)("div",{className:"flex space-x-3",children:[(0,c.jsx)(ek,{userID:r,accessToken:t,teams:i,possibleUIRoles:X}),(0,c.jsx)(b.Z,{onClick:()=>{U(!z),D([])},variant:z?"primary":"secondary",className:"flex items-center",children:z?"Cancel Selection":"Select Users"}),z&&(0,c.jsxs)(b.Z,{onClick:()=>{if(0===O.length){eo.Z.fromBackend("Please select users to edit");return}R(!0)},disabled:0===O.length,className:"flex items-center",children:["Bulk Edit (",O.length," selected)"]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Users"}),(0,c.jsx)(e0.Z,{children:"Default User Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lS,{data:(null===(s=$.data)||void 0===s?void 0:s.users)||[],columns:ee,isLoading:$.isLoading,accessToken:t,userRole:a,onSortChange:(e,s)=>{K({sort_by:e,sort_order:s})},currentSort:{sortBy:w.sort_by,sortOrder:w.sort_order},possibleUIRoles:X,handleEdit:e=>{g(e),x(!0)},handleDelete:V,handleResetPassword:G,enableSelection:z,selectedUsers:O,onSelectionChange:e=>{D(e)},filters:w,updateFilters:K,initialFilters:lT,teams:i,userListResponse:Q,currentPage:o,handlePageChange:W})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lA,{accessToken:t,possibleUIRoles:X,userID:r,userRole:a})})]})]}),(0,c.jsx)(lv,{visible:u,possibleUIRoles:X,onCancel:J,user:p,onSubmit:Y}),f&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,c.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",y]})]})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:H,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{v(!1),_(null)},children:"Cancel"})]})]})]})}),(0,c.jsx)(ec,{isInvitationLinkModalVisible:A,setIsInvitationLinkModalVisible:L,baseUrl:E||"",invitationLinkData:T,modalType:"resetPassword"}),(0,c.jsx)(lZ,{visible:F,onCancel:()=>R(!1),selectedUsers:O,possibleUIRoles:X,accessToken:t,onSuccess:()=>{n.invalidateQueries({queryKey:["userList"]}),D([]),U(!1)},teams:i,userRole:a,userModels:q,allowAllUsers:!!a&&(0,eI.tY)(a)})]})},lE=e=>{var s;let{accessToken:t,userID:l,userRole:a}=e,[r,i]=(0,d.useState)(!0),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)({}),[p,g]=(0,d.useState)(!1),[f,v]=(0,d.useState)([]),{Paragraph:y}=en.default,{Option:N}=I.default;(0,d.useEffect)(()=>{(async()=>{if(!t){i(!1);return}try{let e=await (0,j.getDefaultTeamSettings)(t);if(o(e),h(e.values||{}),t)try{let e=await (0,j.modelAvailableCall)(t,l,a);if(e&&e.data){let s=e.data.map(e=>e.id);v(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),eo.Z.fromBackend("Failed to fetch team settings")}finally{i(!1)}})()},[t]);let Z=async()=>{if(t){g(!0);try{let e=await (0,j.updateDefaultTeamSettings)(t,x);o({...n,values:e.settings}),u(!1),eo.Z.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),eo.Z.fromBackend("Failed to update team settings")}finally{g(!1)}}},w=(e,s)=>{h(t=>({...t,[e]:s}))},C=(e,s,t)=>{var l;let a=s.type;return"budget_duration"===e?(0,c.jsx)(eT,{value:x[e]||null,onChange:s=>w(e,s),className:"mt-2"}):"boolean"===a?(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(tj.Z,{checked:!!x[e],onChange:s=>w(e,s)})}):"array"===a&&(null===(l=s.items)||void 0===l?void 0:l.enum)?(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>w(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,c.jsx)(N,{value:e,children:e},e))}):"models"===e?(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>w(e,s),className:"mt-2",children:f.map(e=>(0,c.jsx)(N,{value:e,children:F(e)},e))}):"string"===a&&s.enum?(0,c.jsx)(I.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>w(e,s),className:"mt-2",children:s.enum.map(e=>(0,c.jsx)(N,{value:e,children:e},e))}):(0,c.jsx)(_.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>w(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},A=(e,s)=>null==s?(0,c.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,c.jsx)("span",{children:eL(s)}):"boolean"==typeof s?(0,c.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:F(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,c.jsx)("span",{className:"text-gray-400",children:"None"}):(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,c.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,c.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,c.jsx)("span",{children:String(s)});return r?(0,c.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,c.jsx)(lI.Z,{size:"large"})}):n?(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&n&&(m?(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{u(!1),h(n.values||{})},disabled:p,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:Z,loading:p,children:"Save Changes"})]}):(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Settings"}))]}),(0,c.jsx)(k.Z,{children:"These settings will be applied by default when creating new teams."}),(null==n?void 0:null===(s=n.field_schema)||void 0===s?void 0:s.description)&&(0,c.jsx)(y,{className:"mb-4 mt-2",children:n.field_schema.description}),(0,c.jsx)(lC.Z,{}),(0,c.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,field_schema:s}=n;return s&&s.properties?Object.entries(s.properties).map(s=>{let[t,l]=s,a=e[t],r=t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,c.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,c.jsx)(k.Z,{className:"font-medium text-lg",children:r}),(0,c.jsx)(y,{className:"text-sm text-gray-500 mt-1",children:l.description||"No description available"}),m?(0,c.jsx)("div",{className:"mt-2",children:C(t,l,a)}):(0,c.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:A(t,a)})]},t)}):(0,c.jsx)(k.Z,{children:"No schema information available"})})()})]}):(0,c.jsx)(G.Z,{children:(0,c.jsx)(k.Z,{children:"No team settings available or you do not have permission to view them."})})},lM=e=>{let{accessToken:s,userID:t}=e,[l,a]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{if(s&&t)try{let e=await (0,j.availableTeamListCall)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,t]);let r=async e=>{if(s&&t)try{await (0,j.teamMemberAddCall)(s,e,{user_id:t,role:"user"}),eo.Z.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),eo.Z.fromBackend("Failed to join team")}};return(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Team Name"}),(0,c.jsx)(sI.Z,{children:"Description"}),(0,c.jsx)(sI.Z,{children:"Members"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"Actions"})]})}),(0,c.jsxs)(sk.Z,{children:[l.map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.team_alias})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.description||"No description available"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:[e.members_with_roles.length," members"]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})})})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===l.length&&(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:5,className:"text-center",children:(0,c.jsx)(k.Z,{children:"No available teams to join"})})})]})]})})},lO=t(32489),lD=t(76865);let lF=(e,s)=>{let t=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),t=e.models):t=s,R(t,s)};var lR=e=>{let{teams:s,searchParams:t,accessToken:l,setTeams:a,userID:r,userRole:i,organizations:n,premiumUser:o=!1}=e,[m,u]=(0,d.useState)(""),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[S,C]=(0,d.useState)(!1),[T,M]=(0,d.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,d.useEffect)(()=>{console.log("inside useeffect - ".concat(m)),l&&f(l,r,i,x,a),eJ()},[m]);let[R]=A.Z.useForm(),[z]=A.Z.useForm(),{Title:q,Paragraph:K}=en.default,[H,J]=(0,d.useState)(""),[Y,$]=(0,d.useState)(!1),[Q,X]=(0,d.useState)(null),[ee,es]=(0,d.useState)(null),[et,el]=(0,d.useState)(!1),[ea,ec]=(0,d.useState)(!1),[ed,em]=(0,d.useState)(!1),[eu,ex]=(0,d.useState)(!1),[eh,ep]=(0,d.useState)([]),[eg,ej]=(0,d.useState)(!1),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)([]),[e_,eN]=(0,d.useState)({}),[eZ,ew]=(0,d.useState)([]),[ek,eS]=(0,d.useState)({}),[eC,eA]=(0,d.useState)([]),[eL,eT]=(0,d.useState)([]),[eM,eD]=(0,d.useState)(!1),[eF,eR]=(0,d.useState)(""),[ez,eU]=(0,d.useState)({});(0,d.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(p));let e=lF(p,eh);console.log("models: ".concat(e)),eb(e),R.setFieldValue("models",[])},[p,eh]),(0,d.useEffect)(()=>{(async()=>{try{if(null==l)return;let e=(await (0,j.getGuardrailsList)(l)).guardrails.map(e=>e.guardrail_name);ew(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[l]);let eq=async()=>{try{if(null==l)return;let e=await (0,j.fetchMCPAccessGroups)(l);eT(e)}catch(e){console.error("Failed to fetch MCP access groups:",e)}};(0,d.useEffect)(()=>{eq()},[l]),(0,d.useEffect)(()=>{s&&eN(s.reduce((e,s)=>(e[s.team_id]={keys:s.keys||[],team_info:{members_with_roles:s.members_with_roles||[]}},e),{}))},[s]);let eV=async e=>{ev(e),ej(!0)},eK=async()=>{if(null!=ef&&null!=s&&null!=l){try{await (0,j.teamDeleteCall)(l,ef),f(l,r,i,x,a)}catch(e){console.error("Error deleting the team:",e)}ej(!1),ev(null)}},eG=()=>{ej(!1),ev(null)};(0,d.useEffect)(()=>{(async()=>{try{if(null===r||null===i||null===l)return;let e=await D(r,i,l);e&&ep(e)}catch(e){console.error("Error fetching user models:",e)}})()},[l,r,i,s]);let eH=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=l){var t,r,i;let n=null==e?void 0:e.team_alias,o=null!==(i=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==i?i:[],c=(null==e?void 0:e.organization_id)||(null==x?void 0:x.organization_id);if(""===c||"string"!=typeof c?e.organization_id=null:e.organization_id=c.trim(),o.includes(n))throw Error("Team alias ".concat(n," already exists, please pick another alias"));if(eo.Z.info("Creating Team"),eC.length>0){let s={};if(e.metadata)try{s=JSON.parse(e.metadata)}catch(e){console.warn("Invalid JSON in metadata field, starting with empty object")}s={...s,logging:eC.filter(e=>e.callback_name)},e.metadata=JSON.stringify(s)}if((e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0||e.allowed_mcp_servers_and_groups&&((null===(t=e.allowed_mcp_servers_and_groups.servers)||void 0===t?void 0:t.length)>0||(null===(r=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===r?void 0:r.length)>0))&&(e.object_permission={},e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission.vector_stores=e.allowed_vector_store_ids,delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups)){let{servers:s,accessGroups:t}=e.allowed_mcp_servers_and_groups;s&&s.length>0&&(e.object_permission.mcp_servers=s),t&&t.length>0&&(e.object_permission.mcp_access_groups=t),delete e.allowed_mcp_servers_and_groups}e.allowed_mcp_access_groups&&e.allowed_mcp_access_groups.length>0&&(e.object_permission||(e.object_permission={}),e.object_permission.mcp_access_groups=e.allowed_mcp_access_groups,delete e.allowed_mcp_access_groups),Object.keys(ez).length>0&&(e.model_aliases=ez);let d=await (0,j.teamCreateCall)(l,e);null!==s?a([...s,d]):a([d]),console.log("response for team create call: ".concat(d)),eo.Z.success("Team created"),R.resetFields(),eA([]),eU({}),ec(!1)}}catch(e){console.error("Error creating the team:",e),eo.Z.fromBackend("Error creating the team: "+e)}},eJ=()=>{u(new Date().toLocaleString())},eY=(e,s)=>{let t={...T,[e]:s};M(t),l&&(0,j.v2TeamListCall)(l,t.organization_id||null,null,t.team_id||null,t.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[("Admin"==i||"Org Admin"==i)&&(0,c.jsx)(b.Z,{className:"w-fit",onClick:()=>ec(!0),children:"+ Create New Team"}),ee?(0,c.jsx)(tu,{teamId:ee,onUpdate:e=>{a(s=>{if(null==s)return s;let t=s.map(s=>e.team_id===s.team_id?eP(s,e):s);return l&&f(l,r,i,x,a),t})},onClose:()=>{es(null),el(!1)},accessToken:l,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===ee)),is_proxy_admin:"Admin"==i,userModels:eh,editTeam:et}):(0,c.jsxs)(e1.Z,{className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"Your Teams"}),(0,c.jsx)(e0.Z,{children:"Available Teams"}),(0,eI.tY)(i||"")&&(0,c.jsx)(e0.Z,{children:"Default Team Settings"})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[m&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",m]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eJ})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(k.Z,{children:["Click on “Team ID” to view team details"," ",(0,c.jsx)("b",{children:"and"})," manage team members."]}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4",children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Search by Team Name...",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:T.team_alias,onChange:e=>eY("team_alias",e.target.value)}),(0,c.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,c.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,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(S?"bg-gray-100":""),onClick:()=>C(!S),children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Filters",(T.team_id||T.team_alias||T.organization_id)&&(0,c.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,c.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{M({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),l&&(0,j.v2TeamListCall)(l,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),"Reset Filters"]})]}),S&&(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,c.jsxs)("div",{className:"relative w-64",children:[(0,c.jsx)("input",{type:"text",placeholder:"Enter Team 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:T.team_id,onChange:e=>eY("team_id",e.target.value)}),(0,c.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,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,c.jsx)("div",{className:"w-64",children:(0,c.jsx)(eQ.Z,{value:T.organization_id||"",onValueChange:e=>eY("organization_id",e),placeholder:"Select Organization",children:null==n?void 0:n.map(e=>(0,c.jsx)(ei.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Team Name"}),(0,c.jsx)(sI.Z,{children:"Team ID"}),(0,c.jsx)(sI.Z,{children:"Created"}),(0,c.jsx)(sI.Z,{children:"Spend (USD)"}),(0,c.jsx)(sI.Z,{children:"Budget (USD)"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"Organization"}),(0,c.jsx)(sI.Z,{children:"Info"})]})}),(0,c.jsx)(sk.Z,{children:s&&s.length>0?s.filter(e=>!x||e.organization_id===x.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.team_id,children:(0,c.jsxs)(b.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:()=>{es(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,c.jsx)(sS.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:eE(e.spend,4)}),(0,c.jsx)(sS.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,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:e.models.length>3?"px-0":"",children:(0,c.jsx)("div",{className:"flex flex-col",children:Array.isArray(e.models)?(0,c.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[e.models.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:ek[e.team_id]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{eS(s=>({...s,[e.team_id]:!s[e.team_id]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.models.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),e.models.length>3&&!ek[e.team_id]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",e.models.length-3," ",e.models.length-3==1?"more model":"more models"]})}),ek[e.team_id]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:e.models.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}),(0,c.jsx)(sS.Z,{children:e.organization_id}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsxs)(k.Z,{children:[e_&&e.team_id&&e_[e.team_id]&&e_[e.team_id].keys&&e_[e.team_id].keys.length," ","Keys"]}),(0,c.jsxs)(k.Z,{children:[e_&&e.team_id&&e_[e.team_id]&&e_[e.team_id].team_info&&e_[e.team_id].team_info.members_with_roles&&e_[e.team_id].team_info.members_with_roles.length," ","Members"]})]}),(0,c.jsx)(sS.Z,{children:"Admin"==i?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{es(e.team_id),el(!0)}}),(0,c.jsx)(sZ.Z,{onClick:()=>eV(e.team_id),icon:W.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),eg&&(()=>{var e;let t=null==s?void 0:s.find(e=>e.team_id===ef),l=(null==t?void 0:t.team_alias)||"",a=(null==t?void 0:null===(e=t.keys)||void 0===e?void 0:e.length)||0,r=eF===l;return(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl min-h-[380px] py-6 overflow-hidden transform transition-all flex flex-col justify-between",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[(0,c.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete Team"}),(0,c.jsx)("button",{onClick:()=>{eG(),eR("")},className:"text-gray-400 hover:text-gray-500 focus:outline-none",children:(0,c.jsx)(lO.Z,{size:20})})]}),(0,c.jsxs)("div",{className:"px-6 py-4",children:[a>0&&(0,c.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-100 rounded-md mb-5",children:[(0,c.jsx)("div",{className:"text-red-500 mt-0.5",children:(0,c.jsx)(lD.Z,{size:20})}),(0,c.jsxs)("div",{children:[(0,c.jsxs)("p",{className:"text-base font-medium text-red-600",children:["Warning: This team has ",a," associated key",a>1?"s":"","."]}),(0,c.jsx)("p",{className:"text-base text-red-600 mt-2",children:"Deleting the team will also delete all associated keys. This action is irreversible."})]})]}),(0,c.jsx)("p",{className:"text-base text-gray-600 mb-5",children:"Are you sure you want to force delete this team and all its keys?"}),(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsxs)("label",{className:"block text-base font-medium text-gray-700 mb-2",children:["Type ",(0,c.jsx)("span",{className:"underline",children:l})," to confirm deletion:"]}),(0,c.jsx)("input",{type:"text",value:eF,onChange:e=>eR(e.target.value),placeholder:"Enter team name exactly",className:"w-full px-4 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-base",autoFocus:!0})]})]})]}),(0,c.jsxs)("div",{className:"px-6 py-4 bg-gray-50 flex justify-end gap-4",children:[(0,c.jsx)("button",{onClick:()=>{eG(),eR("")},className:"px-5 py-3 bg-white border border-gray-300 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Cancel"}),(0,c.jsx)("button",{onClick:eK,disabled:!r,className:"px-5 py-3 rounded-md text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 ".concat(r?"bg-red-600 hover:bg-red-700":"bg-red-300 cursor-not-allowed"),children:"Force Delete"})]})]})})})()]})})})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lM,{accessToken:l,userID:r})}),(0,eI.tY)(i||"")&&(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lE,{accessToken:l,userID:r||"",userRole:i||""})})]})]}),("Admin"==i||"Org Admin"==i)&&(0,c.jsx)(L.Z,{title:"Create Team",visible:ea,width:1e3,footer:null,onOk:()=>{ec(!1),R.resetFields(),eA([]),eU({})},onCancel:()=>{ec(!1),R.resetFields(),eA([]),eU({})},children:(0,c.jsxs)(A.Z,{form:R,onFinish:eH,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Organization"," ",(0,c.jsx)(V.Z,{title:(0,c.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,c.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,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:x?x.organization_id:null,className:"mt-8",children:(0,c.jsx)(I.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{R.setFieldValue("organization_id",e),g((null==n?void 0:n.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var t;return!!s&&((null===(t=s.children)||void 0===t?void 0:t.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==n?void 0:n.map(e=>(0,c.jsxs)(I.default.Option,{value:e.organization_id,children:[(0,c.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,c.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Models"," ",(0,c.jsx)(V.Z,{title:"These are the models that your selected team has access to",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ey.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",onClick:()=>{eM||(eq(),eD(!0))},children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Additional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.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,c.jsx)(_.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Budget (USD)",name:"team_member_budget",normalize:e=>e?Number(e):void 0,tooltip:"This is the individual budget for a user in the team.",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Team Member Key Duration (eg: 1d, 1mo)",name:"team_member_key_duration",tooltip:"Set a limit to the duration of a team member's key. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days), 1mo (month)",children:(0,c.jsx)(_.Z,{placeholder:"e.g., 30d"})}),(0,c.jsx)(A.Z.Item,{label:"Team Member RPM Limit",name:"team_member_rpm_limit",tooltip:"The RPM (Requests Per Minute) limit for individual team members",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Team Member TPM Limit",name:"team_member_tpm_limit",tooltip:"The TPM (Tokens Per Minute) limit for individual team members",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Guardrails"," ",(0,c.jsx)(V.Z,{title:"Setup your first guardrail",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:eZ.map(e=>({value:e,label:e}))})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this team can access by default. Leave empty for access to all vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-8",help:"Select vector stores this team can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>R.setFieldValue("allowed_vector_store_ids",e),value:R.getFieldValue("allowed_vector_store_ids"),accessToken:l||"",placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers or access groups this team can access by default. ",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-8",help:"Select MCP servers or access groups this team can access. ",children:(0,c.jsx)(eO,{onChange:e=>R.setFieldValue("allowed_mcp_servers_and_groups",e),value:R.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:l||"",placeholder:"Select MCP servers or access groups (optional)"})})]})]}),(0,c.jsxs)(N.Z,{className:"mt-8 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Logging Settings"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(er,{value:eC,onChange:eA,premiumUser:o})})})]}),(0,c.jsxs)(N.Z,{className:"mt-8 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Model Aliases"})}),(0,c.jsx)(Z.Z,{children:(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600 mb-4",children:"Create custom aliases for models that can be used by team members in API calls. This allows you to create shortcuts for specific models."}),(0,c.jsx)(eB,{accessToken:l||"",initialModelAliases:ez,onAliasUpdate:eU,showExampleConfig:!1})]})})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create Team"})})]})})]})})})},lz=e=>{var s,t,l,a,r;let{organizationId:i,onClose:n,accessToken:o,is_org_admin:m,is_proxy_admin:u,userModels:x,editOrg:h}=e,[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!0),[N]=A.Z.useForm(),[Z,w]=(0,d.useState)(!1),[C,L]=(0,d.useState)(!1),[T,M]=(0,d.useState)(!1),[D,R]=(0,d.useState)(null),[z,q]=(0,d.useState)({}),B=m||u,V=async()=>{try{if(v(!0),!o)return;let e=await (0,j.organizationInfoCall)(o,i);g(e)}catch(e){eo.Z.fromBackend("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{v(!1)}};(0,d.useEffect)(()=>{V()},[i,o]);let K=async e=>{try{if(null==o)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.organizationMemberAddCall)(o,i,s),eo.Z.success("Organization member added successfully"),L(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to add organization member"),console.error("Error adding organization member:",e)}},H=async e=>{try{if(!o)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,j.organizationMemberUpdateCall)(o,i,s),eo.Z.success("Organization member updated successfully"),M(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to update organization member"),console.error("Error updating organization member:",e)}},J=async e=>{try{if(!o)return;await (0,j.organizationMemberDeleteCall)(o,i,e.user_id),eo.Z.success("Organization member deleted successfully"),M(!1),N.resetFields(),V()}catch(e){eo.Z.fromBackend("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},Y=async e=>{try{if(!o)return;let s={organization_id:i,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};if((void 0!==e.vector_stores||void 0!==e.mcp_servers_and_groups)&&(s.object_permission={...null==p?void 0:p.object_permission,vector_stores:e.vector_stores||[]},void 0!==e.mcp_servers_and_groups)){let{servers:t,accessGroups:l}=e.mcp_servers_and_groups||{servers:[],accessGroups:[]};t&&t.length>0&&(s.object_permission.mcp_servers=t),l&&l.length>0&&(s.object_permission.mcp_access_groups=l)}await (0,j.organizationUpdateCall)(o,s),eo.Z.success("Organization settings updated successfully"),w(!1),V()}catch(e){eo.Z.fromBackend("Failed to update organization settings"),console.error("Error updating organization:",e)}};if(f)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!p)return(0,c.jsx)("div",{className:"p-4",children:"Organization not found"});let $=async(e,s)=>{await eM(e)&&(q(e=>({...e,[s]:!0})),setTimeout(()=>{q(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,onClick:n,variant:"light",className:"mb-4",children:"Back to Organizations"}),(0,c.jsx)(S.Z,{children:p.organization_alias}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:p.organization_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:z["org-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>$(p.organization_id,"org-id"),className:"left-2 z-10 transition-all duration-200 ".concat(z["org-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:h?2:0,children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"}),(0,c.jsx)(e0.Z,{children:"Members"}),(0,c.jsx)(e0.Z,{children:"Settings"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Organization Details"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["Created: ",new Date(p.created_at).toLocaleDateString()]}),(0,c.jsxs)(k.Z,{children:["Updated: ",new Date(p.updated_at).toLocaleDateString()]}),(0,c.jsxs)(k.Z,{children:["Created By: ",p.created_by]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Budget Status"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(S.Z,{children:["$",eE(p.spend,4)]}),(0,c.jsxs)(k.Z,{children:["of"," ",null===p.litellm_budget_table.max_budget?"Unlimited":"$".concat(eE(p.litellm_budget_table.max_budget,4))]}),p.litellm_budget_table.budget_duration&&(0,c.jsxs)(k.Z,{className:"text-gray-500",children:["Reset: ",p.litellm_budget_table.budget_duration]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Rate Limits"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsxs)(k.Z,{children:["TPM: ",p.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,c.jsxs)(k.Z,{children:["RPM: ",p.litellm_budget_table.rpm_limit||"Unlimited"]}),p.litellm_budget_table.max_parallel_requests&&(0,c.jsxs)(k.Z,{children:["Max Parallel Requests: ",p.litellm_budget_table.max_parallel_requests]})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Models"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:0===p.models.length?(0,c.jsx)(eX.Z,{color:"red",children:"All proxy models"}):p.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Teams"}),(0,c.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=p.teams)||void 0===s?void 0:s.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e.team_id},s))})]}),(0,c.jsx)(sc,{objectPermission:p.object_permission,variant:"card",accessToken:o})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"Role"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{children:"Created At"}),(0,c.jsx)(sI.Z,{})]})}),(0,c.jsx)(sk.Z,{children:null===(t=p.members)||void 0===t?void 0:t.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-mono",children:e.user_role})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:["$",eE(e.spend,4)]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,c.jsx)(sS.Z,{children:B&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{R({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),M(!0)}}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>{J(e)}})]})})]},s))})]})}),B&&(0,c.jsx)(b.Z,{onClick:()=>{L(!0)},children:"Add Member"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{className:"overflow-y-auto max-h-[65vh]",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Organization Settings"}),B&&!Z&&(0,c.jsx)(b.Z,{onClick:()=>w(!0),children:"Edit Settings"})]}),Z?(0,c.jsxs)(A.Z,{form:N,onFinish:Y,initialValues:{organization_alias:p.organization_alias,models:p.models,tpm_limit:p.litellm_budget_table.tpm_limit,rpm_limit:p.litellm_budget_table.rpm_limit,max_budget:p.litellm_budget_table.max_budget,budget_duration:p.litellm_budget_table.budget_duration,metadata:p.metadata?JSON.stringify(p.metadata,null,2):"",vector_stores:(null===(l=p.object_permission)||void 0===l?void 0:l.vector_stores)||[],mcp_servers_and_groups:{servers:(null===(a=p.object_permission)||void 0===a?void 0:a.mcp_servers)||[],accessGroups:(null===(r=p.object_permission)||void 0===r?void 0:r.mcp_access_groups)||[]}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),x.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,style:{width:"100%"}})}),(0,c.jsx)(A.Z.Item,{label:"Vector Stores",name:"vector_stores",children:(0,c.jsx)(U,{onChange:e=>N.setFieldValue("vector_stores",e),value:N.getFieldValue("vector_stores"),accessToken:o||"",placeholder:"Select vector stores"})}),(0,c.jsx)(A.Z.Item,{label:"MCP Servers & Access Groups",name:"mcp_servers_and_groups",children:(0,c.jsx)(eO,{onChange:e=>N.setFieldValue("mcp_servers_and_groups",e),value:N.getFieldValue("mcp_servers_and_groups"),accessToken:o||"",placeholder:"Select MCP servers and access groups"})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)("div",{className:"sticky z-10 bg-white p-4 border-t border-gray-200 bottom-[-1.5rem] inset-x-[-1.5rem]",children:(0,c.jsxs)("div",{className:"flex justify-end items-center gap-2",children:[(0,c.jsx)(P.ZP,{onClick:()=>w(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization Name"}),(0,c.jsx)("div",{children:p.organization_alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Organization ID"}),(0,c.jsx)("div",{className:"font-mono",children:p.organization_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:new Date(p.created_at).toLocaleString()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Models"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:p.models.map((e,s)=>(0,c.jsx)(eX.Z,{color:"red",children:e},s))})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Rate Limits"}),(0,c.jsxs)("div",{children:["TPM: ",p.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,c.jsxs)("div",{children:["RPM: ",p.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Budget"}),(0,c.jsxs)("div",{children:["Max:"," ",null!==p.litellm_budget_table.max_budget?"$".concat(eE(p.litellm_budget_table.max_budget,4)):"No Limit"]}),(0,c.jsxs)("div",{children:["Reset: ",p.litellm_budget_table.budget_duration||"Never"]})]}),(0,c.jsx)(sc,{objectPermission:p.object_permission,variant:"inline",className:"pt-4 border-t border-gray-200",accessToken:o})]})]})})]})]}),(0,c.jsx)(tm,{isVisible:C,onCancel:()=>L(!1),onSubmit:K,accessToken:o,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,c.jsx)(td,{visible:T,onCancel:()=>M(!1),onSubmit:H,initialData:D,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"}]}})]})};let lU=async(e,s)=>{s(await (0,j.organizationListCall)(e))};var lq=e=>{let{organizations:s,userRole:t,userModels:l,accessToken:a,lastRefreshed:r,handleRefreshClick:i,currentOrg:n,guardrailsList:o=[],setOrganizations:m,premiumUser:u}=e,[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(!1),[f,_]=(0,d.useState)(!1),[N,Z]=(0,d.useState)(null),[w,S]=(0,d.useState)(!1),[C]=A.Z.useForm(),[T,P]=(0,d.useState)({});(0,d.useEffect)(()=>{a&&lU(a,m)},[a]);let M=e=>{e&&(Z(e),_(!0))},D=async()=>{if(N&&a)try{await (0,j.organizationDeleteCall)(a,N),eo.Z.success("Organization deleted successfully"),_(!1),Z(null),lU(a,m)}catch(e){console.error("Error deleting organization:",e)}},R=async e=>{try{var s,t,l,r;if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),(e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0||e.allowed_mcp_servers_and_groups&&((null===(s=e.allowed_mcp_servers_and_groups.servers)||void 0===s?void 0:s.length)>0||(null===(t=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===t?void 0:t.length)>0))&&(e.object_permission={},e.allowed_vector_store_ids&&e.allowed_vector_store_ids.length>0&&(e.object_permission.vector_stores=e.allowed_vector_store_ids,delete e.allowed_vector_store_ids),e.allowed_mcp_servers_and_groups&&((null===(l=e.allowed_mcp_servers_and_groups.servers)||void 0===l?void 0:l.length)>0&&(e.object_permission.mcp_servers=e.allowed_mcp_servers_and_groups.servers),(null===(r=e.allowed_mcp_servers_and_groups.accessGroups)||void 0===r?void 0:r.length)>0&&(e.object_permission.mcp_access_groups=e.allowed_mcp_servers_and_groups.accessGroups),delete e.allowed_mcp_servers_and_groups)),await (0,j.organizationCreateCall)(a,e),eo.Z.success("Organization created successfully"),S(!1),C.resetFields(),lU(a,m)}catch(e){console.error("Error creating organization:",e)}};return u?(0,c.jsxs)("div",{className:"w-full mx-4 h-[75vh]",children:[(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(v.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[("Admin"===t||"Org Admin"===t)&&(0,c.jsx)(b.Z,{className:"w-fit",onClick:()=>S(!0),children:"+ Create New Organization"}),x?(0,c.jsx)(lz,{organizationId:x,onClose:()=>{h(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===t,userModels:l,editOrg:p}):(0,c.jsxs)(e1.Z,{className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsx)("div",{className:"flex",children:(0,c.jsx)(e0.Z,{children:"Your Organizations"})}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",r]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:i})]})]}),(0,c.jsx)(e5.Z,{children:(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(k.Z,{children:"Click on “Organization ID” to view organization details."}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(G.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Organization ID"}),(0,c.jsx)(sI.Z,{children:"Organization Name"}),(0,c.jsx)(sI.Z,{children:"Created"}),(0,c.jsx)(sI.Z,{children:"Spend (USD)"}),(0,c.jsx)(sI.Z,{children:"Budget (USD)"}),(0,c.jsx)(sI.Z,{children:"Models"}),(0,c.jsx)(sI.Z,{children:"TPM / RPM Limits"}),(0,c.jsx)(sI.Z,{children:"Info"}),(0,c.jsx)(sI.Z,{children:"Actions"})]})}),(0,c.jsx)(sk.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,l,a,r,i,n,o,d,m;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.organization_id,children:(0,c.jsxs)(b.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:()=>h(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,c.jsx)(sS.Z,{children:e.organization_alias}),(0,c.jsx)(sS.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,c.jsx)(sS.Z,{children:eE(e.spend,4)}),(0,c.jsx)(sS.Z,{children:(null===(l=e.litellm_budget_table)||void 0===l?void 0:l.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,c.jsx)(sS.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},className:e.models.length>3?"px-0":"",children:(0,c.jsx)("div",{className:"flex flex-col",children:Array.isArray(e.models)?(0,c.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})}):(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)("div",{className:"flex items-start",children:[e.models.length>3&&(0,c.jsx)("div",{children:(0,c.jsx)(sZ.Z,{icon:T[e.organization_id||""]?sL.Z:sT.Z,className:"cursor-pointer",size:"xs",onClick:()=>{P(s=>({...s,[e.organization_id||""]:!s[e.organization_id||""]}))}})}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.models.slice(0,3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s)),e.models.length>3&&!T[e.organization_id||""]&&(0,c.jsx)(eX.Z,{size:"xs",color:"gray",className:"cursor-pointer",children:(0,c.jsxs)(k.Z,{children:["+",e.models.length-3," ",e.models.length-3==1?"more model":"more models"]})}),T[e.organization_id||""]&&(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:e.models.slice(3).map((e,s)=>"all-proxy-models"===e?(0,c.jsx)(eX.Z,{size:"xs",color:"red",children:(0,c.jsx)(k.Z,{children:"All Proxy Models"})},s+3):(0,c.jsx)(eX.Z,{size:"xs",color:"blue",children:(0,c.jsx)(k.Z,{children:e.length>30?"".concat(F(e).slice(0,30),"..."):F(e)})},s+3))})]})]})})}):null})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:["TPM:"," ",(null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit)?null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit:"Unlimited",(0,c.jsx)("br",{}),"RPM:"," ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(k.Z,{children:[(null===(m=e.members)||void 0===m?void 0:m.length)||0," Members"]})}),(0,c.jsx)(sS.Z,{children:"Admin"===t&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{h(e.organization_id),g(!0)}}),(0,c.jsx)(sZ.Z,{onClick:()=>M(e.organization_id),icon:W.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})})})]})})]})]})}),(0,c.jsx)(L.Z,{title:"Create Organization",visible:w,width:800,footer:null,onCancel:()=>{S(!1),C.resetFields()},children:(0,c.jsxs)(A.Z,{form:C,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,c.jsx)(sW.o,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Models",name:"models",children:(0,c.jsxs)(I.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,c.jsx)(I.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),l&&l.length>0&&l.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))]})}),(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(O,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})}),(0,c.jsx)(A.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,c.jsx)(O,{step:1,width:400})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Vector Stores"," ",(0,c.jsx)(V.Z,{title:"Select which vector stores this organization can access by default. Leave empty for access to all vector stores",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_vector_store_ids",className:"mt-4",help:"Select vector stores this organization can access. Leave empty for access to all vector stores",children:(0,c.jsx)(U,{onChange:e=>C.setFieldValue("allowed_vector_store_ids",e),value:C.getFieldValue("allowed_vector_store_ids"),accessToken:a||"",placeholder:"Select vector stores (optional)"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed MCP Servers"," ",(0,c.jsx)(V.Z,{title:"Select which MCP servers and access groups this organization can access by default.",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_mcp_servers_and_groups",className:"mt-4",help:"Select MCP servers and access groups this organization can access.",children:(0,c.jsx)(eO,{onChange:e=>C.setFieldValue("allowed_mcp_servers_and_groups",e),value:C.getFieldValue("allowed_mcp_servers_and_groups"),accessToken:a||"",placeholder:"Select MCP servers and access groups (optional)"})}),(0,c.jsx)(A.Z.Item,{label:"Metadata",name:"metadata",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(b.Z,{type:"submit",children:"Create Organization"})})]})}),f?(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{_(!1),Z(null)},children:"Cancel"})]})]})]})}):(0,c.jsx)(c.Fragment,{})]}):(0,c.jsx)("div",{children:(0,c.jsxs)(k.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key"," ",(0,c.jsx)("a",{href:"https://www.litellm.ai/#pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lB=t(94789);let lV={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:""},lK={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 lG=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:t,handleAddSSOOk:l,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:i,handleInstructionsCancel:n,form:o,accessToken:m,ssoConfigured:u=!1}=e,[x,h]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(s&&m)try{let s=await (0,j.getSSOSettings)(m);if(console.log("Raw SSO data received:",s),s&&s.values){console.log("SSO values:",s.values),console.log("user_email from API:",s.values.user_email);let l=null;if(s.values.google_client_id)l="google";else if(s.values.microsoft_client_id)l="microsoft";else if(s.values.generic_client_id){var e,t;l=(null===(e=s.values.generic_authorization_endpoint)||void 0===e?void 0:e.includes("okta"))||(null===(t=s.values.generic_authorization_endpoint)||void 0===t?void 0:t.includes("auth0"))?"okta":"generic"}let a={sso_provider:l,proxy_base_url:s.values.proxy_base_url,user_email:s.values.user_email,...s.values};console.log("Setting form values:",a),o.resetFields(),setTimeout(()=>{o.setFieldsValue(a),console.log("Form values set, current form values:",o.getFieldsValue())},100)}}catch(e){console.error("Failed to load SSO settings:",e)}})()},[s,m,o]);let p=async e=>{if(!m){eo.Z.fromBackend("No access token available");return}try{await (0,j.updateSSOSettings)(m,e),r(e)}catch(e){console.error("Failed to save SSO settings:",e),eo.Z.fromBackend("Failed to save SSO settings")}},g=async()=>{if(!m){eo.Z.fromBackend("No access token available");return}try{await (0,j.updateSSOSettings)(m,{google_client_id:"",google_client_secret:"",microsoft_client_id:"",microsoft_client_secret:"",microsoft_tenant:"",generic_client_id:"",generic_client_secret:"",generic_authorization_endpoint:"",generic_token_endpoint:"",generic_userinfo_endpoint:"",proxy_base_url:"",user_email:"",sso_provider:""}),o.resetFields(),h(!1),l(),eo.Z.success("SSO settings cleared successfully")}catch(e){console.error("Failed to clear SSO settings:",e),eo.Z.fromBackend("Failed to clear SSO settings")}},f=e=>{let s=lK[e];return s?s.fields.map(e=>(0,c.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,c.jsx)(E.default.Password,{}):(0,c.jsx)(_.Z,{placeholder:e.placeholder})},e.name)):null};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(L.Z,{title:u?"Edit SSO Settings":"Add SSO",visible:s,width:800,footer:null,onOk:l,onCancel:a,children:(0,c.jsxs)(A.Z,{form:o,onFinish:p,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,c.jsx)(I.default,{children:Object.entries(lV).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:s,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[t&&(0,c.jsx)("img",{src:t,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,c.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,t=s("sso_provider");return t?f(t):null}}),(0,c.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,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,c.jsx)(_.Z,{})})]}),(0,c.jsxs)("div",{style:{textAlign:"right",marginTop:"10px",display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"8px"},children:[u&&(0,c.jsx)(P.ZP,{onClick:()=>h(!0),style:{backgroundColor:"#6366f1",borderColor:"#6366f1",color:"white"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#5558eb",e.currentTarget.style.borderColor="#5558eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#6366f1",e.currentTarget.style.borderColor="#6366f1"},children:"Clear"}),(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})]})]})}),(0,c.jsxs)(L.Z,{title:"Confirm Clear SSO Settings",visible:x,onOk:g,onCancel:()=>h(!1),okText:"Yes, Clear",cancelText:"Cancel",okButtonProps:{danger:!0,style:{backgroundColor:"#dc2626",borderColor:"#dc2626"}},children:[(0,c.jsx)("p",{children:"Are you sure you want to clear all SSO settings? This action cannot be undone."}),(0,c.jsx)("p",{children:"Users will no longer be able to login using SSO after this change."})]}),(0,c.jsxs)(L.Z,{title:"SSO Setup Instructions",visible:t,width:800,footer:null,onOk:i,onCancel:n,children:[(0,c.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,c.jsx)(k.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{onClick:i,children:"Done"})})]})]})},lH=t(62272),lJ=t(92403),lY=t(29271),lW=t(34419),l$=e=>{let{accessToken:s,userID:t,proxySettings:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)("");(0,d.useEffect)(()=>{let e="";u(l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL?l.PROXY_BASE_URL:window.location.origin)},[l]);let x="".concat(m,"/scim/v2"),h=async e=>{if(!s||!t){eo.Z.fromBackend("You need to be logged in to create a SCIM token");return}try{i(!0);let l={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,j.keyCreateCall)(s,t,l);o(a),eo.Z.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),eo.Z.fromBackend("Failed to create SCIM token: "+(0,sx.O)(e))}finally{i(!1)}};return(0,c.jsx)(y.Z,{numItems:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("div",{className:"flex items-center mb-4",children:(0,c.jsx)(S.Z,{children:"SCIM Configuration"})}),(0,c.jsx)(k.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,c.jsx)(lC.Z,{}),(0,c.jsxs)("div",{className:"space-y-8",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,c.jsxs)(S.Z,{className:"text-lg flex items-center",children:[(0,c.jsx)(lH.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,c.jsx)(k.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(_.Z,{value:x,disabled:!0,className:"flex-grow"}),(0,c.jsx)(C.CopyToClipboard,{text:x,onCopy:()=>eo.Z.success("URL copied to clipboard"),children:(0,c.jsxs)(b.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,c.jsx)(tR.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,c.jsxs)(S.Z,{className:"text-lg flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,c.jsx)(lB.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),n?(0,c.jsxs)(G.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,c.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,c.jsx)(lY.Z,{className:"h-5 w-5 mr-2"}),(0,c.jsx)(S.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,c.jsx)(k.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(_.Z,{value:n.key,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,c.jsx)(C.CopyToClipboard,{text:n.key,onCopy:()=>eo.Z.success("Token copied to clipboard"),children:(0,c.jsxs)(b.Z,{variant:"primary",className:"flex items-center",children:[(0,c.jsx)(tR.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,c.jsxs)(b.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,c.jsx)(lW.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,c.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,c.jsxs)(A.Z,{form:a,onFinish:h,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,c.jsx)(_.Z,{placeholder:"SCIM Access Token"})}),(0,c.jsx)(A.Z.Item,{children:(0,c.jsxs)(b.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lQ=e=>{let{accessToken:s,onSuccess:t}=e,[l]=A.Z.useForm(),[a,r]=(0,d.useState)(!1);(0,d.useEffect)(()=>{(async()=>{if(s)try{let e=await (0,j.getSSOSettings)(s);if(e&&e.values){let s=e.values.ui_access_mode,t={};s&&"object"==typeof s?t={ui_access_mode_type:s.type,restricted_sso_group:s.restricted_sso_group,sso_group_jwt_field:s.sso_group_jwt_field}:"string"==typeof s&&(t={ui_access_mode_type:s,restricted_sso_group:e.values.restricted_sso_group,sso_group_jwt_field:e.values.team_ids_jwt_field||e.values.sso_group_jwt_field}),l.setFieldsValue(t)}}catch(e){console.error("Failed to load UI access settings:",e)}})()},[s,l]);let i=async e=>{if(!s){eo.Z.fromBackend("No access token available");return}r(!0);try{let l;l="all_authenticated_users"===e.ui_access_mode_type?{ui_access_mode:"none"}:{ui_access_mode:{type:e.ui_access_mode_type,restricted_sso_group:e.restricted_sso_group,sso_group_jwt_field:e.sso_group_jwt_field}},await (0,j.updateSSOSettings)(s,l),t()}catch(e){console.error("Failed to save UI access settings:",e),eo.Z.fromBackend("Failed to save UI access settings")}finally{r(!1)}};return(0,c.jsxs)("div",{style:{padding:"16px"},children:[(0,c.jsx)("div",{style:{marginBottom:"16px"},children:(0,c.jsx)(k.Z,{style:{fontSize:"14px",color:"#6b7280"},children:"Configure who can access the UI interface and how group information is extracted from JWT tokens."})}),(0,c.jsxs)(A.Z,{form:l,onFinish:i,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"UI Access Mode",name:"ui_access_mode_type",tooltip:"Controls who can access the UI interface",children:(0,c.jsxs)(I.default,{placeholder:"Select access mode",children:[(0,c.jsx)(I.default.Option,{value:"all_authenticated_users",children:"All Authenticated Users"}),(0,c.jsx)(I.default.Option,{value:"restricted_sso_group",children:"Restricted SSO Group"})]})}),(0,c.jsx)(A.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.ui_access_mode_type!==s.ui_access_mode_type,children:e=>{let{getFieldValue:s}=e;return"restricted_sso_group"===s("ui_access_mode_type")?(0,c.jsx)(A.Z.Item,{label:"Restricted SSO Group",name:"restricted_sso_group",rules:[{required:!0,message:"Please enter the restricted SSO group"}],children:(0,c.jsx)(_.Z,{placeholder:"ui-access-group"})}):null}}),(0,c.jsx)(A.Z.Item,{label:"SSO Group JWT Field",name:"sso_group_jwt_field",tooltip:"JWT field name that contains team/group information. Use dot notation to access nested fields.",children:(0,c.jsx)(_.Z,{placeholder:"groups"})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"16px"},children:(0,c.jsx)(P.ZP,{type:"primary",htmlType:"submit",loading:a,style:{backgroundColor:"#6366f1",borderColor:"#6366f1"},children:"Update UI Access Control"})})]})]})},lX=t(69870),l0=e=>{let{searchParams:s,accessToken:t,userID:l,showSSOBanner:a,premiumUser:r,proxySettings:i,userRole:n}=e,[o]=A.Z.useForm(),[u]=A.Z.useForm(),{Title:x,Paragraph:h}=en.default,[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(null),[y,_]=(0,d.useState)(null),[N,Z]=(0,d.useState)(!1),[w,k]=(0,d.useState)(!1),[S,C]=(0,d.useState)(!1),[I,T]=(0,d.useState)(!1),[M,O]=(0,d.useState)(!1),[D,F]=(0,d.useState)(!1),[R,z]=(0,d.useState)(!1),[U,q]=(0,d.useState)(!1),[B,V]=(0,d.useState)(!1),[K,H]=(0,d.useState)(!1),[J,Y]=(0,d.useState)([]),[W,$]=(0,d.useState)(null),[Q,X]=(0,d.useState)(!1);(0,m.useRouter)();let[ee,es]=(0,d.useState)(null);console.log=function(){};let et=sb(),el="All IP Addresses Allowed",ea=et;ea+="/fallback/login";let er=async()=>{if(t&&r)try{let e=await (0,j.getSSOSettings)(t);if(console.log("SSO data:",e),e&&e.values){let s=e.values.google_client_id&&e.values.google_client_secret,t=e.values.microsoft_client_id&&e.values.microsoft_client_secret,l=e.values.generic_client_id&&e.values.generic_client_secret;X(s||t||l)}else X(!1)}catch(e){console.error("Error checking SSO configuration:",e),X(!1)}},ei=async()=>{try{if(!0!==r){eo.Z.fromBackend("This feature is only available for premium users. Please upgrade your account.");return}if(t){let e=await (0,j.getAllowedIPs)(t);Y(e&&e.length>0?e:[el])}else Y([el])}catch(e){console.error("Error fetching allowed IPs:",e),eo.Z.fromBackend("Failed to fetch allowed IPs ".concat(e)),Y([el])}finally{!0===r&&z(!0)}},ec=async e=>{try{if(t){await (0,j.addAllowedIP)(t,e.ip);let s=await (0,j.getAllowedIPs)(t);Y(s),eo.Z.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),eo.Z.fromBackend("Failed to add IP address ".concat(e))}finally{q(!1)}},ed=async e=>{$(e),V(!0)},em=async()=>{if(W&&t)try{await (0,j.deleteAllowedIP)(t,W);let e=await (0,j.getAllowedIPs)(t);Y(e.length>0?e:[el]),eo.Z.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),eo.Z.fromBackend("Failed to delete IP address ".concat(e))}finally{V(!1),$(null)}};(0,d.useEffect)(()=>{(async()=>{if(null!=t){let e=[],s=await (0,j.userGetAllUsersCall)(t,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let l=s.users;console.log("proxy viewers response: ".concat(l)),l.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(l));let a=(await (0,j.userGetAllUsersCall)(t,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),v(e),es(await (0,j.getPossibleUserRoles)(t))}})()},[t]),(0,d.useEffect)(()=>{er()},[t,r]);let eu=()=>{H(!1)};return console.log("admins: ".concat(null==f?void 0:f.length)),(0,c.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,c.jsx)(x,{level:4,children:"Admin Access "}),(0,c.jsx)(h,{children:"Go to 'Internal Users' page to add other admins."}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Security Settings"}),(0,c.jsx)(e0.Z,{children:"SCIM"}),(0,c.jsx)(e0.Z,{children:"Useful Links"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(x,{level:4,children:" ✨ Security Settings"}),(0,c.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem",marginLeft:"0.5rem"},children:[(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:()=>!0===r?O(!0):eo.Z.fromBackend("Only premium users can add SSO"),children:Q?"Edit SSO Settings":"Add SSO"})}),(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:ei,children:"Allowed IPs"})}),(0,c.jsx)("div",{children:(0,c.jsx)(b.Z,{style:{width:"150px"},onClick:()=>!0===r?H(!0):eo.Z.fromBackend("Only premium users can configure UI access control"),children:"UI Access Control"})})]})]}),(0,c.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,c.jsx)(lG,{isAddSSOModalVisible:M,isInstructionsModalVisible:D,handleAddSSOOk:()=>{O(!1),o.resetFields(),t&&r&&er()},handleAddSSOCancel:()=>{O(!1),o.resetFields()},handleShowInstructions:e=>{O(!1),F(!0)},handleInstructionsOk:()=>{F(!1),t&&r&&er()},handleInstructionsCancel:()=>{F(!1),t&&r&&er()},form:o,accessToken:t,ssoConfigured:Q}),(0,c.jsx)(L.Z,{title:"Manage Allowed IP Addresses",width:800,visible:R,onCancel:()=>z(!1),footer:[(0,c.jsx)(b.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,c.jsx)(b.Z,{onClick:()=>z(!1),children:"Close"},"close")],children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"IP Address"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Action"})]})}),(0,c.jsx)(sk.Z,{children:J.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e}),(0,c.jsx)(sS.Z,{className:"text-right",children:e!==el&&(0,c.jsx)(b.Z,{onClick:()=>ed(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,c.jsx)(L.Z,{title:"Add Allowed IP Address",visible:U,onCancel:()=>q(!1),footer:null,children:(0,c.jsxs)(A.Z,{onFinish:ec,children:[(0,c.jsx)(A.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,c.jsx)(E.default,{placeholder:"Enter IP address"})}),(0,c.jsx)(A.Z.Item,{children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,c.jsx)(L.Z,{title:"Confirm Delete",visible:B,onCancel:()=>V(!1),onOk:em,footer:[(0,c.jsx)(b.Z,{className:"mx-1",onClick:()=>em(),children:"Yes"},"delete"),(0,c.jsx)(b.Z,{onClick:()=>V(!1),children:"Close"},"close")],children:(0,c.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",W,"?"]})}),(0,c.jsx)(L.Z,{title:"UI Access Control Settings",visible:K,width:600,footer:null,onOk:eu,onCancel:()=>{H(!1)},children:(0,c.jsx)(lQ,{accessToken:t,onSuccess:()=>{eu(),eo.Z.success("UI Access Control settings updated successfully")}})})]}),(0,c.jsxs)(lB.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,c.jsxs)("a",{href:ea,target:"_blank",children:[(0,c.jsx)("b",{children:ea})," "]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l$,{accessToken:t,userID:l,proxySettings:i})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(lX.Z,{accessToken:t,userRole:n||null})})]})]})]})};let{Title:l1}=en.default;var l2=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)([]);(0,d.useEffect)(()=>{i()},[s]);let i=async()=>{if(s){l(!0);try{let e=await (0,j.getEmailEventSettings)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),eo.Z.fromBackend(e)}finally{l(!1)}}},n=(e,s)=>{r(a.map(t=>t.event===e?{...t,enabled:s}:t))},o=async()=>{if(s)try{await (0,j.updateEmailEventSettings)(s,{settings:a}),eo.Z.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),eo.Z.fromBackend(e)}},m=async()=>{if(s)try{await (0,j.resetEmailEventSettings)(s),eo.Z.success("Email event settings reset to defaults"),i()}catch(e){console.error("Failed to reset email event settings:",e),eo.Z.fromBackend(e)}},u=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(l1,{level:4,children:"Email Notifications"}),(0,c.jsx)(k.Z,{children:"Select which events should trigger email notifications."}),(0,c.jsx)(K.Z,{}),t?(0,c.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,c.jsx)(lI.Z,{size:"large"})}):(0,c.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(ts.Z,{checked:e.enabled,onChange:s=>n(e.event,s.target.checked)}),(0,c.jsxs)("div",{className:"ml-3",children:[(0,c.jsx)(k.Z,{children:e.event}),(0,c.jsx)("div",{className:"text-sm text-gray-500 block",children:u(e.event)})]})]},e.event))}),(0,c.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,c.jsx)(b.Z,{onClick:o,disabled:t,children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:m,variant:"secondary",disabled:t,children:"Reset to Defaults"})]})]})};let{Title:l4}=en.default;var l5=e=>{let{accessToken:s,premiumUser:t,alerts:l}=e,a=async()=>{if(!s)return;let e={};l.filter(e=>"email"===e.name).forEach(s=>{var t;Object.entries(null!==(t=s.variables)&&void 0!==t?t:{}).forEach(s=>{let[t,l]=s,a=document.querySelector('input[name="'.concat(t,'"]'));a&&a.value&&(e[t]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{await (0,j.setCallbacksCall)(s,{general_settings:{alerting:["email"]},environment_variables:e}),eo.Z.success("Email settings updated successfully")}catch(e){eo.Z.fromBackend(e)}};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mt-6 mb-6",children:(0,c.jsx)(l2,{accessToken:s})}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(l4,{level:4,children:"Email Server Settings"}),(0,c.jsxs)(k.Z,{children:[(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,c.jsx)("br",{})]}),(0,c.jsx)("div",{className:"flex w-full",children:l.filter(e=>"email"===e.name).map((e,s)=>{var l;return(0,c.jsx)(sS.Z,{children:(0,c.jsx)("ul",{children:(0,c.jsx)(y.Z,{numItems:2,children:Object.entries(null!==(l=e.variables)&&void 0!==l?l:{}).map(e=>{let[s,l]=e;return(0,c.jsxs)("li",{className:"mx-2 my-2",children:[!0!=t&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,c.jsxs)("div",{children:[(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,c.jsxs)(k.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,c.jsx)(_.Z,{name:s,defaultValue:l,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"mt-2",children:s}),(0,c.jsx)(_.Z,{name:s,defaultValue:l,type:"password",style:{width:"400px"}})]}),(0,c.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,c.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,c.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,c.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,c.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,c.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:async()=>{if(s)try{await (0,j.serviceHealthCheck)(s,"email"),eo.Z.success("Email test triggered. Check your configured email inbox/logs.")}catch(e){eo.Z.fromBackend(e)}},className:"mx-2",children:"Test Email Alerts"})]})]})},l6=e=>{let{alertingSettings:s,handleInputChange:t,handleResetField:l,handleSubmit:a,premiumUser:r}=e,[i]=A.Z.useForm();return(0,c.jsxs)(A.Z,{form:i,onFinish:()=>{console.log("INSIDE ONFINISH");let e=i.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,t]=e;return"boolean"!=typeof t&&(""===t||null==t)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{align:"center",children:[(0,c.jsx)(k.Z,{children:e.field_name}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,c.jsx)(A.Z.Item,{name:e.field_name,children:(0,c.jsx)(sS.Z,{children:"Integer"===e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>t(e.field_name,s)}):"Boolean"===e.field_type?(0,c.jsx)(tB.Z,{checked:e.field_value,onChange:s=>t(e.field_name,s)}):(0,c.jsx)(E.default,{value:e.field_value,onChange:s=>t(e.field_name,s)})})}):(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{className:"flex items-center justify-center",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,c.jsx)(A.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,c.jsx)(sS.Z,{children:"Integer"===e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>t(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,c.jsx)(tB.Z,{checked:e.field_value,onChange:s=>{t(e.field_name,s),i.setFieldsValue({[e.field_name]:s})}}):(0,c.jsx)(E.default,{value:e.field_value,onChange:s=>t(e.field_name,s)})})}),(0,c.jsx)(sS.Z,{children:!0==e.stored_in_db?(0,c.jsx)(eX.Z,{icon:eb.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(sZ.Z,{icon:W.Z,color:"red",onClick:()=>l(e.field_name,s),children:"Reset"})})]},s)),(0,c.jsx)("div",{children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l3=e=>{let{accessToken:s,premiumUser:t}=e,[l,a]=(0,d.useState)([]);return(0,d.useEffect)(()=>{s&&(0,j.alertingSettingsCall)(s).then(e=>{a(e)})},[s]),(0,c.jsx)(l6,{alertingSettings:l,handleInputChange:(e,s)=>{let t=l.map(t=>t.field_name===e?{...t,field_value:s}:t);console.log("updatedSettings: ".concat(JSON.stringify(t))),a(t)},handleResetField:(e,t)=>{if(s)try{let s=l.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let t={};l.forEach(e=>{t[e.field_name]=e.field_value});let a={...e,...t};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.updateConfigFieldSetting)(s,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,j.updateConfigFieldSetting)(s,"alerting",["slack"]):(0,j.updateConfigFieldSetting)(s,"alerting",[])),eo.Z.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:t})},l8=t(38994);let{Title:l7,Paragraph:l9}=en.default;var ae=e=>{let{accessToken:s,userRole:t,userID:l,premiumUser:a}=e,[r,n]=(0,d.useState)([]),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(!1),[h]=A.Z.useForm(),[p]=A.Z.useForm(),[g,f]=(0,d.useState)(null),[v,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)({}),[S,C]=(0,d.useState)([]),[T,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)([]),[F,R]=(0,d.useState)([]),[z,U]=(0,d.useState)(!1),[q,B]=(0,d.useState)(null),[V,K]=(0,d.useState)(!1),[H,J]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(z&&q){let e=Object.fromEntries(Object.entries(q.variables||{}).map(e=>{let[s,t]=e;return[s,null!=t?t:""]}));p.setFieldsValue(e)}},[z,q,p]);let Y=e=>{S.includes(e)?C(S.filter(s=>s!==e)):C([...S,e])},Q={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,d.useEffect)(()=>{s&&t&&l&&(0,j.getCallbacksCall)(s,l,t).then(e=>{n(e.callbacks),D(e.available_callbacks);let s=e.alerts;if(s&&s.length>0){let e=s[0],t=e.variables.SLACK_WEBHOOK_URL;C(e.active_alerts),N(t),w(e.alerts_to_webhook)}m(s)})},[s,t,l]);let X=e=>S&&S.includes(e),ee=async e=>{if(!s||!q)return;let a={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(a[s]=t)});let r={environment_variables:e,litellm_settings:{success_callback:[q.name]}};try{if(await (0,j.setCallbacksCall)(s,r),eo.Z.success("Callback updated successfully"),U(!1),p.resetFields(),B(null),l&&t){let e=await (0,j.getCallbacksCall)(s,l,t);n(e.callbacks)}}catch(e){eo.Z.fromBackend(e)}},es=async e=>{if(!s)return;let a=null==e?void 0:e.callback,r={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(r[s]=t)});try{await (0,j.setCallbacksCall)(s,{environment_variables:e,litellm_settings:{success_callback:[a]}}),eo.Z.success("Callback ".concat(a," added successfully")),M(!1),h.resetFields(),f(null),R([]);let r=await (0,j.getCallbacksCall)(s,l||"",t||"");n(r.callbacks)}catch(e){eo.Z.fromBackend(e)}},el=e=>{f(e.litellm_callback_name),e&&e.litellm_callback_params?R(e.litellm_callback_params):R([])},ea=async()=>{if(!s)return;let e={};Object.entries(Q).forEach(s=>{let[t,l]=s,a=document.querySelector('input[name="'.concat(t,'"]')),r=(null==a?void 0:a.value)||"";e[t]=r});try{await (0,j.setCallbacksCall)(s,{general_settings:{alert_to_webhook_url:e,alert_types:S}})}catch(e){eo.Z.fromBackend(e)}eo.Z.success("Alerts updated successfully")},er=e=>{J(e),K(!0)},en=async()=>{if(H&&s)try{if(await (0,j.deleteCallback)(s,H),eo.Z.success("Callback ".concat(H," deleted successfully")),l&&t){let e=await (0,j.getCallbacksCall)(s,l,t);n(e.callbacks)}K(!1),J(null)}catch(e){console.error("Failed to delete callback:",e),eo.Z.fromBackend(e)}};return s?(0,c.jsxs)("div",{className:"w-full mx-4",children:[(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Logging Callbacks"}),(0,c.jsx)(e0.Z,{value:"2",children:"Alerting Types"}),(0,c.jsx)(e0.Z,{value:"3",children:"Alerting Settings"}),(0,c.jsx)(e0.Z,{value:"4",children:"Email Alerts"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(l7,{level:4,children:"Active Logging Callbacks"}),(0,c.jsx)(y.Z,{numItems:2,children:(0,c.jsx)(G.Z,{className:"max-h-[50vh]",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sI.Z,{children:"Callback Name"})})}),(0,c.jsx)(sk.Z,{children:r.map((e,t)=>(0,c.jsxs)(sA.Z,{className:"flex justify-between",children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.name})}),(0,c.jsx)(sS.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"flex justify-between",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>{B(e),U(!0)}}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>er(e.name),className:"text-red-500 hover:text-red-700 cursor-pointer"}),(0,c.jsx)(b.Z,{onClick:async()=>{try{await (0,j.serviceHealthCheck)(s,e.name),eo.Z.success("Health check triggered")}catch(e){eo.Z.fromBackend((0,sx.O)(e))}},className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},t))})]})})}),(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>M(!0),children:"Add Callback"})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(k.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,c.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{}),(0,c.jsx)(sI.Z,{}),(0,c.jsx)(sI.Z,{children:"Slack Webhook URL"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(Q).map((e,s)=>{let[t,l]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:"region_outage_alerts"==t?a?(0,c.jsx)(tB.Z,{id:"switch",name:"switch",checked:X(t),onChange:()=>Y(t)}):(0,c.jsx)(b.Z,{className:"flex items-center justify-center",children:(0,c.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,c.jsx)(tB.Z,{id:"switch",name:"switch",checked:X(t),onChange:()=>Y(t)})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:l})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(_.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:v})})]},s)})})]}),(0,c.jsx)(b.Z,{size:"xs",className:"mt-2",onClick:ea,children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:async()=>{try{await (0,j.serviceHealthCheck)(s,"slack"),eo.Z.success("Alert test triggered. Test request to slack made - check logs/alerts on slack to verify")}catch(e){eo.Z.fromBackend((0,sx.O)(e))}},className:"mx-2",children:"Test Alerts"})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l3,{accessToken:s,premiumUser:a})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(l5,{accessToken:s,premiumUser:a,alerts:o})})]})]})}),(0,c.jsxs)(L.Z,{title:"Add Logging Callback",visible:T,width:800,onCancel:()=>{M(!1),f(null),R([])},footer:null,children:[(0,c.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:[" ","LiteLLM Docs: Logging"]}),(0,c.jsx)(A.Z,{form:h,onFinish:es,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(l8.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,c.jsx)(I.default,{onChange:e=>{let s=O[e];s&&el(s)},children:Object.entries(i).map(e=>{var s;let[t,l]=e;return(0,c.jsx)(ei.Z,{value:$[t],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(null===(s=et[l])||void 0===s?void 0:s.logo)?(0,c.jsx)("div",{className:"w-5 h-5 flex items-center justify-center",children:(0,c.jsx)("img",{src:et[l].logo,alt:"".concat(t," logo"),className:"w-5 h-5",onError:e=>{e.currentTarget.style.display="none"}})}):(0,c.jsx)("div",{className:"w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",children:l.charAt(0).toUpperCase()}),(0,c.jsx)("span",{children:l})]})},l)})})}),F&&F.map(e=>(0,c.jsx)(l8.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,c.jsx)(E.default.Password,{})},e)),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,c.jsx)(L.Z,{visible:z,width:800,title:"Edit ".concat(null==q?void 0:q.name," Settings"),onCancel:()=>{U(!1),B(null)},footer:null,children:(0,c.jsxs)(A.Z,{form:p,onFinish:ee,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(c.Fragment,{children:q&&q.variables&&Object.entries(q.variables).map(e=>{let[s]=e;return(0,c.jsx)(l8.Z,{label:s,name:s,rules:[{required:!0,message:"Please enter the value for ".concat(s)}],children:(0,c.jsx)(E.default.Password,{})},s)})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,c.jsx)(L.Z,{title:"Confirm Delete",visible:V,onOk:en,onCancel:()=>{K(!1),J(null)},okText:"Delete",cancelText:"Cancel",okButtonProps:{danger:!0},children:(0,c.jsxs)("p",{children:["Are you sure you want to delete the callback - ",H,"? This action cannot be undone."]})})]}):null},as=t(54250),at=t(70450),al=e=>{let{models:s,accessToken:t,routerSettings:l,setRouterSettings:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(""),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]);(0,d.useEffect)(()=>{(async()=>{try{let e=await eU(t);console.log("Fetched models for fallbacks:",e),x(e)}catch(e){console.error("Error fetching model info for fallbacks:",e)}})()},[t]);let g=()=>{n(!1),r.resetFields(),p([]),m("")};return(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{className:"mx-auto",onClick:()=>n(!0),icon:()=>(0,c.jsx)("span",{className:"mr-1",children:"+"}),children:"Add Fallbacks"}),(0,c.jsx)(L.Z,{title:(0,c.jsx)("div",{className:"pb-4 border-b border-gray-100",children:(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Fallbacks"})}),open:i,width:900,footer:null,onOk:()=>{n(!1),r.resetFields(),p([]),m("")},onCancel:g,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsxs)("div",{className:"mt-6",children:[(0,c.jsx)("div",{className:"mb-6",children:(0,c.jsx)("p",{className:"text-gray-600",children:"Configure fallback models to improve reliability. When the primary model fails or is unavailable, requests will automatically route to the specified fallback models in order."})}),(0,c.jsxs)(A.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:i}=e,o=[...l.fallbacks||[],{[s]:i}],c={...l,fallbacks:o};console.log(c);try{(0,j.setCallbacksCall)(t,{router_settings:c}),a(c)}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}eo.Z.success("router settings updated successfully"),n(!1),r.resetFields(),p([]),m("")},layout:"vertical",className:"space-y-6",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Primary Model ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"model_name",rules:[{required:!0,message:"Please select the primary model that needs fallbacks"}],className:"!mb-0",children:[(0,c.jsx)(as.Z,{placeholder:"Select the model that needs fallback protection",value:o,onValueChange:e=>{m(e);let s=h.filter(s=>s!==e);p(s),r.setFieldValue("models",s),r.setFieldValue("model_name",e)},children:Array.from(new Set(u.map(e=>e.model_group))).map((e,s)=>(0,c.jsx)(at.Z,{value:e,children:e},s))}),(0,c.jsx)("p",{className:"text-sm text-gray-500 mt-1",children:"This is the primary model that users will request"})]}),(0,c.jsx)("div",{className:"border-t border-gray-200 my-6"}),(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Fallback Models (select multiple) ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"models",rules:[{required:!0,message:"Please select at least one fallback model"}],className:"!mb-0",children:[(0,c.jsxs)("div",{className:"space-y-3",children:[h.length>0&&(0,c.jsxs)("div",{className:"border border-gray-200 rounded-lg p-3 bg-gray-50",children:[(0,c.jsx)("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Fallback Order:"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:h.map((e,s)=>(0,c.jsxs)("div",{className:"flex items-center bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm",children:[(0,c.jsxs)("span",{className:"font-medium mr-2",children:[s+1,"."]}),(0,c.jsx)("span",{children:e}),(0,c.jsx)("button",{type:"button",onClick:()=>{let s=h.filter(s=>s!==e);p(s),r.setFieldValue("models",s)},className:"ml-2 text-blue-600 hover:text-blue-800",children:"\xd7"})]},e))})]}),(0,c.jsx)(as.Z,{placeholder:"Add a fallback model",value:"",onValueChange:e=>{if(e&&!h.includes(e)){let s=[...h,e];p(s),r.setFieldValue("models",s)}},children:Array.from(new Set(u.map(e=>e.model_group))).filter(e=>e!==o&&!h.includes(e)).sort().map(e=>(0,c.jsx)(at.Z,{value:e,children:e},e))})]}),(0,c.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:[(0,c.jsx)("strong",{children:"Order matters:"})," Models will be tried in the order shown above (1st, 2nd, 3rd, etc.)"]})]})]}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:g,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",type:"submit",children:"Add Fallbacks"})]})]})]})})]})},aa=t(26433);async function ar(e,s){console.log=function(){},console.log("isLocal:",!1);let t=window.location.origin,l=new aa.ZP.OpenAI({apiKey:s,baseURL:t,dangerouslyAllowBrowser:!0});try{let s=await l.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});eo.Z.success((0,c.jsxs)("span",{children:["Test model=",(0,c.jsx)("strong",{children:e}),", received model=",(0,c.jsx)("strong",{children:s.model}),". See"," ",(0,c.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e))}}let ai={ttl:3600,lowest_latency_buffer:0},an=e=>{let{selectedStrategy:s,strategyArgs:t,paramExplanation:l}=e;return(0,c.jsxs)(N.Z,{children:[(0,c.jsx)(w.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,c.jsx)(Z.Z,{children:"latency-based-routing"==s?(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(t).map(e=>{let[s,t]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:s}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:l[s]})]}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(_.Z,{name:s,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},s)})})]})}):(0,c.jsx)(k.Z,{children:"No specific settings"})})]})};var ao=e=>{let{accessToken:s,userRole:t,userID:l,modelData:a}=e,[r,i]=(0,d.useState)({}),[n,o]=(0,d.useState)({}),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p]=A.Z.useForm(),[g,f]=(0,d.useState)(null),[N,Z]=(0,d.useState)(null),[w,C]=(0,d.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,d.useEffect)(()=>{s&&t&&l&&((0,j.getCallbacksCall)(s,l,t).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,i(s)}),(0,j.getGeneralSettingsCall)(s).then(e=>{u(e)}))},[s,t,l]);let L=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let t=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),l={...r,fallbacks:t};try{await (0,j.setCallbacksCall)(s,{router_settings:l}),i(l),eo.Z.success("Router settings updated successfully")}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}},T=(e,s)=>{u(m.map(t=>t.field_name===e?{...t,field_value:s}:t))},P=(e,t)=>{if(!s)return;let l=m[t].field_value;if(null!=l&&void 0!=l)try{(0,j.updateConfigFieldSetting)(s,e,l);let t=m.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);u(t)}catch(e){}},E=(e,t)=>{if(s)try{(0,j.deleteConfigFieldSetting)(s,e);let t=m.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);u(t)}catch(e){}},M=e=>{if(!s)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[s,t]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var l;return[s,(null===(l=document.querySelector('input[name="'.concat(s,'"]')))||void 0===l?void 0:l.value)||t]}if("routing_strategy"==s)return[s,N];if("routing_strategy_args"==s&&"latency-based-routing"==N){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),t=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==t?void 0:t.value)&&(e.ttl=Number(t.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",t);try{(0,j.setCallbacksCall)(s,{router_settings:t})}catch(e){eo.Z.fromBackend("Failed to update router settings: "+e)}eo.Z.success("router settings updated successfully")};return s?(0,c.jsx)("div",{className:"w-full mx-4",children:(0,c.jsxs)(e1.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)(e2.Z,{variant:"line",defaultValue:"1",children:[(0,c.jsx)(e0.Z,{value:"1",children:"Loadbalancing"}),(0,c.jsx)(e0.Z,{value:"2",children:"Fallbacks"}),(0,c.jsx)(e0.Z,{value:"3",children:"General"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,c.jsx)(S.Z,{children:"Router Settings"}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"})]})}),(0,c.jsx)(sk.Z,{children:Object.entries(r).filter(e=>{let[s,t]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,t]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:s}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:I[s]})]}),(0,c.jsx)(sS.Z,{children:"routing_strategy"==s?(0,c.jsxs)(eQ.Z,{defaultValue:t,className:"w-full max-w-md",onValueChange:Z,children:[(0,c.jsx)(ei.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,c.jsx)(ei.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,c.jsx)(ei.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,c.jsx)(_.Z,{name:s,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},s)})})]}),(0,c.jsx)(an,{selectedStrategy:N,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:ai,paramExplanation:I})]}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(b.Z,{className:"mt-2",onClick:()=>M(r),children:"Save Changes"})})]})}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Model Name"}),(0,c.jsx)(sI.Z,{children:"Fallbacks"})]})}),(0,c.jsx)(sk.Z,{children:r.fallbacks&&r.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[l,a]=e;return(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:l}),(0,c.jsx)(sS.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(b.Z,{onClick:()=>ar(l,s),children:"Test Fallback"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>L(l)})})]},t.toString()+l)}))})]}),(0,c.jsx)(al,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:i})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Setting"}),(0,c.jsx)(sI.Z,{children:"Value"}),(0,c.jsx)(sI.Z,{children:"Status"}),(0,c.jsx)(sI.Z,{children:"Action"})]})}),(0,c.jsx)(sk.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(k.Z,{children:e.field_name}),(0,c.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,c.jsx)(sS.Z,{children:"Integer"==e.field_type?(0,c.jsx)(eW.Z,{step:1,value:e.field_value,onChange:s=>T(e.field_name,s)}):null}),(0,c.jsx)(sS.Z,{children:!0==e.stored_in_db?(0,c.jsx)(eX.Z,{icon:eb.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,c.jsx)(eX.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,c.jsxs)(sS.Z,{children:[(0,c.jsx)(b.Z,{onClick:()=>P(e.field_name,s),children:"Update"}),(0,c.jsx)(sZ.Z,{icon:W.Z,color:"red",onClick:()=>E(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ac=e=>{let{isModalVisible:s,accessToken:t,setIsModalVisible:l,setBudgetList:a}=e,[r]=A.Z.useForm(),i=async e=>{if(null!=t&&void 0!=t)try{eo.Z.info("Making API Call");let s=await (0,j.budgetCreateCall)(t,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),eo.Z.success("Budget Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};return(0,c.jsx)(L.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{l(!1),r.resetFields()},onCancel:()=>{l(!1),r.resetFields()},children:(0,c.jsxs)(A.Z,{form:r,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ad=e=>{let{isModalVisible:s,accessToken:t,setIsModalVisible:l,setBudgetList:a,existingBudget:r,handleUpdateCall:i}=e;console.log("existingBudget",r);let[n]=A.Z.useForm();(0,d.useEffect)(()=>{n.setFieldsValue(r)},[r,n]);let o=async e=>{if(null!=t&&void 0!=t)try{eo.Z.info("Making API Call"),l(!0);let s=await (0,j.budgetUpdateCall)(t,e);a(e=>e?[...e,s]:[s]),eo.Z.success("Budget Updated"),n.resetFields(),i()}catch(e){console.error("Error creating the key:",e),eo.Z.fromBackend("Error creating the key: ".concat(e))}};return(0,c.jsx)(L.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{l(!1),n.resetFields()},onCancel:()=>{l(!1),n.resetFields()},children:(0,c.jsxs)(A.Z,{form:n,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,c.jsxs)(c.Fragment,{children:[(0,c.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,c.jsx)(_.Z,{placeholder:""})}),(0,c.jsx)(A.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,c.jsx)(eW.Z,{step:1,precision:2,width:200})}),(0,c.jsxs)(N.Z,{className:"mt-20 mb-8",children:[(0,c.jsx)(w.Z,{children:(0,c.jsx)("b",{children:"Optional Settings"})}),(0,c.jsxs)(Z.Z,{children:[(0,c.jsx)(A.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,c.jsx)(eW.Z,{step:.01,precision:2,width:200})}),(0,c.jsx)(A.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,c.jsxs)(I.default,{defaultValue:null,placeholder:"n/a",children:[(0,c.jsx)(I.default.Option,{value:"24h",children:"daily"}),(0,c.jsx)(I.default.Option,{value:"7d",children:"weekly"}),(0,c.jsx)(I.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(P.ZP,{htmlType:"submit",children:"Save"})})]})})},am=t(17906),au=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)(!1),[a,r]=(0,d.useState)(!1),[i,n]=(0,d.useState)(null),[o,m]=(0,d.useState)([]);(0,d.useEffect)(()=>{s&&(0,j.getBudgetList)(s).then(e=>{m(e)})},[s]);let u=async(e,t)=>{console.log("budget_id",e),null!=s&&(n(o.find(s=>s.budget_id===e)||null),r(!0))},x=async(e,t)=>{if(null==s)return;eo.Z.info("Request made"),await (0,j.budgetDeleteCall)(s,e);let l=[...o];l.splice(t,1),m(l),eo.Z.success("Budget Deleted.")},h=async()=>{null!=s&&(0,j.getBudgetList)(s).then(e=>{m(e)})};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)(b.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>l(!0),children:"+ Create Budget"}),(0,c.jsx)(ac,{accessToken:s,isModalVisible:t,setIsModalVisible:l,setBudgetList:m}),i&&(0,c.jsx)(ad,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:m,existingBudget:i,handleUpdateCall:h}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Create a budget to assign to customers."}),(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Budget ID"}),(0,c.jsx)(sI.Z,{children:"Max Budget"}),(0,c.jsx)(sI.Z,{children:"TPM"}),(0,c.jsx)(sI.Z,{children:"RPM"})]})}),(0,c.jsx)(sk.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.budget_id}),(0,c.jsx)(sS.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,c.jsx)(sS.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,c.jsx)(sS.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>u(e.budget_id,s)}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>x(e.budget_id,s)})]},s))})]})]}),(0,c.jsxs)("div",{className:"mt-5",children:[(0,c.jsx)(k.Z,{className:"text-base",children:"How to use budget id"}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Assign Budget to Customer"}),(0,c.jsx)(e0.Z,{children:"Test it (Curl)"}),(0,c.jsx)(e0.Z,{children:"Test it (OpenAI SDK)"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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)'})})]})]})]})]})},ax=t(77398),ah=t.n(ax);let ap=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"}},ag=e=>{let{utcTime:s}=e;return(0,c.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:ap(s)})},aj=(e,s)=>{var t,l;return(null===(l=e.metadata)||void 0===l?void 0:null===(t=l.mcp_tool_call_metadata)||void 0===t?void 0:t.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?(0,sU.dr)(s).logo:""},af=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,c.jsx)(()=>{let[e,t]=d.useState(s.getIsExpanded()),l=d.useCallback(()=>{t(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,c.jsx)("button",{onClick:l,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,c.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,c.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,c.jsx)(ag,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),t=e.row.original.onSessionClick;return(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==t?void 0:t(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,c.jsxs)("span",{children:["$",eE(e.getValue()||0,6)]})},{header:"Duration (s)",accessorKey:"duration",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),t=e.row.original.onKeyHashClick;return(0,c.jsx)(V.Z,{title:s,children:(0,c.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==t?void 0:t(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,t=s.custom_llm_provider,l=String(e.getValue()||"");return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,c.jsx)("img",{src:aj(s,t),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)(V.Z,{title:l,children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:l})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,c.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,c.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||"-"),children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let t=Object.entries(s),l=t[0],a=t.slice(1);return(0,c.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,c.jsx)(V.Z,{title:(0,c.jsx)("div",{className:"flex flex-col gap-1",children:t.map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{children:[s,": ",String(t)]},s)})}),children:(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l[0],": ",String(l[1]),a.length>0&&" +".concat(a.length)]})})})}}],av=e=>(0,c.jsx)(eX.Z,{color:"gray",className:"flex items-center gap-1",children:(0,c.jsx)("span",{className:"whitespace-nowrap text-xs",children:e})}),ay=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,c.jsx)(()=>{let[e,t]=d.useState(s.getIsExpanded()),l=d.useCallback(()=>{t(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,c.jsx)("button",{onClick:l,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,c.jsx)("svg",{className:"w-4 h-4 transform transition-transform ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,c.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Timestamp",accessorKey:"updated_at",cell:e=>(0,c.jsx)(ag,{utcTime:e.getValue()})},{header:"Table Name",accessorKey:"table_name",cell:e=>{let s=e.getValue(),t=s;switch(s){case"LiteLLM_VerificationToken":t="Keys";break;case"LiteLLM_TeamTable":t="Teams";break;case"LiteLLM_OrganizationTable":t="Organizations";break;case"LiteLLM_UserTable":t="Users";break;case"LiteLLM_ProxyModelTable":t="Models";break;default:t=s}return(0,c.jsx)("span",{children:t})}},{header:"Action",accessorKey:"action",cell:e=>(0,c.jsx)("span",{children:av(e.getValue())})},{header:"Changed By",accessorKey:"changed_by",cell:e=>{let s=e.row.original.changed_by,t=e.row.original.changed_by_api_key;return(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsx)("div",{className:"font-medium",children:s}),t&&(0,c.jsx)(V.Z,{title:t,children:(0,c.jsxs)("div",{className:"text-xs text-muted-foreground max-w-[15ch] truncate",children:[" ",t]})})]})}},{header:"Affected Item ID",accessorKey:"object_id",cell:e=>(0,c.jsx)(()=>{let s=e.getValue(),[t,l]=(0,d.useState)(!1);if(!s)return(0,c.jsx)(c.Fragment,{children:"-"});let a=async()=>{try{await navigator.clipboard.writeText(String(s)),l(!0),setTimeout(()=>l(!1),1500)}catch(e){console.error("Failed to copy object ID: ",e)}};return(0,c.jsx)(V.Z,{title:t?"Copied!":String(s),children:(0,c.jsx)("span",{className:"max-w-[20ch] truncate block cursor-pointer hover:text-blue-600",onClick:a,children:String(s)})})},{})}],ab=async(e,s,t,l)=>{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),l.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let l=await (0,j.uiSpendLogDetailsCall)(t,e.request_id,s);return console.log("Received details for",e.request_id,":",l?"success":"failed"),l},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}};function a_(e){let{row:s,hasMessages:t,hasResponse:l,hasError:a,errorInfo:r,getRawRequest:i,formattedResponse:n}=e,o=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0;{let s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.focus(),s.select();let t=document.execCommand("copy");if(document.body.removeChild(s),!t)throw Error("execCommand failed");return!0}}catch(e){return console.error("Copy failed:",e),!1}},d=async()=>{await o(JSON.stringify(i(),null,2))?eo.Z.success("Request copied to clipboard"):eo.Z.fromBackend("Failed to copy request")},m=async()=>{await o(JSON.stringify(n(),null,2))?eo.Z.success("Response copied to clipboard"):eo.Z.fromBackend("Failed to copy response")};return(0,c.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 w-full max-w-full overflow-hidden box-border",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,c.jsx)("button",{onClick:d,className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-96 w-full max-w-full box-border",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all w-full max-w-full overflow-hidden break-words",children:JSON.stringify(i(),null,2)})})]}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,c.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,c.jsx)("button",{onClick:m,className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!l,children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50 w-full max-w-full box-border",children:l?(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all w-full max-w-full overflow-hidden break-words",children:JSON.stringify(n(),null,2)}):(0,c.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let aN=e=>{var s;let{errorInfo:t}=e,[l,a]=d.useState({}),[r,i]=d.useState(!1),n=e=>{a(s=>({...s,[e]:!s[e]}))},o=t.traceback&&(s=t.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let t=e[1],l=e[2],a=t.split("/").pop()||t,r=e.index||0,i=s.indexOf('File "',r+1),n=i>-1?s.substring(r,i).trim():s.substring(r).trim(),o=n.split("\n"),c="";return o.length>1&&(c=o[o.length-1].trim()),{filePath:t,fileName:a,lineNumber:l,code:c,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"p-4 border-b",children:(0,c.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,c.jsx)("span",{className:"text-red-700",children:t.error_class||"Unknown Error"})]}),(0,c.jsxs)("div",{className:"flex mt-2",children:[(0,c.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,c.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:t.error_message||"Unknown error occurred"})]})]}),t.traceback&&(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,c.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsx)("button",{onClick:()=>{let e=!r;if(i(e),o.length>0){let s={};o.forEach((t,l)=>{s[l]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,c.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(t.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,c.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,c.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,c.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,c.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>n(s),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,c.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,c.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,c.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,c.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(l[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(l[s]||!1)&&e.code&&(0,c.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})]},s))})]})]})]})},aZ=e=>{let{show:s}=e;return s?(0,c.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,c.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,c.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,c.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,c.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,c.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,c.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,c.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,c.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,c.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var aw=t(35829);let ak=e=>{let{sessionId:s,logs:t,onBack:l}=e,[a,r]=(0,d.useState)(null),[i,n]=(0,d.useState)({}),o=t.reduce((e,s)=>e+(s.spend||0),0),m=t.reduce((e,s)=>e+(s.total_tokens||0),0),u=t.reduce((e,s)=>{var t,l;return e+((null===(l=s.metadata)||void 0===l?void 0:null===(t=l.additional_usage_values)||void 0===t?void 0:t.cache_read_input_tokens)||0)},0),x=t.reduce((e,s)=>{var t,l;return e+((null===(l=s.metadata)||void 0===l?void 0:null===(t=l.additional_usage_values)||void 0===t?void 0:t.cache_creation_input_tokens)||0)},0),h=m+u+x,p=t.length>0?new Date(t[0].startTime):new Date;(((t.length>0?new Date(t[t.length-1].endTime):new Date).getTime()-p.getTime())/1e3).toFixed(2),t.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0}));let g=async(e,s)=>{await eM(e)&&(n(e=>({...e,[s]:!0})),setTimeout(()=>{n(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:l,className:"mb-4",children:"Back to All Logs"}),(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:i["session-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>g(s,"session-id"),className:"left-2 z-10 transition-all duration-200 ".concat(i["session-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]}),(0,c.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(aw.Z,{children:t.length})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Cost"}),(0,c.jsxs)(aw.Z,{children:["$",eE(o,6)]})]}),(0,c.jsx)(V.Z,{title:(0,c.jsxs)("div",{className:"text-white min-w-[200px]",children:[(0,c.jsx)("div",{className:"text-lg font-medium mb-3",children:"Usage breakdown"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-base font-medium mb-2",children:"Input usage:"}),(0,c.jsxs)("div",{className:"space-y-2 text-sm text-gray-300",children:[(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(t.reduce((e,s)=>e+(s.prompt_tokens||0),0))})]}),u>0&&(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input_cached_tokens:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(u)})]}),x>0&&(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"input_cache_creation_tokens:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(x)})]})]})]}),(0,c.jsxs)("div",{className:"border-t border-gray-600 pt-3",children:[(0,c.jsx)("div",{className:"text-base font-medium mb-2",children:"Output usage:"}),(0,c.jsx)("div",{className:"space-y-2 text-sm text-gray-300",children:(0,c.jsxs)("div",{className:"flex justify-between",children:[(0,c.jsx)("span",{children:"output:"}),(0,c.jsx)("span",{className:"ml-8",children:eE(t.reduce((e,s)=>e+(s.completion_tokens||0),0))})]})})]}),(0,c.jsx)("div",{className:"border-t border-gray-600 pt-3",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-base font-medium",children:"Total usage:"}),(0,c.jsx)("span",{className:"text-sm text-gray-300",children:eE(h)})]})})]})]}),placement:"top",overlayStyle:{minWidth:"300px"},children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)("span",{className:"text-gray-400 text-sm",children:"ⓘ"})]}),(0,c.jsx)(aw.Z,{children:eE(h)})]})})]}),(0,c.jsx)(S.Z,{children:"Session Logs"}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(lx,{columns:af,data:t,renderSubComponent:aq,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function aS(e){let{data:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)({});if(!s||0===s.length)return null;let i=e=>new Date(1e3*e).toLocaleString(),n=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let t="".concat(e,"-").concat(s);r(e=>({...e,[t]:!e[t]}))};return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>l(!t),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:t?"Click to collapse":"Click to expand"})]}),t&&(0,c.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,c.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,c.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,c.jsx)("span",{className:"font-mono",children:e.query})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,c.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,c.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:t}=(0,sU.dr)(e.custom_llm_provider);return(0,c.jsxs)(c.Fragment,{children:[s&&(0,c.jsx)("img",{src:s,alt:"".concat(t," logo"),className:"h-5 w-5 mr-2"}),t]})})()})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:i(e.start_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:i(e.end_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsx)("span",{children:n(e.start_time,e.end_time)})]})]})]})}),(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,c.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,t)=>{let l=a["".concat(s,"-").concat(t)]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,t),children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsxs)("span",{className:"font-medium mr-2",children:["Result ",t+1]}),(0,c.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,c.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),l&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,c.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,c.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},t)})})]},s))})]})}let aC=e=>e>=.8?"text-green-600":"text-yellow-600";var aI=e=>{let{entities:s}=e,[t,l]=(0,d.useState)(!0),[a,r]=(0,d.useState)({}),i=e=>{r(s=>({...s,[e]:!s[e]}))};return s&&0!==s.length?(0,c.jsxs)("div",{className:"mt-4",children:[(0,c.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>l(!t),children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.length,")"]})]}),t&&(0,c.jsx)("div",{className:"space-y-2",children:s.map((e,s)=>{let t=a[s]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>i(s),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,c.jsxs)("span",{className:"font-mono ".concat(aC(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,c.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),t&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,c.jsx)("span",{children:e.entity_type})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,c.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,c.jsx)("span",{className:aC(e.score),children:e.score.toFixed(2)})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,c.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,c.jsxs)("div",{className:"flex overflow-hidden",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,c.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,c.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]}):null};let aA=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"slate";return(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat({green:"bg-green-100 text-green-800",red:"bg-red-100 text-red-800",blue:"bg-blue-50 text-blue-700",slate:"bg-slate-100 text-slate-800",amber:"bg-amber-100 text-amber-800"}[s]),children:e})},aL=e=>e?aA("detected","red"):aA("not detected","slate"),aT=e=>{let{title:s,count:t,defaultOpen:l=!0,right:a,children:r}=e,[i,n]=(0,d.useState)(l);return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>n(e=>!e),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(i?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsxs)("h5",{className:"font-medium",children:[s," ","number"==typeof t&&(0,c.jsxs)("span",{className:"text-gray-500 font-normal",children:["(",t,")"]})]})]}),(0,c.jsx)("div",{children:a})]}),i&&(0,c.jsx)("div",{className:"p-3 border-t bg-white",children:r})]})},aP=e=>{let{label:s,children:t,mono:l}=e;return(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:s}),(0,c.jsx)("span",{className:l?"font-mono text-sm break-all":"",children:t})]})},aE=()=>(0,c.jsx)("div",{className:"my-3 border-t"});var aM=e=>{var s,t,l,a,r,i,n,o,d,m;let{response:u}=e;if(!u)return null;let x=null!==(r=null!==(a=u.outputs)&&void 0!==a?a:u.output)&&void 0!==r?r:[],h="GUARDRAIL_INTERVENED"===u.action?"red":"green",p=(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(null===(s=u.guardrailCoverage)||void 0===s?void 0:s.textCharacters)&&aA("text guarded ".concat(null!==(i=u.guardrailCoverage.textCharacters.guarded)&&void 0!==i?i:0,"/").concat(null!==(n=u.guardrailCoverage.textCharacters.total)&&void 0!==n?n:0),"blue"),(null===(t=u.guardrailCoverage)||void 0===t?void 0:t.images)&&aA("images guarded ".concat(null!==(o=u.guardrailCoverage.images.guarded)&&void 0!==o?o:0,"/").concat(null!==(d=u.guardrailCoverage.images.total)&&void 0!==d?d:0),"blue")]}),g=u.usage&&(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(u.usage).map(e=>{let[s,t]=e;return"number"==typeof t?(0,c.jsxs)("span",{className:"px-2 py-1 bg-slate-100 text-slate-800 rounded-md text-xs font-medium",children:[s,": ",t]},s):null})});return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Action:",children:aA(null!==(m=u.action)&&void 0!==m?m:"N/A",h)}),u.actionReason&&(0,c.jsx)(aP,{label:"Action Reason:",children:u.actionReason}),u.blockedResponse&&(0,c.jsx)(aP,{label:"Blocked Response:",children:(0,c.jsx)("span",{className:"italic",children:u.blockedResponse})})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Coverage:",children:p}),(0,c.jsx)(aP,{label:"Usage:",children:g})]})]}),x.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(aE,{}),(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Outputs"}),(0,c.jsx)("div",{className:"space-y-2",children:x.map((e,s)=>{var t;return(0,c.jsx)("div",{className:"p-3 bg-gray-50 rounded-md",children:(0,c.jsx)("div",{className:"text-sm whitespace-pre-wrap",children:null!==(t=e.text)&&void 0!==t?t:(0,c.jsx)("em",{children:"(non-text output)"})})},s)})})]})]}),(null===(l=u.assessments)||void 0===l?void 0:l.length)?(0,c.jsx)("div",{className:"space-y-3",children:u.assessments.map((e,s)=>{var t,l,a,r,i,n,o,d,m,u,x,h,p,g,j,f,v,y,b,_,N,Z,w,k;let S=(0,c.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.wordPolicy&&aA("word","slate"),e.contentPolicy&&aA("content","slate"),e.topicPolicy&&aA("topic","slate"),e.sensitiveInformationPolicy&&aA("sensitive-info","slate"),e.contextualGroundingPolicy&&aA("contextual-grounding","slate"),e.automatedReasoningPolicy&&aA("automated-reasoning","slate")]});return(0,c.jsxs)(aT,{title:"Assessment #".concat(s+1),defaultOpen:!0,right:(0,c.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.invocationMetrics)||void 0===t?void 0:t.guardrailProcessingLatency)!=null&&aA("".concat(e.invocationMetrics.guardrailProcessingLatency," ms"),"amber"),S]}),children:[e.wordPolicy&&(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Word Policy"}),(null!==(f=null===(l=e.wordPolicy.customWords)||void 0===l?void 0:l.length)&&void 0!==f?f:0)>0&&(0,c.jsx)(aT,{title:"Custom Words",defaultOpen:!0,children:(0,c.jsx)("div",{className:"space-y-2",children:e.wordPolicy.customWords.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-mono text-sm break-all",children:e.match})]}),aL(e.detected)]},s)})})}),(null!==(v=null===(a=e.wordPolicy.managedWordLists)||void 0===a?void 0:a.length)&&void 0!==v?v:0)>0&&(0,c.jsx)(aT,{title:"Managed Word Lists",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.wordPolicy.managedWordLists.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-mono text-sm break-all",children:e.match}),e.type&&aA(e.type,"slate")]}),aL(e.detected)]},s)})})})]}),(null===(i=e.contentPolicy)||void 0===i?void 0:null===(r=i.filters)||void 0===r?void 0:r.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Content Policy"}),(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)("table",{className:"min-w-full text-sm",children:[(0,c.jsx)("thead",{children:(0,c.jsxs)("tr",{className:"text-left text-gray-600",children:[(0,c.jsx)("th",{className:"py-1 pr-4",children:"Type"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Action"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Detected"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Strength"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Confidence"})]})}),(0,c.jsx)("tbody",{children:e.contentPolicy.filters.map((e,s)=>{var t,l,a,r;return(0,c.jsxs)("tr",{className:"border-t",children:[(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(t=e.type)&&void 0!==t?t:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aA(null!==(l=e.action)&&void 0!==l?l:"—",e.detected?"red":"slate")}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aL(e.detected)}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(a=e.filterStrength)&&void 0!==a?a:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(r=e.confidence)&&void 0!==r?r:"—"})]},s)})})]})})]}):null,(null===(o=e.contextualGroundingPolicy)||void 0===o?void 0:null===(n=o.filters)||void 0===n?void 0:n.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Contextual Grounding"}),(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)("table",{className:"min-w-full text-sm",children:[(0,c.jsx)("thead",{children:(0,c.jsxs)("tr",{className:"text-left text-gray-600",children:[(0,c.jsx)("th",{className:"py-1 pr-4",children:"Type"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Action"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Detected"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Score"}),(0,c.jsx)("th",{className:"py-1 pr-4",children:"Threshold"})]})}),(0,c.jsx)("tbody",{children:e.contextualGroundingPolicy.filters.map((e,s)=>{var t,l,a,r;return(0,c.jsxs)("tr",{className:"border-t",children:[(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(t=e.type)&&void 0!==t?t:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aA(null!==(l=e.action)&&void 0!==l?l:"—",e.detected?"red":"slate")}),(0,c.jsx)("td",{className:"py-1 pr-4",children:aL(e.detected)}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(a=e.score)&&void 0!==a?a:"—"}),(0,c.jsx)("td",{className:"py-1 pr-4",children:null!==(r=e.threshold)&&void 0!==r?r:"—"})]},s)})})]})})]}):null,e.sensitiveInformationPolicy&&(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Sensitive Information"}),(null!==(y=null===(d=e.sensitiveInformationPolicy.piiEntities)||void 0===d?void 0:d.length)&&void 0!==y?y:0)>0&&(0,c.jsx)(aT,{title:"PII Entities",defaultOpen:!0,children:(0,c.jsx)("div",{className:"space-y-2",children:e.sensitiveInformationPolicy.piiEntities.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),e.type&&aA(e.type,"slate"),(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.match})]}),aL(e.detected)]},s)})})}),(null!==(b=null===(m=e.sensitiveInformationPolicy.regexes)||void 0===m?void 0:m.length)&&void 0!==b?b:0)>0&&(0,c.jsx)(aT,{title:"Custom Regexes",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.sensitiveInformationPolicy.regexes.map((e,s)=>{var t,l;return(0,c.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-2 bg-gray-50 rounded gap-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-medium",children:null!==(l=e.name)&&void 0!==l?l:"regex"}),(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.regex})]}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aL(e.detected),e.match&&(0,c.jsx)("span",{className:"font-mono text-xs break-all",children:e.match})]})]},s)})})})]}),(null===(x=e.topicPolicy)||void 0===x?void 0:null===(u=x.topics)||void 0===u?void 0:u.length)?(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsx)("h6",{className:"font-medium mb-2",children:"Topic Policy"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:e.topicPolicy.topics.map((e,s)=>{var t,l;return(0,c.jsx)("div",{className:"px-3 py-1.5 bg-gray-50 rounded-md text-xs",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[aA(null!==(t=e.action)&&void 0!==t?t:"N/A",e.detected?"red":"slate"),(0,c.jsx)("span",{className:"font-medium",children:null!==(l=e.name)&&void 0!==l?l:"topic"}),e.type&&aA(e.type,"slate"),aL(e.detected)]})},s)})})]}):null,e.invocationMetrics&&(0,c.jsx)(aT,{title:"Invocation Metrics",defaultOpen:!1,children:(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)(aP,{label:"Latency (ms)",children:null!==(_=e.invocationMetrics.guardrailProcessingLatency)&&void 0!==_?_:"—"}),(0,c.jsx)(aP,{label:"Coverage:",children:(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(null===(h=e.invocationMetrics.guardrailCoverage)||void 0===h?void 0:h.textCharacters)&&aA("text ".concat(null!==(N=e.invocationMetrics.guardrailCoverage.textCharacters.guarded)&&void 0!==N?N:0,"/").concat(null!==(Z=e.invocationMetrics.guardrailCoverage.textCharacters.total)&&void 0!==Z?Z:0),"blue"),(null===(p=e.invocationMetrics.guardrailCoverage)||void 0===p?void 0:p.images)&&aA("images ".concat(null!==(w=e.invocationMetrics.guardrailCoverage.images.guarded)&&void 0!==w?w:0,"/").concat(null!==(k=e.invocationMetrics.guardrailCoverage.images.total)&&void 0!==k?k:0),"blue")]})})]}),(0,c.jsx)("div",{className:"space-y-2",children:(0,c.jsx)(aP,{label:"Usage:",children:(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:e.invocationMetrics.usage&&Object.entries(e.invocationMetrics.usage).map(e=>{let[s,t]=e;return"number"==typeof t?(0,c.jsxs)("span",{className:"px-2 py-1 bg-slate-100 text-slate-800 rounded-md text-xs font-medium",children:[s,": ",t]},s):null})})})})]})}),(null===(j=e.automatedReasoningPolicy)||void 0===j?void 0:null===(g=j.findings)||void 0===g?void 0:g.length)?(0,c.jsx)(aT,{title:"Automated Reasoning Findings",defaultOpen:!1,children:(0,c.jsx)("div",{className:"space-y-2",children:e.automatedReasoningPolicy.findings.map((e,s)=>(0,c.jsx)("pre",{className:"bg-gray-50 rounded p-2 text-xs overflow-x-auto",children:JSON.stringify(e,null,2)},s))})}):null]},s)})}):null,(0,c.jsx)(aT,{title:"Raw Bedrock Guardrail Response",defaultOpen:!1,children:(0,c.jsx)("pre",{className:"bg-gray-50 rounded p-3 text-xs overflow-x-auto",children:JSON.stringify(u,null,2)})})]})},aO=e=>{var s,t;let{data:l}=e,[a,r]=(0,d.useState)(!0),i=null!==(t=l.guardrail_provider)&&void 0!==t?t:"presidio";if(!l)return null;let n="string"==typeof l.guardrail_status&&"success"===l.guardrail_status.toLowerCase(),o=n?null:"Guardrail failed to run.",m=l.masked_entity_count?Object.values(l.masked_entity_count).reduce((e,s)=>e+s,0):0,u=e=>new Date(1e3*e).toLocaleString();return(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>r(!a),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,c.jsx)(V.Z,{title:o,placement:"top",arrow:!0,destroyTooltipOnHide:!0,children:(0,c.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat(n?"bg-green-100 text-green-800":"bg-red-100 text-red-800 cursor-help"),children:l.guardrail_status})}),m>0&&(0,c.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[m," masked ",1===m?"entity":"entities"]})]}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:a?"Click to collapse":"Click to expand"})]}),a&&(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,c.jsx)("span",{className:"font-mono",children:l.guardrail_name})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,c.jsx)("span",{className:"font-mono",children:l.guardrail_mode})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,c.jsx)(V.Z,{title:o,placement:"top",arrow:!0,destroyTooltipOnHide:!0,children:(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat(n?"bg-green-100 text-green-800":"bg-red-100 text-red-800 cursor-help"),children:l.guardrail_status})})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:u(l.start_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:u(l.end_time)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsxs)("span",{children:[l.duration.toFixed(4),"s"]})]})]})]}),l.masked_entity_count&&Object.keys(l.masked_entity_count).length>0&&(0,c.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,c.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(l.masked_entity_count).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",t]},s)})})]})]}),"presidio"===i&&(null===(s=l.guardrail_response)||void 0===s?void 0:s.length)>0&&(0,c.jsx)(aI,{entities:l.guardrail_response}),"bedrock"===i&&l.guardrail_response&&(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(aM,{response:l.guardrail_response})})]})]})};let aD={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",END_USER:"End User",STATUS:"Status",KEY_ALIAS:"Key Alias"},aF="".concat("../ui/assets/","audit-logs-preview.png");function aR(e){let{userID:s,userRole:t,token:l,accessToken:a,isActive:r,premiumUser:i,allTeams:n}=e,[o,m]=(0,d.useState)(ah()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),u=(0,d.useRef)(null),x=(0,d.useRef)(null),[h,p]=(0,d.useState)(1),[g]=(0,d.useState)(50),[f,v]=(0,d.useState)({}),[y,b]=(0,d.useState)(""),[_,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)(""),[S,C]=(0,d.useState)("all"),[I,A]=(0,d.useState)("all"),[L,T]=(0,d.useState)(!1),[P,E]=(0,d.useState)(!1),M=(0,sj.a)({queryKey:["all_audit_logs",a,l,t,s,o],queryFn:async()=>{if(!a||!l||!t||!s)return[];let e=ah()(o).utc().format("YYYY-MM-DD HH:mm:ss"),r=ah()().utc().format("YYYY-MM-DD HH:mm:ss"),i=[],n=1,c=1;do{let s=await (0,j.uiAuditLogsCall)(a,e,r,n,50);i=i.concat(s.audit_logs),c=s.total_pages,n++}while(n<=c);return i},enabled:!!a&&!!l&&!!t&&!!s&&r,refetchInterval:5e3,refetchIntervalInBackground:!0}),O=(0,d.useCallback)(async e=>{if(a)try{let s=(await (0,j.keyListCall)(a,null,null,e,null,null,1,10)).keys.find(s=>s.key_alias===e);s?N(s.token):N("")}catch(e){console.error("Error fetching key hash for alias:",e),N("")}},[a]);(0,d.useEffect)(()=>{if(!a)return;let e=!1,s=!1;f["Team ID"]?y!==f["Team ID"]&&(b(f["Team ID"]),e=!0):""!==y&&(b(""),e=!0),f["Key Hash"]?_!==f["Key Hash"]&&(N(f["Key Hash"]),s=!0):f["Key Alias"]?O(f["Key Alias"]):""!==_&&(N(""),s=!0),(e||s)&&p(1)},[f,a,O,y,_]),(0,d.useEffect)(()=>{p(1)},[y,_,o,Z,S,I]),(0,d.useEffect)(()=>{function e(e){u.current&&!u.current.contains(e.target)&&T(!1),x.current&&!x.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let D=(0,d.useMemo)(()=>M.data?M.data.filter(e=>{var s,t,l,a,r,i,n;let o=!0,c=!0,d=!0,m=!0,u=!0;if(y){let r="string"==typeof e.before_value?null===(s=JSON.parse(e.before_value))||void 0===s?void 0:s.team_id:null===(t=e.before_value)||void 0===t?void 0:t.team_id,i="string"==typeof e.updated_values?null===(l=JSON.parse(e.updated_values))||void 0===l?void 0:l.team_id:null===(a=e.updated_values)||void 0===a?void 0:a.team_id;o=r===y||i===y}if(_)try{let s="string"==typeof e.before_value?JSON.parse(e.before_value):e.before_value,t="string"==typeof e.updated_values?JSON.parse(e.updated_values):e.updated_values,l=null==s?void 0:s.token,a=null==t?void 0:t.token;c="string"==typeof l&&l.includes(_)||"string"==typeof a&&a.includes(_)}catch(e){c=!1}if(Z&&(d=null===(r=e.object_id)||void 0===r?void 0:r.toLowerCase().includes(Z.toLowerCase())),"all"!==S&&(m=(null===(i=e.action)||void 0===i?void 0:i.toLowerCase())===S.toLowerCase()),"all"!==I){let s="";switch(I){case"keys":s="litellm_verificationtoken";break;case"teams":s="litellm_teamtable";break;case"users":s="litellm_usertable";break;default:s=I}u=(null===(n=e.table_name)||void 0===n?void 0:n.toLowerCase())===s}return o&&c&&d&&m&&u}):[],[M.data,y,_,Z,S,I]),F=D.length,R=Math.ceil(F/g)||1,z=(0,d.useMemo)(()=>{let e=(h-1)*g,s=e+g;return D.slice(e,s)},[D,h,g]),U=!M.data||0===M.data.length,q=(0,d.useCallback)(e=>{let{row:s}=e;return(0,c.jsx)(e=>{let{rowData:s}=e,{before_value:t,updated_values:l,table_name:a,action:r}=s,i=(e,s)=>{if(!e||0===Object.keys(e).length)return(0,c.jsx)(k.Z,{children:"N/A"});if(s){let s=Object.keys(e),t=["token","spend","max_budget"];if(s.every(e=>t.includes(e))&&s.length>0)return(0,c.jsxs)("div",{children:[s.includes("token")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Token:"})," ",e.token||"N/A"]}),s.includes("spend")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Spend:"})," ",void 0!==e.spend?"$".concat(eE(e.spend,6)):"N/A"]}),s.includes("max_budget")&&(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Max Budget:"})," ",void 0!==e.max_budget?"$".concat(eE(e.max_budget,6)):"N/A"]})]});if(e["No differing fields detected in 'before' state"]||e["No differing fields detected in 'updated' state"]||e["No fields changed"])return(0,c.jsx)(k.Z,{children:e[Object.keys(e)[0]]})}return(0,c.jsx)("pre",{className:"p-2 bg-gray-50 border rounded text-xs overflow-auto max-h-60",children:JSON.stringify(e,null,2)})},n=t,o=l;if(("updated"===r||"rotated"===r)&&t&&l&&("LiteLLM_TeamTable"===a||"LiteLLM_UserTable"===a||"LiteLLM_VerificationToken"===a)){let e={},s={};new Set([...Object.keys(t),...Object.keys(l)]).forEach(a=>{JSON.stringify(t[a])!==JSON.stringify(l[a])&&(t.hasOwnProperty(a)&&(e[a]=t[a]),l.hasOwnProperty(a)&&(s[a]=l[a]))}),Object.keys(t).forEach(a=>{l.hasOwnProperty(a)||e.hasOwnProperty(a)||(e[a]=t[a],s[a]=void 0)}),Object.keys(l).forEach(a=>{t.hasOwnProperty(a)||s.hasOwnProperty(a)||(s[a]=l[a],e[a]=void 0)}),n=Object.keys(e).length>0?e:{"No differing fields detected in 'before' state":"N/A"},o=Object.keys(s).length>0?s:{"No differing fields detected in 'updated' state":"N/A"},0===Object.keys(e).length&&0===Object.keys(s).length&&(n={"No fields changed":"N/A"},o={"No fields changed":"N/A"})}return(0,c.jsxs)("div",{className:"-mx-4 p-4 bg-slate-100 border-y border-slate-300 grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"font-semibold mb-2 text-sm text-slate-700",children:"Before Value:"}),i(n,"LiteLLM_VerificationToken"===a)]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"font-semibold mb-2 text-sm text-slate-700",children:"Updated Value:"}),i(o,"LiteLLM_VerificationToken"===a)]})]})},{rowData:s.original})},[]);if(!i)return(0,c.jsxs)("div",{style:{textAlign:"center",marginTop:"20px"},children:[(0,c.jsx)("h1",{style:{display:"block",marginBottom:"10px"},children:"✨ Enterprise Feature."}),(0,c.jsx)(k.Z,{style:{display:"block",marginBottom:"10px"},children:"This is a LiteLLM Enterprise feature, and requires a valid key to use."}),(0,c.jsx)(k.Z,{style:{display:"block",marginBottom:"20px",fontStyle:"italic"},children:"Here's a preview of what Audit Logs offer:"}),(0,c.jsx)("img",{src:aF,alt:"Audit Logs Preview",style:{maxWidth:"100%",maxHeight:"700px",borderRadius:"8px",boxShadow:"0 4px 8px rgba(0,0,0,0.1)",margin:"0 auto"},onError:e=>{console.error("Failed to load audit logs preview image"),e.target.style.display="none"}})]});let B=F>0?(h-1)*g+1:0,V=Math.min(h*g,F);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4"}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"border-b px-6 py-4",children:[(0,c.jsx)("h1",{className:"text-xl font-semibold py-4",children:"Audit Logs"}),(0,c.jsx)(e=>{let{show:s}=e;return s?(0,c.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start mb-6",children:[(0,c.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,c.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,c.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,c.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,c.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,c.jsxs)("div",{children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Audit Logs Not Available"}),(0,c.jsx)("p",{className:"text-sm text-blue-700 mt-1",children:"To enable audit logging, add the following configuration to your LiteLLM proxy configuration file:"}),(0,c.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"litellm_settings:\n store_audit_logs: true"}),(0,c.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change and proxy restart."})]})]}):null},{show:U}),(0,c.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,c.jsx)("div",{className:"flex flex-wrap items-center gap-3",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)("input",{type:"text",placeholder:"Search by Object ID...",value:Z,onChange:e=>w(e.target.value),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,c.jsxs)("button",{onClick:()=>{M.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,c.jsx)("svg",{className:"w-4 h-4 ".concat(M.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsx)("span",{children:"Refresh"})]})]})}),(0,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsxs)("div",{className:"relative",ref:u,children:[(0,c.jsx)("label",{htmlFor:"actionFilterDisplay",className:"mr-2 text-sm font-medium text-gray-700 sr-only",children:"Action:"}),(0,c.jsxs)("button",{id:"actionFilterDisplay",onClick:()=>T(!L),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 bg-white w-40 text-left justify-between",children:[(0,c.jsxs)("span",{children:["all"===S&&"All Actions","created"===S&&"Created","updated"===S&&"Updated","deleted"===S&&"Deleted","rotated"===S&&"Rotated"]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})]}),L&&(0,c.jsx)("div",{className:"absolute left-0 mt-2 w-40 bg-white rounded-lg shadow-lg border p-1 z-50",children:(0,c.jsx)("div",{className:"space-y-1",children:[{label:"All Actions",value:"all"},{label:"Created",value:"created"},{label:"Updated",value:"updated"},{label:"Deleted",value:"deleted"},{label:"Rotated",value:"rotated"}].map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(S===e.value?"bg-blue-50 text-blue-600 font-medium":"font-normal"),onClick:()=>{C(e.value),T(!1)},children:e.label},e.value))})})]}),(0,c.jsxs)("div",{className:"relative",ref:x,children:[(0,c.jsx)("label",{htmlFor:"tableFilterDisplay",className:"mr-2 text-sm font-medium text-gray-700 sr-only",children:"Table:"}),(0,c.jsxs)("button",{id:"tableFilterDisplay",onClick:()=>E(!P),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 bg-white w-40 text-left justify-between",children:[(0,c.jsxs)("span",{children:["all"===I&&"All Tables","keys"===I&&"Keys","teams"===I&&"Teams","users"===I&&"Users"]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})]}),P&&(0,c.jsx)("div",{className:"absolute left-0 mt-2 w-40 bg-white rounded-lg shadow-lg border p-1 z-50",children:(0,c.jsx)("div",{className:"space-y-1",children:[{label:"All Tables",value:"all"},{label:"Keys",value:"keys"},{label:"Teams",value:"teams"},{label:"Users",value:"users"}].map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I===e.value?"bg-blue-50 text-blue-600 font-medium":"font-normal"),onClick:()=>{A(e.value),E(!1)},children:e.label},e.value))})})]}),(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",M.isLoading?"...":B," ","-"," ",M.isLoading?"...":V," ","of"," ",M.isLoading?"...":F," ","results"]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",M.isLoading?"...":h," of"," ",M.isLoading?"...":R]}),(0,c.jsx)("button",{onClick:()=>p(e=>Math.max(1,e-1)),disabled:M.isLoading||1===h,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,c.jsx)("button",{onClick:()=>p(e=>Math.min(R,e+1)),disabled:M.isLoading||h===R,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})]}),(0,c.jsx)(lx,{columns:ay,data:z,renderSubComponent:q,getRowCanExpand:()=>!0})]})]})}let az=(e,s,t)=>{if(e)return"".concat(ah()(s).format("MMM D, h:mm A")," - ").concat(ah()(t).format("MMM D, h:mm A"));let l=ah()(),a=ah()(s),r=l.diff(a,"minutes");if(r>=0&&r<2)return"Last 1 Minute";if(r>=2&&r<16)return"Last 15 Minutes";if(r>=16&&r<61)return"Last Hour";let i=l.diff(a,"hours");return i>=1&&i<5?"Last 4 Hours":i>=5&&i<25?"Last 24 Hours":i>=25&&i<169?"Last 7 Days":"".concat(a.format("MMM D")," - ").concat(l.format("MMM D"))};function aU(e){var s,t,l;let{accessToken:a,token:r,userRole:i,userID:n,allTeams:o,premiumUser:m}=e,[u,x]=(0,d.useState)(""),[p,g]=(0,d.useState)(!1),[f,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(1),[_]=(0,d.useState)(50),N=(0,d.useRef)(null),Z=(0,d.useRef)(null),w=(0,d.useRef)(null),[k,S]=(0,d.useState)(ah()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[C,I]=(0,d.useState)(ah()().format("YYYY-MM-DDTHH:mm")),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(!1),[E,M]=(0,d.useState)(""),[O,D]=(0,d.useState)(""),[F,R]=(0,d.useState)(""),[z,U]=(0,d.useState)(""),[q,B]=(0,d.useState)(""),[V,K]=(0,d.useState)(null),[G,H]=(0,d.useState)(null),[J,Y]=(0,d.useState)(""),[W,$]=(0,d.useState)(""),[Q,X]=(0,d.useState)(i&&eI.lo.includes(i)),[ee,es]=(0,d.useState)("request logs"),[et,el]=(0,d.useState)(null),[ea,er]=(0,d.useState)(null),ei=(0,h.NL)(),[en,eo]=(0,d.useState)(()=>{let e=sessionStorage.getItem("isLiveTail");return null===e||JSON.parse(e)});(0,d.useEffect)(()=>{sessionStorage.setItem("isLiveTail",JSON.stringify(en))},[en]);let[ec,ed]=(0,d.useState)({value:24,unit:"hours"});(0,d.useEffect)(()=>{(async()=>{G&&a&&K({...(await (0,j.keyInfoV1Call)(a,G)).info,token:G,api_key:G})})()},[G,a]),(0,d.useEffect)(()=>{function e(e){N.current&&!N.current.contains(e.target)&&v(!1),Z.current&&!Z.current.contains(e.target)&&g(!1),w.current&&!w.current.contains(e.target)&&P(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,d.useEffect)(()=>{i&&eI.lo.includes(i)&&X(!0)},[i]);let em=(0,sj.a)({queryKey:["logs","table",y,_,k,C,F,z,Q?n:null,J,q],queryFn:async()=>{if(!a||!r||!i||!n)return{data:[],total:0,page:1,page_size:_,total_pages:0};let e=ah()(k).utc().format("YYYY-MM-DD HH:mm:ss"),s=A?ah()(C).utc().format("YYYY-MM-DD HH:mm:ss"):ah()().utc().format("YYYY-MM-DD HH:mm:ss"),t=await (0,j.uiSpendLogsCall)(a,z||void 0,F||void 0,void 0,e,s,y,_,Q?n:void 0,W,J,q);return await ab(t.data,e,a,ei),t.data=t.data.map(s=>{let t=ei.getQueryData(["logDetails",s.request_id,e]);return(null==t?void 0:t.messages)&&(null==t?void 0:t.response)&&(s.messages=t.messages,s.response=t.response),s}),t},enabled:!!a&&!!r&&!!i&&!!n&&"request logs"===ee,refetchInterval:!!en&&1===y&&15e3,refetchIntervalInBackground:!0}),{filters:eu,filteredLogs:ex,allTeams:eh,allKeyAliases:ep,handleFilterChange:eg,handleFilterReset:ej}=function(e){let{logs:s,accessToken:t,startTime:l,endTime:a,pageSize:r=25,isCustomDate:i,setCurrentPage:n,userID:o,userRole:c}=e,m=(0,d.useMemo)(()=>({[aD.TEAM_ID]:"",[aD.KEY_HASH]:"",[aD.REQUEST_ID]:"",[aD.MODEL]:"",[aD.USER_ID]:"",[aD.END_USER]:"",[aD.STATUS]:"",[aD.KEY_ALIAS]:""}),[]),[u,x]=(0,d.useState)(m),[h,p]=(0,d.useState)(s),g=(0,d.useRef)(0),f=(0,d.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!t)return;console.log("Filters being sent to API:",e);let n=Date.now();g.current=n;let o=ah()(l).utc().format("YYYY-MM-DD HH:mm:ss"),c=i?ah()(a).utc().format("YYYY-MM-DD HH:mm:ss"):ah()().utc().format("YYYY-MM-DD HH:mm:ss");try{let l=await (0,j.uiSpendLogsCall)(t,e[aD.KEY_HASH]||void 0,e[aD.TEAM_ID]||void 0,e[aD.REQUEST_ID]||void 0,o,c,s,r,e[aD.USER_ID]||void 0,e[aD.END_USER]||void 0,e[aD.STATUS]||void 0,e[aD.MODEL]||void 0,e[aD.KEY_ALIAS]||void 0);n===g.current&&l.data&&p(l)}catch(e){console.error("Error searching users:",e)}},[t,l,a,i,r]),v=(0,d.useMemo)(()=>eC()((e,s)=>f(e,s),300),[f]);(0,d.useEffect)(()=>()=>v.cancel(),[v]);let y=(0,sj.a)({queryKey:["allKeys"],queryFn:async()=>{if(!t)throw Error("Access token required");return await sf(t)},enabled:!!t}).data||[];(0,d.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}if(u[aD.KEY_ALIAS]||u[aD.KEY_HASH]||u[aD.REQUEST_ID]||u[aD.USER_ID]||u[aD.END_USER])return;let e=[...s.data];u[aD.TEAM_ID]&&(e=e.filter(e=>e.team_id===u[aD.TEAM_ID])),u[aD.STATUS]&&(e=e.filter(e=>"success"===u[aD.STATUS]?!e.status||"success"===e.status:e.status===u[aD.STATUS])),u[aD.MODEL]&&(e=e.filter(e=>e.model===u[aD.MODEL])),u[aD.KEY_HASH]&&(e=e.filter(e=>e.api_key===u[aD.KEY_HASH])),u[aD.END_USER]&&(e=e.filter(e=>e.end_user===u[aD.END_USER]));let t={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(t)!==JSON.stringify(h)&&p(t)},[s,u,h,t]);let{data:b}=(0,sj.a)({queryKey:["allTeamsForLogFilters",t],queryFn:async()=>t&&await sv(t)||[],enabled:!!t});return{filters:u,filteredLogs:h,allKeyAliases:y,allTeams:b,handleFilterChange:e=>{x(s=>{let t={...s,...e};for(let e of Object.keys(m))e in t||(t[e]=m[e]);return JSON.stringify(t)!==JSON.stringify(s)&&(n(1),v(t,1)),t})},handleFilterReset:()=>{x(m),v(m,1)}}}({logs:em.data||{data:[],total:0,page:1,page_size:_||10,total_pages:1},accessToken:a,startTime:k,endTime:C,pageSize:_,isCustomDate:A,setCurrentPage:b,userID:n,userRole:i}),ef=(0,d.useCallback)(async e=>{if(a)try{let s=(await (0,j.keyListCall)(a,null,null,e,null,null,y,_)).keys.find(s=>s.key_alias===e);s&&U(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,y,_]);(0,d.useEffect)(()=>{a&&(eu["Team ID"]?R(eu["Team ID"]):R(""),Y(eu.Status||""),B(eu.Model||""),$(eu["End User"]||""),eu["Key Hash"]?U(eu["Key Hash"]):eu["Key Alias"]?ef(eu["Key Alias"]):U(""))},[eu,a,ef]);let ev=(0,sj.a)({queryKey:["sessionLogs",ea],queryFn:async()=>{if(!a||!ea)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,j.sessionSpendLogsCall)(a,ea);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!ea});if((0,d.useEffect)(()=>{var e;(null===(e=em.data)||void 0===e?void 0:e.data)&&et&&!em.data.data.some(e=>e.request_id===et)&&el(null)},[null===(s=em.data)||void 0===s?void 0:s.data,et]),!a||!r||!i||!n)return null;let ey=ex.data.filter(e=>!u||e.request_id.includes(u)||e.model.includes(u)||e.user&&e.user.includes(u)).map(e=>({...e,duration:(Date.parse(e.endTime)-Date.parse(e.startTime))/1e3,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&er(e)}}))||[],eb=(null===(l=ev.data)||void 0===l?void 0:null===(t=l.data)||void 0===t?void 0:t.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],e_=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!1},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await sf(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"End User",label:"End User",isSearchable:!0,searchFn:async e=>{if(!a)return[];let s=await (0,j.allEndUsersCall)(a);return((null==s?void 0:s.end_users)||[]).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))}},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];if(ea&&ev.data)return(0,c.jsx)("div",{className:"w-full p-6",children:(0,c.jsx)(ak,{sessionId:ea,logs:ev.data.data,onBack:()=>er(null)})});let eN=[{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"}],eZ=eN.find(e=>e.value===ec.value&&e.unit===ec.unit),ew=A?az(A,k,C):null==eZ?void 0:eZ.label;return(0,c.jsx)("div",{className:"w-full max-w-screen p-6 overflow-x-hidden box-border",children:(0,c.jsxs)(e1.Z,{defaultIndex:0,onIndexChange:e=>es(0===e?"request logs":"audit logs"),children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"Request Logs"}),(0,c.jsx)(e0.Z,{children:"Audit Logs"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,c.jsx)("h1",{className:"text-xl font-semibold",children:ea?(0,c.jsxs)(c.Fragment,{children:["Session: ",(0,c.jsx)("span",{className:"font-mono",children:ea}),(0,c.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>er(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&G&&V.api_key===G?(0,c.jsx)(sh,{keyId:G,keyData:V,accessToken:a,userID:n,userRole:i,teams:o,onClose:()=>H(null),premiumUser:m,backButtonText:"Back to Logs"}):ea?(0,c.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,c.jsx)(lx,{columns:af,data:eb,renderSubComponent:aq,getRowCanExpand:()=>!0})}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(sg,{options:e_,onApplyFilters:eg,onResetFilters:ej}),(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full box-border",children:[(0,c.jsx)("div",{className:"border-b px-6 py-4 w-full max-w-full box-border",children:(0,c.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0 w-full max-w-full box-border",children:[(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3 w-full max-w-full box-border",children:[(0,c.jsxs)("div",{className:"relative w-64 min-w-0 flex-shrink-0",children:[(0,c.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:u,onChange:e=>x(e.target.value)}),(0,c.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,c.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,c.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-shrink",children:[(0,c.jsxs)("div",{className:"relative z-50",ref:w,children:[(0,c.jsxs)("button",{onClick:()=>P(!T),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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"})}),ew]}),T&&(0,c.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,c.jsxs)("div",{className:"space-y-1",children:[eN.map(e=>(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ew===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{I(ah()().format("YYYY-MM-DDTHH:mm")),S(ah()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),ed({value:e.value,unit:e.unit}),L(!1),P(!1)},children:e.label},e.label)),(0,c.jsx)("div",{className:"border-t my-2"}),(0,c.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(A?"bg-blue-50 text-blue-600":""),onClick:()=>L(!A),children:"Custom Range"})]})})]}),(0,c.jsx)(()=>(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{className:"text-sm font-medium text-gray-900",children:"Live Tail"}),(0,c.jsx)(tB.Z,{color:"green",checked:en,defaultChecked:!0,onChange:eo})]}),{}),(0,c.jsxs)("button",{onClick:()=>{em.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,c.jsx)("svg",{className:"w-4 h-4 ".concat(em.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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,c.jsx)("span",{children:"Refresh"})]})]}),A&&(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{children:(0,c.jsx)("input",{type:"datetime-local",value:k,onChange:e=>{S(e.target.value),b(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,c.jsx)("span",{className:"text-gray-500",children:"to"}),(0,c.jsx)("div",{children:(0,c.jsx)("input",{type:"datetime-local",value:C,onChange:e=>{I(e.target.value),b(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,c.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700 whitespace-nowrap",children:["Showing ",em.isLoading?"...":ex?(y-1)*_+1:0," -"," ",em.isLoading?"...":ex?Math.min(y*_,ex.total):0," ","of ",em.isLoading?"...":ex?ex.total:0," results"]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsxs)("span",{className:"text-sm text-gray-700 min-w-[90px]",children:["Page ",em.isLoading?"...":y," of"," ",em.isLoading?"...":ex?ex.total_pages:1]}),(0,c.jsx)("button",{onClick:()=>b(e=>Math.max(1,e-1)),disabled:em.isLoading||1===y,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,c.jsx)("button",{onClick:()=>b(e=>Math.min(ex.total_pages||1,e+1)),disabled:em.isLoading||y===(ex.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"})]})]})]})}),en&&1===y&&(0,c.jsxs)("div",{className:"mb-4 px-4 py-2 bg-green-50 border border-greem-200 rounded-md flex items-center justify-between",children:[(0,c.jsx)("div",{className:"flex items-center gap-2",children:(0,c.jsx)("span",{className:"text-sm text-green-700",children:"Auto-refreshing every 15 seconds"})}),(0,c.jsx)("button",{onClick:()=>eo(!1),className:"text-sm text-green-600 hover:text-green-800",children:"Stop"})]}),(0,c.jsx)(lx,{columns:af,data:ey,renderSubComponent:aq,getRowCanExpand:()=>!0})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(aR,{userID:n,userRole:i,token:r,accessToken:a,isActive:"audit logs"===ee,premiumUser:m,allTeams:o})})]})]})})}function aq(e){var s,t,l,a,r,i,n,o;let{row:d}=e,m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},u=d.original.metadata||{},x="failure"===u.status,h=x?u.error_information:null,p=d.original.messages&&(Array.isArray(d.original.messages)?d.original.messages.length>0:Object.keys(d.original.messages).length>0),g=d.original.response&&Object.keys(m(d.original.response)).length>0,j=u.vector_store_request_metadata&&Array.isArray(u.vector_store_request_metadata)&&u.vector_store_request_metadata.length>0,f=d.original.metadata&&d.original.metadata.guardrail_information,v=f&&(null===(o=d.original.metadata)||void 0===o?void 0:o.guardrail_information.masked_entity_count)?Object.values(d.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,c.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6 w-full max-w-full overflow-hidden box-border",children:[(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full overflow-hidden",children:[(0,c.jsx)("div",{className:"p-4 border-b",children:(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,c.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 p-4 w-full max-w-full overflow-hidden",children:[(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,c.jsx)("span",{className:"font-mono text-sm",children:d.original.request_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,c.jsx)("span",{children:d.original.model})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,c.jsx)("span",{children:d.original.model_id})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,c.jsx)("span",{children:d.original.call_type})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,c.jsx)("span",{children:d.original.custom_llm_provider||"-"})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,c.jsx)(V.Z,{title:d.original.api_base||"-",children:(0,c.jsx)("span",{className:"max-w-[15ch] truncate block",children:d.original.api_base||"-"})})]}),(null==d?void 0:null===(s=d.original)||void 0===s?void 0:s.requester_ip_address)&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,c.jsx)("span",{children:null==d?void 0:null===(t=d.original)||void 0===t?void 0:t.requester_ip_address})]}),f&&(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"font-mono",children:d.original.metadata.guardrail_information.guardrail_name}),v>0&&(0,c.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[v," masked"]})]})]})]}),(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,c.jsxs)("span",{children:[d.original.total_tokens," (",d.original.prompt_tokens," prompt tokens +"," ",d.original.completion_tokens," completion tokens)"]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Read Tokens:"}),(0,c.jsx)("span",{children:eE((null===(a=d.original.metadata)||void 0===a?void 0:null===(l=a.additional_usage_values)||void 0===l?void 0:l.cache_read_input_tokens)||0)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Creation Tokens:"}),(0,c.jsx)("span",{children:eE(null===(r=d.original.metadata)||void 0===r?void 0:r.additional_usage_values.cache_creation_input_tokens)})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,c.jsxs)("span",{children:["$",eE(d.original.spend||0,6)]})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,c.jsx)("span",{children:d.original.cache_hit})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,c.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(i=d.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=d.original.metadata)||void 0===n?void 0:n.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,c.jsx)("span",{children:d.original.startTime})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,c.jsx)("span",{children:d.original.endTime})]}),(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,c.jsxs)("span",{children:[d.original.duration," s."]})]})]})]})]}),(0,c.jsx)(aZ,{show:!p&&!g}),(0,c.jsx)("div",{className:"w-full max-w-full overflow-hidden",children:(0,c.jsx)(a_,{row:d,hasMessages:p,hasResponse:g,hasError:x,errorInfo:h,getRawRequest:()=>{var e;return(null===(e=d.original)||void 0===e?void 0:e.proxy_server_request)?m(d.original.proxy_server_request):m(d.original.messages)},formattedResponse:()=>x&&h?{error:{message:h.error_message||"An error occurred",type:h.error_class||"error",code:h.error_code||"unknown",param:null}}:m(d.original.response)})}),f&&(0,c.jsx)(aO,{data:d.original.metadata.guardrail_information}),j&&(0,c.jsx)(aS,{data:u.vector_store_request_metadata}),x&&h&&(0,c.jsx)(aN,{errorInfo:h}),d.original.request_tags&&Object.keys(d.original.request_tags).length>0&&(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,c.jsx)("div",{className:"p-4",children:(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(d.original.request_tags).map(e=>{let[s,t]=e;return(0,c.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(t)]},s)})})})]}),d.original.metadata&&Object.keys(d.original.metadata).length>0&&(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,c.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,c.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(d.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,c.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,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,c.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(d.original.metadata,null,2)})})]})]})}var aB=t(36172),aV=t(14042),aK=t(49634);let aG=[{label:"Today",shortLabel:"today",getValue:()=>({from:ah()().startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Last 7 days",shortLabel:"7d",getValue:()=>({from:ah()().subtract(7,"days").startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Last 30 days",shortLabel:"30d",getValue:()=>({from:ah()().subtract(30,"days").startOf("day").toDate(),to:ah()().endOf("day").toDate()})},{label:"Month to date",shortLabel:"MTD",getValue:()=>({from:ah()().startOf("month").toDate(),to:ah()().endOf("day").toDate()})},{label:"Year to date",shortLabel:"YTD",getValue:()=>({from:ah()().startOf("year").toDate(),to:ah()().endOf("day").toDate()})}];var aH=e=>{let{value:s,onValueChange:t,label:l="Select Time Range",showTimeRange:a=!0}=e,[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(s),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(""),[p,g]=(0,d.useState)(""),j=(0,d.useRef)(null),f=(0,d.useCallback)(e=>{if(!e.from||!e.to)return null;for(let s of aG){let t=s.getValue(),l=ah()(e.from).isSame(ah()(t.from),"day"),a=ah()(e.to).isSame(ah()(t.to),"day");if(l&&a)return s.shortLabel}return null},[]);(0,d.useEffect)(()=>{u(f(s))},[s,f]);let v=(0,d.useCallback)(()=>{if(!x||!p)return{isValid:!0,error:""};let e=ah()(x,"YYYY-MM-DD"),s=ah()(p,"YYYY-MM-DD");return e.isValid()&&s.isValid()?s.isBefore(e)?{isValid:!1,error:"End date cannot be before start date"}:{isValid:!0,error:""}:{isValid:!1,error:"Invalid date format"}},[x,p])();(0,d.useEffect)(()=>{s.from&&h(ah()(s.from).format("YYYY-MM-DD")),s.to&&g(ah()(s.to).format("YYYY-MM-DD")),o(s)},[s]),(0,d.useEffect)(()=>{let e=e=>{j.current&&!j.current.contains(e.target)&&i(!1)};return r&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]);let y=(0,d.useCallback)((e,s)=>{if(!e||!s)return"Select date range";let t=e=>ah()(e).format("D MMM, HH:mm");return"".concat(t(e)," - ").concat(t(s))},[]),_=(0,d.useCallback)(e=>{let s;if(!e.from)return e;let t={...e},l=new Date(e.from);return s=new Date(e.to?e.to:e.from),l.toDateString(),s.toDateString(),l.setHours(0,0,0,0),s.setHours(23,59,59,999),t.from=l,t.to=s,t},[]),N=e=>{let{from:s,to:t}=e.getValue();o({from:s,to:t}),u(e.shortLabel),h(ah()(s).format("YYYY-MM-DD")),g(ah()(t).format("YYYY-MM-DD"))},Z=(0,d.useCallback)(()=>{try{if(x&&p&&v.isValid){let e=ah()(x,"YYYY-MM-DD").startOf("day"),s=ah()(p,"YYYY-MM-DD").endOf("day");if(e.isValid()&&s.isValid()){let t={from:e.toDate(),to:s.toDate()};o(t);let l=f(t);u(l)}}}catch(e){console.warn("Invalid date format:",e)}},[x,p,v.isValid,f]);return(0,d.useEffect)(()=>{Z()},[Z]),(0,c.jsxs)("div",{children:[l&&(0,c.jsx)(k.Z,{className:"mb-2",children:l}),(0,c.jsxs)("div",{className:"relative",ref:j,children:[(0,c.jsx)("div",{className:"w-[300px] px-3 py-2 text-sm border border-gray-300 rounded-md bg-white cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500",onClick:()=>i(!r),children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(t2.Z,{className:"text-gray-600"}),(0,c.jsx)("span",{className:"text-gray-900",children:y(s.from,s.to)})]}),(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-400 transition-transform ".concat(r?"rotate-180":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})}),r&&(0,c.jsx)("div",{className:"absolute top-full left-0 z-[9999] min-w-[600px] mt-1 bg-white border border-gray-200 rounded-lg shadow-xl",children:(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsxs)("div",{className:"w-1/2 border-r border-gray-200",children:[(0,c.jsx)("div",{className:"p-3 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-sm font-semibold text-gray-900",children:"Relative time (today, 7d, 30d, MTD, YTD)"})}),(0,c.jsx)("div",{className:"h-[350px] overflow-y-auto",children:aG.map(e=>{let s=m===e.shortLabel;return(0,c.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer border-b border-gray-100 transition-colors ".concat(s?"bg-blue-50 hover:bg-blue-100 border-blue-200":"hover:bg-gray-50"),onClick:()=>N(e),children:[(0,c.jsx)("span",{className:"text-sm ".concat(s?"text-blue-700 font-medium":"text-gray-700"),children:e.label}),(0,c.jsx)("span",{className:"text-xs px-2 py-1 rounded ".concat(s?"text-blue-700 bg-blue-100":"text-gray-500 bg-gray-100"),children:e.shortLabel})]},e.label)})})]}),(0,c.jsxs)("div",{className:"w-1/2 relative",children:[(0,c.jsx)("div",{className:"p-3.5 border-b border-gray-200",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(aK.Z,{className:"text-gray-600"}),(0,c.jsx)("span",{className:"text-sm font-semibold text-gray-900",children:"Start and end dates"})]})}),(0,c.jsxs)("div",{className:"p-6 space-y-6 pb-20",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"text-sm text-gray-700 mb-1 block",children:"Start date"}),(0,c.jsx)("input",{type:"date",value:x,onChange:e=>h(e.target.value),className:"w-65 px-3 py-2 text-sm border rounded-md cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 ".concat(v.isValid?"border-gray-300":"border-red-300 focus:border-red-500 focus:ring-red-200")})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{className:"text-sm text-gray-700 mb-1 block",children:"End date"}),(0,c.jsx)("input",{type:"date",value:p,onChange:e=>g(e.target.value),className:"w-65 px-3 py-2 text-sm border rounded-md cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 ".concat(v.isValid?"border-gray-300":"border-red-300 focus:border-red-500 focus:ring-red-200")})]}),!v.isValid&&v.error&&(0,c.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-4 h-4 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,c.jsx)("span",{className:"text-sm text-red-700 font-medium",children:v.error})]})}),n.from&&n.to&&v.isValid&&(0,c.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md",children:[(0,c.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Preview:"}),(0,c.jsx)("div",{className:"text-sm text-blue-800",children:y(n.from,n.to)})]})]}),(0,c.jsx)("div",{className:"absolute bottom-4 right-4",children:(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{o(s),s.from&&h(ah()(s.from).format("YYYY-MM-DD")),s.to&&g(ah()(s.to).format("YYYY-MM-DD")),u(f(s)),i(!1)},children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>{n.from&&n.to&&v.isValid&&(t(n),requestIdleCallback(()=>{t(_(n))},{timeout:100}),i(!1))},disabled:!n.from||!n.to||!v.isValid,children:"Apply"})]})})]})]})})]}),a&&s.from&&s.to&&(0,c.jsxs)(k.Z,{className:"mt-2 text-xs text-gray-500",children:[ah()(s.from).format("MMM D, YYYY [at] HH:mm:ss")," -"," ",ah()(s.to).format("MMM D, YYYY [at] HH:mm:ss")]})]})},aJ=e=>{let{userID:s,userRole:t,accessToken:l,userSpend:a,userMaxBudget:r,selectedTeam:i}=e;console.log("userSpend: ".concat(a));let[n,o]=(0,d.useState)(null!==a?a:0),[m,u]=(0,d.useState)(i?Number(eE(i.max_budget,4)):null);(0,d.useEffect)(()=>{if(i){if("Default Team"===i.team_alias)u(r);else{let e=!1;if(i.team_memberships)for(let t of i.team_memberships)t.user_id===s&&"max_budget"in t.litellm_budget_table&&null!==t.litellm_budget_table.max_budget&&(u(t.litellm_budget_table.max_budget),e=!0);e||u(i.max_budget)}}},[i,r]);let[x,h]=(0,d.useState)([]);(0,d.useEffect)(()=>{let e=async()=>{if(!l||!s||!t)return};(async()=>{try{if(null===s||null===t)return;if(null!==l){let e=(await (0,j.modelAvailableCall)(l,s,t)).data.map(e=>e.id);console.log("available_model_names:",e),h(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,l,s]),(0,d.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];i&&i.models&&(p=i.models),p&&p.includes("all-proxy-models")?(console.log("user models:",x),p=x):p&&p.includes("all-team-models")?p=i.models:p&&0===p.length&&(p=x);let g=null!==m?"$".concat(eE(Number(m),4)," limit"):"No limit",f=void 0!==n?eE(n,4):null;return console.log("spend in view user spend: ".concat(n)),(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,c.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",f]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,c.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:g})]})]})})};let aY=e=>{let{key:s,info:t}=e;return{token:s,...t}};var aW=e=>{let{topKeys:s,accessToken:t,userID:l,userRole:a,teams:r,premiumUser:i}=e,[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(void 0),[p,g]=(0,d.useState)("table"),f=async e=>{if(t)try{let s=await (0,j.keyInfoV1Call)(t,e.api_key),l=aY(s);h(l),u(e.api_key),o(!0)}catch(e){console.error("Error fetching key info:",e)}},v=()=>{o(!1),u(null),h(void 0)};d.useEffect(()=>{let e=e=>{"Escape"===e.key&&n&&v()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]);let y=s.map(e=>({...e,display_key_alias:e.key_alias&&e.key_alias.length>10?"".concat(e.key_alias.slice(0,10),"..."):e.key_alias||"-"}));return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)("button",{onClick:()=>g("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===p?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,c.jsx)("button",{onClick:()=>g("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===p?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===p?(0,c.jsx)("div",{className:"relative",children:(0,c.jsx)(s3.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:y,index:"display_key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:120,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(eE(e,2)):"No Key Alias",onValueChange:e=>f(e),showTooltip:!0,customTooltip:e=>{var s,t;let l=null===(t=e.payload)||void 0===t?void 0:null===(s=t[0])||void 0===s?void 0:s.payload;return(0,c.jsx)("div",{className:"relative z-50 p-3 bg-black/90 shadow-lg rounded-lg text-white max-w-xs",children:(0,c.jsxs)("div",{className:"space-y-1.5",children:[(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Key Alias: "}),(0,c.jsx)("span",{className:"font-mono text-gray-100 break-all",children:null==l?void 0:l.key_alias})]}),(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Key ID: "}),(0,c.jsx)("span",{className:"font-mono text-gray-100 break-all",children:null==l?void 0:l.api_key})]}),(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,c.jsxs)("span",{className:"text-white font-medium",children:["$",eE(null==l?void 0:l.spend,2)]})]})]})})}})}):(0,c.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,c.jsx)(lx,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:e.getValue(),children:(0,c.jsx)(b.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.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(eE(e.getValue(),2))}],data:s,renderSubComponent:()=>(0,c.jsx)(c.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),n&&m&&x&&(console.log("Rendering modal with:",{isModalOpen:n,selectedKey:m,keyData:x}),(0,c.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&v()},children:(0,c.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,c.jsx)("button",{onClick:v,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,c.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,c.jsx)("div",{className:"p-6 h-full",children:(0,c.jsx)(sh,{keyId:m,onClose:v,keyData:x,accessToken:t,userID:l,userRole:a,teams:r,premiumUser:i})})]})}))]})};function a$(e){return e>=1e6?(e/1e6).toFixed(2)+"M":e>=1e3?e/1e3+"k":e.toString()}function aQ(e){return 0===e?"$0":e>=1e6?"$"+e/1e6+"M":e>=1e3?"$"+e/1e3+"k":"$"+e}let aX={blue:"#3b82f6",cyan:"#06b6d4",indigo:"#6366f1",green:"#22c55e",red:"#ef4444",purple:"#8b5cf6"},a0=e=>{let{active:s,payload:t,label:l}=e;if(s&&t&&t.length){let e=e=>e.replace("metrics.","").replace(/_/g," ").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),s=(e,s)=>{let t=s.substring(s.indexOf(".")+1);if(e.metrics&&t in e.metrics)return e.metrics[t]};return(0,c.jsxs)("div",{className:"w-56 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[(0,c.jsx)("p",{className:"text-tremor-content-strong",children:l}),t.map(t=>{var l;let a=null===(l=t.dataKey)||void 0===l?void 0:l.toString();if(!a||!t.payload)return null;let r=s(t.payload,a),i=a.includes("spend"),n=void 0!==r?i?"$".concat(r.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})):r.toLocaleString():"N/A",o=aX[t.color]||t.color;return(0,c.jsxs)("div",{className:"flex items-center justify-between space-x-4",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full ring-2 ring-white drop-shadow-md",style:{backgroundColor:o}}),(0,c.jsx)("p",{className:"font-medium text-tremor-content dark:text-dark-tremor-content",children:e(a)})]}),(0,c.jsx)("p",{className:"font-medium text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis",children:n})]},a)})]})}return null},a1=e=>{let{categories:s,colors:t}=e,l=e=>e.replace("metrics.","").replace(/_/g," ").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ");return(0,c.jsx)("div",{className:"flex items-center justify-end space-x-4",children:s.map((e,s)=>{let a=aX[t[s]]||t[s];return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full ring-4 ring-white",style:{backgroundColor:a}}),(0,c.jsx)("p",{className:"text-sm text-tremor-content dark:text-dark-tremor-content",children:l(e)})]},e)})})},a2=e=>{var s,t;let{modelName:l,metrics:a}=e;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(S.Z,{children:a.total_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Successful Requests"}),(0,c.jsx)(S.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)(S.Z,{children:a.total_tokens.toLocaleString()}),(0,c.jsxs)(k.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," ","avg per successful request"]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Spend"}),(0,c.jsxs)(S.Z,{children:["$",eE(a.total_spend,2)]}),(0,c.jsxs)(k.Z,{children:["$",eE(a.total_spend/a.total_successful_requests,3)," ","per successful request"]})]})]}),a.top_api_keys&&a.top_api_keys.length>0&&(0,c.jsxs)(G.Z,{className:"mt-4",children:[(0,c.jsx)(S.Z,{children:"Top API Keys by Spend"}),(0,c.jsx)("div",{className:"mt-3",children:(0,c.jsx)("div",{className:"grid grid-cols-1 gap-2",children:a.top_api_keys.map((e,s)=>(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 bg-gray-50 rounded-lg",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:e.key_alias||"".concat(e.api_key.substring(0,10),"...")}),e.team_id&&(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500",children:["Team: ",e.team_id]})]}),(0,c.jsxs)("div",{className:"text-right",children:[(0,c.jsxs)(k.Z,{className:"font-medium",children:["$",eE(e.spend,2)]}),(0,c.jsxs)(k.Z,{className:"text-xs text-gray-500",children:[e.requests.toLocaleString()," requests | ",e.tokens.toLocaleString()," tokens"]})]})]},e.api_key))})})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(a1,{categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Requests per day"}),(0,c.jsx)(a1,{categories:["metrics.api_requests"],colors:["blue"]})]}),(0,c.jsx)(s3.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Spend per day"}),(0,c.jsx)(a1,{categories:["metrics.spend"],colors:["green"]})]}),(0,c.jsx)(s3.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(eE(e,2))})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Success vs Failed Requests"}),(0,c.jsx)(a1,{categories:["metrics.successful_requests","metrics.failed_requests"],colors:["green","red"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["green","red"],valueFormatter:a$,stack:!0,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Prompt Caching Metrics"}),(0,c.jsx)(a1,{categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"]})]}),(0,c.jsxs)("div",{className:"mb-2",children:[(0,c.jsxs)(k.Z,{children:["Cache Read:"," ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," ","tokens"]}),(0,c.jsxs)(k.Z,{children:["Cache Creation:"," ",(null===(t=a.total_cache_creation_input_tokens)||void 0===t?void 0:t.toLocaleString())||0," ","tokens"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]})]})]})},a4=e=>{let{modelMetrics:s}=e,t=Object.keys(s).sort((e,t)=>""===e?1:""===t?-1:s[t].total_spend-s[e].total_spend),l={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{l.total_requests+=e.total_requests,l.total_successful_requests+=e.total_successful_requests,l.total_tokens+=e.total_tokens,l.total_spend+=e.total_spend,l.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,l.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{l.daily_data[e.date]||(l.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),l.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,l.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,l.daily_data[e.date].total_tokens+=e.metrics.total_tokens,l.daily_data[e.date].api_requests+=e.metrics.api_requests,l.daily_data[e.date].spend+=e.metrics.spend,l.daily_data[e.date].successful_requests+=e.metrics.successful_requests,l.daily_data[e.date].failed_requests+=e.metrics.failed_requests,l.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,l.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(l.daily_data).map(e=>{let[s,t]=e;return{date:s,metrics:t}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,c.jsxs)("div",{className:"space-y-8",children:[(0,c.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,c.jsx)(S.Z,{children:"Overall Usage"}),(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Requests"}),(0,c.jsx)(S.Z,{children:l.total_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Successful Requests"}),(0,c.jsx)(S.Z,{children:l.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Tokens"}),(0,c.jsx)(S.Z,{children:l.total_tokens.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Total Spend"}),(0,c.jsxs)(S.Z,{children:["$",eE(l.total_spend,2)]})]})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(S.Z,{children:"Total Tokens Over Time"}),(0,c.jsx)(a1,{categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"]})]}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:a$,customTooltip:a0,showLegend:!1})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests Over Time"}),(0,c.jsx)(s6.Z,{className:"mt-4",data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0,customTooltip:a0,showLegend:!1})]})]})]}),(0,c.jsx)(t_.default,{defaultActiveKey:t[0],children:t.map(e=>(0,c.jsx)(t_.default.Panel,{header:(0,c.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,c.jsx)(S.Z,{children:s[e].label||"Unknown Item"}),(0,c.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,c.jsxs)("span",{children:["$",eE(s[e].total_spend,2)]}),(0,c.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," ","requests"]})]})]}),children:(0,c.jsx)(a2,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},a5=(e,s)=>{let t=e.metadata.key_alias||"key-hash-".concat(s),l=e.metadata.team_id;return l?"".concat(t," (team_id: ").concat(l,")"):t},a6=(e,s)=>{let t={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(l=>{let[a,r]=l;t[a]||(t[a]={label:"api_keys"===s?a5(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,top_api_keys:[],daily_data:[]}),t[a].total_requests+=r.metrics.api_requests,t[a].prompt_tokens+=r.metrics.prompt_tokens,t[a].completion_tokens+=r.metrics.completion_tokens,t[a].total_tokens+=r.metrics.total_tokens,t[a].total_spend+=r.metrics.spend,t[a].total_successful_requests+=r.metrics.successful_requests,t[a].total_failed_requests+=r.metrics.failed_requests,t[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,t[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,t[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),"api_keys"!==s&&Object.entries(t).forEach(l=>{let[a,r]=l,i={};e.results.forEach(e=>{var t;let l=null===(t=e.breakdown[s])||void 0===t?void 0:t[a];l&&"api_key_breakdown"in l&&Object.entries(l.api_key_breakdown||{}).forEach(e=>{let[s,t]=e;i[s]||(i[s]={api_key:s,key_alias:t.metadata.key_alias,team_id:t.metadata.team_id,spend:0,requests:0,tokens:0}),i[s].spend+=t.metrics.spend,i[s].requests+=t.metrics.api_requests,i[s].tokens+=t.metrics.total_tokens})}),t[a].top_api_keys=Object.values(i).sort((e,s)=>s.spend-e.spend).slice(0,5)}),Object.values(t).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),t};var a3=e=>{let{accessToken:s,selectedTags:t,formatAbbreviatedNumber:l}=e,[a,r]=(0,d.useState)({results:[],total_count:0,page:1,page_size:50,total_pages:0}),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(1),u=async()=>{if(s){n(!0);try{let e=await (0,j.perUserAnalyticsCall)(s,o,50,t.length>0?t:void 0);r(e)}catch(e){console.error("Failed to fetch per-user data:",e)}finally{n(!1)}}};return(0,d.useEffect)(()=>{u()},[s,t,o]),(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"Per User Usage"}),(0,c.jsx)(sz.Z,{children:"Individual developer usage metrics"}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"User Details"}),(0,c.jsx)(e0.Z,{children:"Usage Distribution"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"User ID"}),(0,c.jsx)(sI.Z,{children:"User Email"}),(0,c.jsx)(sI.Z,{children:"User Agent"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Success Generations"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Total Tokens"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Failed Requests"}),(0,c.jsx)(sI.Z,{className:"text-right",children:"Total Cost"})]})}),(0,c.jsx)(sk.Z,{children:a.results.slice(0,10).map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{className:"font-medium",children:e.user_id})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.user_email||"N/A"})}),(0,c.jsx)(sS.Z,{children:(0,c.jsx)(k.Z,{children:e.user_agent||"Unknown"})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.successful_requests)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.total_tokens)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsx)(k.Z,{children:l(e.failed_requests)})}),(0,c.jsx)(sS.Z,{className:"text-right",children:(0,c.jsxs)(k.Z,{children:["$",l(e.spend,4)]})})]},s))})]}),a.results.length>10&&(0,c.jsxs)("div",{className:"mt-4 flex justify-between items-center",children:[(0,c.jsxs)(k.Z,{className:"text-sm text-gray-500",children:["Showing 10 of ",a.total_count," results"]}),(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:()=>{o>1&&m(o-1)},disabled:1===o,children:"Previous"}),(0,c.jsx)(b.Z,{size:"sm",variant:"secondary",onClick:()=>{o=a.total_pages,children:"Next"})]})]})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsx)(S.Z,{className:"text-lg",children:"User Usage Distribution"}),(0,c.jsx)(sz.Z,{children:"Number of users by successful request frequency"})]}),(0,c.jsx)(s3.Z,{data:(()=>{let e=new Map;a.results.forEach(s=>{let t=s.user_agent||"Unknown";e.set(t,(e.get(t)||0)+1)});let s=Array.from(e.entries()).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).slice(0,8).map(e=>{let[s]=e;return s}),t={"1-9 requests":{range:[1,9],agents:{}},"10-99 requests":{range:[10,99],agents:{}},"100-999 requests":{range:[100,999],agents:{}},"1K-9.9K requests":{range:[1e3,9999],agents:{}},"10K-99.9K requests":{range:[1e4,99999],agents:{}},"100K+ requests":{range:[1e5,1/0],agents:{}}};return a.results.forEach(e=>{let l=e.successful_requests,a=e.user_agent||"Unknown";s.includes(a)&&Object.entries(t).forEach(e=>{let[s,t]=e;l>=t.range[0]&&l<=t.range[1]&&(t.agents[a]||(t.agents[a]=0),t.agents[a]++)})}),Object.entries(t).map(e=>{let[t,l]=e,a={category:t};return s.forEach(e=>{a[e]=l.agents[e]||0}),a})})(),index:"category",categories:(()=>{let e=new Map;return a.results.forEach(s=>{let t=s.user_agent||"Unknown";e.set(t,(e.get(t)||0)+1)}),Array.from(e.entries()).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).slice(0,8).map(e=>{let[s]=e;return s})})(),colors:["blue","green","orange","red","purple","yellow","pink","indigo"],valueFormatter:e=>"".concat(e," users"),yAxisWidth:80,showLegend:!0,stack:!0})]})]})]})]})},a8=t(49096),a7=t(53335);let{cva:a9,cx:re,compose:rs}=(0,a8.ZD)({hooks:{onComplete:e=>(0,a7.m6)(e)}});function rt(e){var s,t;let{className:l="",...a}=e,r=(0,d.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),t=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&t&&(s.currentTime=t.currentTime)},t=[r],(0,d.useLayoutEffect)(s,t),(0,c.jsxs)("svg",{"data-spinner-id":r,className:re("pointer-events-none size-12 animate-spin text-current",l),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,c.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,c.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rl=e=>{let{isDateChanging:s=!1}=e;return(0,c.jsx)("div",{className:"flex items-center justify-center h-40",children:(0,c.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,c.jsx)(rt,{className:"size-5"}),(0,c.jsxs)("div",{className:"flex flex-col",children:[(0,c.jsx)("span",{className:"text-gray-600 text-sm font-medium",children:s?"Processing date selection...":"Loading chart data..."}),(0,c.jsx)("span",{className:"text-gray-400 text-xs mt-1",children:s?"This will only take a moment":"Fetching your data"})]})]})})};var ra=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)({results:[]}),[r,i]=(0,d.useState)({results:[]}),[n,o]=(0,d.useState)({results:[]}),[m,u]=(0,d.useState)({results:[]}),[x,h]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)([]),[b,_]=(0,d.useState)([]),[N,Z]=(0,d.useState)(!1),[w,C]=(0,d.useState)(!1),[A,L]=(0,d.useState)(!1),[T,P]=(0,d.useState)(!1),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)(!1),F=new Date,R=async()=>{if(s){Z(!0);try{let e=await (0,j.tagDistinctCall)(s);v(e.results.map(e=>e.tag))}catch(e){console.error("Failed to fetch available tags:",e)}finally{Z(!1)}}},z=async()=>{if(s){C(!0);try{let e=await (0,j.tagDauCall)(s,F,p||void 0,b.length>0?b:void 0);a(e)}catch(e){console.error("Failed to fetch DAU data:",e)}finally{C(!1)}}},U=async()=>{if(s){L(!0);try{let e=await (0,j.tagWauCall)(s,F,p||void 0,b.length>0?b:void 0);i(e)}catch(e){console.error("Failed to fetch WAU data:",e)}finally{L(!1)}}},q=async()=>{if(s){P(!0);try{let e=await (0,j.tagMauCall)(s,F,p||void 0,b.length>0?b:void 0);o(e)}catch(e){console.error("Failed to fetch MAU data:",e)}finally{P(!1)}}},B=async()=>{if(s&&x.from&&x.to){M(!0);try{let e=await (0,j.userAgentSummaryCall)(s,x.from,x.to,b.length>0?b:void 0);u(e)}catch(e){console.error("Failed to fetch user agent summary data:",e)}finally{M(!1),D(!1)}}};(0,d.useEffect)(()=>{R()},[s]),(0,d.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>{z(),U(),q()},50);return()=>clearTimeout(e)},[s,p,b]),(0,d.useEffect)(()=>{if(!x.from||!x.to)return;let e=setTimeout(()=>{B()},50);return()=>clearTimeout(e)},[s,x,b]);let K=e=>e.startsWith("User-Agent: ")?e.replace("User-Agent: ",""):e,H=e=>e.length>15?e.substring(0,15)+"...":e,J=e=>Object.entries(e.reduce((e,s)=>(e[s.tag]=(e[s.tag]||0)+s.active_users,e),{})).sort((e,s)=>{let[,t]=e,[,l]=s;return l-t}).map(e=>{let[s]=e;return s}),Y=J(l.results).slice(0,10),W=J(r.results).slice(0,10),$=J(n.results).slice(0,10),Q=(()=>{let e=[],s=new Date;for(let t=6;t>=0;t--){let l=new Date(s);l.setDate(l.getDate()-t);let a={date:l.toISOString().split("T")[0]};Y.forEach(e=>{a[K(e)]=0}),e.push(a)}return l.results.forEach(s=>{let t=K(s.tag),l=e.find(e=>e.date===s.date);l&&(l[t]=s.active_users)}),e})(),X=(()=>{let e=[];for(let s=1;s<=7;s++){let t={week:"Week ".concat(s)};W.forEach(e=>{t[K(e)]=0}),e.push(t)}return r.results.forEach(s=>{let t=K(s.tag),l=s.date.match(/Week (\d+)/);if(l){let a="Week ".concat(l[1]),r=e.find(e=>e.week===a);r&&(r[t]=s.active_users)}}),e})(),ee=(()=>{let e=[];for(let s=1;s<=7;s++){let t={month:"Month ".concat(s)};$.forEach(e=>{t[K(e)]=0}),e.push(t)}return n.results.forEach(s=>{let t=K(s.tag),l=s.date.match(/Month (\d+)/);if(l){let a="Month ".concat(l[1]),r=e.find(e=>e.month===a);r&&(r[t]=s.active_users)}}),e})(),es=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e>=1e8||e>=1e7||e>=1e6?(e/1e6).toFixed(s)+"M":e>=1e4?(e/1e3).toFixed(s)+"K":e>=1e3?(e/1e3).toFixed(s)+"K":e.toFixed(s)};return(0,c.jsxs)("div",{className:"space-y-6 mt-6",children:[(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"flex justify-between items-start",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Summary by User Agent"}),(0,c.jsx)(sz.Z,{children:"Performance metrics for different user agents"})]}),(0,c.jsxs)("div",{className:"w-96",children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium block mb-2",children:"Filter by User Agents"}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"All User Agents",value:b,onChange:_,style:{width:"100%"},showSearch:!0,allowClear:!0,loading:N,optionFilterProp:"label",className:"rounded-md",maxTagCount:"responsive",children:f.map(e=>{let s=K(e),t=s.length>50?"".concat(s.substring(0,50),"..."):s;return(0,c.jsx)(I.default.Option,{value:e,label:t,title:s,children:t},e)})})]})]}),(0,c.jsx)(aH,{value:x,onValueChange:e=>{D(!0),M(!0),h(e)}}),E?(0,c.jsx)(rl,{isDateChanging:O}):(0,c.jsxs)(y.Z,{numItems:4,className:"gap-4",children:[(m.results||[]).slice(0,4).map((e,s)=>{let t=K(e.tag),l=H(t);return(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(V.Z,{title:t,placement:"top",children:(0,c.jsx)(S.Z,{className:"truncate",children:l})}),(0,c.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Success Requests"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:es(e.successful_requests)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Tokens"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:es(e.total_tokens)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Cost"}),(0,c.jsxs)(aw.Z,{className:"text-lg",children:["$",es(e.total_spend,4)]})]})]})]},s)}),Array.from({length:Math.max(0,4-(m.results||[]).length)}).map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"No Data"}),(0,c.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Success Requests"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Tokens"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm text-gray-600",children:"Total Cost"}),(0,c.jsx)(aw.Z,{className:"text-lg",children:"-"})]})]})]},"empty-".concat(s)))]})]})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"DAU/WAU/MAU"}),(0,c.jsx)(e0.Z,{children:"Per User Usage (Last 30 Days)"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(S.Z,{children:"DAU, WAU & MAU per Agent"}),(0,c.jsx)(sz.Z,{children:"Active users across different time periods"})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"DAU"}),(0,c.jsx)(e0.Z,{children:"WAU"}),(0,c.jsx)(e0.Z,{children:"MAU"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Daily Active Users - Last 7 Days"})}),w?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:Q,index:"date",categories:Y.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Weekly Active Users - Last 7 Weeks"})}),A?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:X,index:"week",categories:W.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(S.Z,{className:"text-lg",children:"Monthly Active Users - Last 7 Months"})}),T?(0,c.jsx)(rl,{isDateChanging:!1}):(0,c.jsx)(s3.Z,{data:ee,index:"month",categories:$.map(K),valueFormatter:e=>es(e),yAxisWidth:60,showLegend:!0,stack:!0})]})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a3,{accessToken:s,selectedTags:b,formatAbbreviatedNumber:es})})]})]})})]})},rr=e=>{let{accessToken:s,entityType:t,entityId:l,userID:a,userRole:r,entityList:i,premiumUser:n}=e,[o,m]=(0,d.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),u=a6(o,"models"),x=a6(o,"api_keys"),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)({from:new Date(Date.now()-24192e5),to:new Date}),b=async()=>{if(!s||!g.from||!g.to)return;let e=new Date(g.from),l=new Date(g.to);if("tag"===t)m(await (0,j.tagDailyActivityCall)(s,e,l,1,h.length>0?h:null));else if("team"===t)m(await (0,j.teamDailyActivityCall)(s,e,l,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,d.useEffect)(()=>{b()},[s,g,l,h]);let _=()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={provider:t,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[t].spend+=l.metrics.spend,e[t].requests+=l.metrics.api_requests,e[t].successful_requests+=l.metrics.successful_requests,e[t].failed_requests+=l.metrics.failed_requests,e[t].tokens+=l.metrics.total_tokens}catch(e){console.error("Error processing provider ".concat(t,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},N=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),Z=()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:l.metadata.team_alias||t,id:t}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.total_tokens+=l.metrics.total_tokens})}),N(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,c.jsxs)("div",{style:{width:"100%"},children:[(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(aH,{value:g,onValueChange:f})}),i&&i.length>0&&(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(k.Z,{children:["Filter by ","tag"===t?"Tags":"Teams"]}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===t?"tags":"teams"," to filter..."),value:h,onChange:p,options:(()=>{if(i)return i})(),className:"mt-2",allowClear:!0})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Model Activity"}),(0,c.jsx)(e0.Z,{children:"Key Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full",children:[(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(S.Z,{children:["tag"===t?"Tag":"Team"," Spend Overview"]}),(0,c.jsxs)(y.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Spend"}),(0,c.jsxs)(k.Z,{className:"text-2xl font-bold mt-2",children:["$",eE(o.metadata.total_spend,2)]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:o.metadata.total_api_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Successful Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:o.metadata.total_successful_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Failed Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:o.metadata.total_failed_requests.toLocaleString()})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:o.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend"}),(0,c.jsx)(s3.Z,{data:[...o.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let a=s[0].payload,r=Object.keys(a.breakdown.entities||{}).length;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:a.date}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",eE(a.metrics.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["tag"===t?"Total Tags":"Total Teams",": ",r]}),(0,c.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,c.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===t?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).sort((e,s)=>{let[,t]=e,[,l]=s,a=t.metrics.spend;return l.metrics.spend-a}).slice(0,5).map(e=>{let[s,t]=e;return(0,c.jsxs)("p",{className:"text-sm text-gray-600",children:[t.metadata.team_alias||s,": $",eE(t.metrics.spend,2)]},s)}),r>5&&(0,c.jsxs)("p",{className:"text-sm text-gray-500 italic",children:["...and ",r-5," more"]})]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,c.jsxs)(S.Z,{children:["Spend Per ","tag"===t?"Tag":"Team"]}),(0,c.jsx)(sz.Z,{className:"text-xs",children:"Showing Top 5 by Spend"}),(0,c.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,c.jsxs)("span",{children:["Get Started by Tracking cost per ",t," "]}),(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#spend-tracking",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-6",children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(s3.Z,{className:"mt-4 h-52",data:Z().slice(0,5).map(e=>({...e,metadata:{...e.metadata,alias_display:e.metadata.alias&&e.metadata.alias.length>15?"".concat(e.metadata.alias.slice(0,15),"..."):e.metadata.alias}})),index:"metadata.alias_display",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,layout:"vertical",showLegend:!1,yAxisWidth:150,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.metadata.alias}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.metrics.spend,4)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Requests:"," ",l.metrics.api_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-green-600",children:["Successful:"," ",l.metrics.successful_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-red-600",children:["Failed:"," ",l.metrics.failed_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens:"," ",l.metrics.total_tokens.toLocaleString()]})]})}})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)("div",{className:"h-52 overflow-y-auto",children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"tag"===t?"Tag":"Team"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:Z().filter(e=>e.metrics.spend>0).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.metadata.alias}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.metrics.spend,4)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})})]})]})})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:(()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:l.metadata.key_alias,team_id:l.metadata.team_id||null}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{api_key:s,key_alias:t.metadata.key_alias||"-",spend:t.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null,premiumUser:n})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Top Models"}),(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:(()=>{let e={};return o.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[t].spend+=l.metrics.spend}catch(e){console.error("Error adding spend for ".concat(t,": ").concat(e,", got metrics: ").concat(JSON.stringify(l)))}e[t].requests+=l.metrics.api_requests,e[t].successful_requests+=l.metrics.successful_requests,e[t].failed_requests+=l.metrics.failed_requests,e[t].tokens+=l.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,...t}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"display_key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(eE(e,2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,c.jsx)(S.Z,{children:"Provider Usage"}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",data:_(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(eE(e,2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:_().map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[e.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(e.provider).logo,alt:"".concat(e.provider," logo"),className:"w-4 h-4",onError:s=>{let t=s.target,l=t.parentElement;if(l){var a;let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=(null===(a=e.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e.provider})]})}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.spend,2)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:u})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:x})})]})]})]})},ri=e=>{let{isOpen:s,onClose:t,accessToken:l}=e,[a]=A.Z.useForm(),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)("cloudzero"),[p,g]=(0,d.useState)(!1);(0,d.useEffect)(()=>{s&&l&&j()},[s,l]);let j=async()=>{u(!0);try{let e=await fetch("/cloudzero/settings",{method:"GET",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(e.ok){let s=await e.json();o(s),a.setFieldsValue({connection_id:s.connection_id})}else if(404!==e.status){let s=await e.json();eo.Z.fromBackend("Failed to load existing settings: ".concat(s.error||"Unknown error"))}}catch(e){console.error("Error loading CloudZero settings:",e),eo.Z.fromBackend("Failed to load existing settings")}finally{u(!1)}},f=async e=>{if(!l){eo.Z.fromBackend("No access token available");return}i(!0);try{let s={...e,timezone:"UTC"},t=await fetch(n?"/cloudzero/settings":"/cloudzero/init",{method:n?"PUT":"POST",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify(s)}),a=await t.json();if(t.ok)return eo.Z.success(a.message||"CloudZero settings saved successfully"),o({api_key_masked:e.api_key.substring(0,4)+"****"+e.api_key.slice(-4),connection_id:e.connection_id,status:"configured"}),!0;return eo.Z.fromBackend(a.error||"Failed to save CloudZero settings"),!1}catch(e){return console.error("Error saving CloudZero settings:",e),eo.Z.fromBackend("Failed to save CloudZero settings"),!1}finally{i(!1)}},v=async()=>{if(!l){eo.Z.fromBackend("No access token available");return}g(!0);try{let e=await fetch("/cloudzero/export",{method:"POST",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({limit:1e5,operation:"replace_hourly"})}),s=await e.json();e.ok?(eo.Z.success(s.message||"Export to CloudZero completed successfully"),t()):eo.Z.fromBackend(s.error||"Failed to export to CloudZero")}catch(e){console.error("Error exporting to CloudZero:",e),eo.Z.fromBackend("Failed to export to CloudZero")}finally{g(!1)}},y=async()=>{g(!0);try{eo.Z.info("CSV export functionality coming soon!"),t()}catch(e){console.error("Error exporting CSV:",e),eo.Z.fromBackend("Failed to export CSV")}finally{g(!1)}},N=async()=>{if("cloudzero"===x){if(!n){let e=await a.validateFields();if(!await f(e))return}await v()}else await y()},Z=()=>{a.resetFields(),h("cloudzero"),o(null),t()},w=[{value:"cloudzero",label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("img",{src:"/cloudzero.png",alt:"CloudZero",className:"w-5 h-5",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)("span",{children:"Export to CloudZero"})]})},{value:"csv",label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,c.jsx)("span",{children:"Export to CSV"})]})}];return(0,c.jsx)(L.Z,{title:"Export Data",open:s,onCancel:Z,footer:null,width:600,destroyOnClose:!0,children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium mb-2 block",children:"Export Destination"}),(0,c.jsx)(I.default,{value:x,onChange:h,options:w,className:"w-full",size:"large"})]}),"cloudzero"===x&&(0,c.jsx)("div",{children:m?(0,c.jsx)("div",{className:"flex justify-center py-8",children:(0,c.jsx)(lI.Z,{size:"large"})}):(0,c.jsxs)(c.Fragment,{children:[n&&(0,c.jsx)(lB.Z,{title:"Existing CloudZero Configuration",icon:()=>(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),color:"green",className:"mb-4",children:(0,c.jsxs)(k.Z,{children:["API Key: ",n.api_key_masked,(0,c.jsx)("br",{}),"Connection ID: ",n.connection_id]})}),!n&&(0,c.jsxs)(A.Z,{form:a,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"CloudZero API Key",name:"api_key",rules:[{required:!0,message:"Please enter your CloudZero API key"}],children:(0,c.jsx)(_.Z,{type:"password",placeholder:"Enter your CloudZero API key"})}),(0,c.jsx)(A.Z.Item,{label:"Connection ID",name:"connection_id",rules:[{required:!0,message:"Please enter the CloudZero connection ID"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter CloudZero connection ID"})})]})]})}),"csv"===x&&(0,c.jsx)(lB.Z,{title:"CSV Export",icon:()=>(0,c.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),color:"blue",children:(0,c.jsx)(k.Z,{children:"Export your usage data as a CSV file for analysis in spreadsheet applications."})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 pt-4",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:Z,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:N,loading:r||p,disabled:r||p,children:"cloudzero"===x?"Export to CloudZero":"Export CSV"})]})]})})},rn=e=>{var s,t,l,a,r,i,n,o,m,u;let{accessToken:x,userRole:h,userID:p,teams:g,premiumUser:f}=e,[b,_]=(0,d.useState)({results:[],metadata:{}}),[N,Z]=(0,d.useState)(!1),[w,C]=(0,d.useState)(!1),I=(0,d.useMemo)(()=>new Date(Date.now()-6048e5),[]),A=(0,d.useMemo)(()=>new Date,[]),[L,T]=(0,d.useState)({from:I,to:A}),[P,E]=(0,d.useState)([]),[M,O]=(0,d.useState)("groups"),[D,F]=(0,d.useState)(!1),R=async()=>{x&&E(Object.values(await (0,j.tagListCall)(x)).map(e=>({label:e.name,value:e.name})))};(0,d.useEffect)(()=>{R()},[x]);let z=(null===(s=b.metadata)||void 0===s?void 0:s.total_spend)||0,U=()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{provider:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}})},q=(0,d.useCallback)(async()=>{if(!x||!L.from||!L.to)return;Z(!0);let e=new Date(L.from),s=new Date(L.to);try{try{let t=await (0,j.userDailyActivityAggregatedCall)(x,e,s);_(t);return}catch(e){}let t=await (0,j.userDailyActivityCall)(x,e,s);if(t.metadata.total_pages<=1){_(t);return}let l=[...t.results],a={...t.metadata};for(let r=2;r<=t.metadata.total_pages;r++){let t=await (0,j.userDailyActivityCall)(x,e,s,r);l.push(...t.results),t.metadata&&(a.total_spend+=t.metadata.total_spend||0,a.total_api_requests+=t.metadata.total_api_requests||0,a.total_successful_requests+=t.metadata.total_successful_requests||0,a.total_failed_requests+=t.metadata.total_failed_requests||0,a.total_tokens+=t.metadata.total_tokens||0)}_({results:l,metadata:a})}catch(e){console.error("Error fetching user spend data:",e)}finally{Z(!1),C(!1)}},[x,L.from,L.to]),B=(0,d.useCallback)(e=>{C(!0),Z(!0),T(e)},[]);(0,d.useEffect)(()=>{if(!L.from||!L.to)return;let e=setTimeout(()=>{q()},50);return()=>clearTimeout(e)},[q]);let V=a6(b,"models"),K=a6(b,"api_keys"),H=a6(b,"mcp_servers");return(0,c.jsxs)("div",{style:{width:"100%"},className:"p-8 relative",children:[(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"Global Usage"}):(0,c.jsx)(e0.Z,{children:"Your Usage"}),(0,c.jsx)(e0.Z,{children:"Team Usage"}),eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"Tag Usage"}):(0,c.jsx)(c.Fragment,{}),eI.ZL.includes(h||"")?(0,c.jsx)(e0.Z,{children:"User Agent Activity"}):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsx)(y.Z,{numItems:2,className:"gap-10 w-1/2 mb-4",children:(0,c.jsx)(v.Z,{children:(0,c.jsx)(aH,{value:L,onValueChange:B})})}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Model Activity"}),(0,c.jsx)(e0.Z,{children:"Key Activity"}),(0,c.jsx)(e0.Z,{children:"MCP Server Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(k.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,c.jsx)(aJ,{userID:p,userRole:h,accessToken:x,userSpend:z,selectedTeam:null,userMaxBudget:null})]}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Usage Metrics"}),(0,c.jsxs)(y.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:(null===(l=b.metadata)||void 0===l?void 0:null===(t=l.total_api_requests)||void 0===t?void 0:t.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Successful Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=b.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Failed Requests"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(n=b.metadata)||void 0===n?void 0:null===(i=n.total_failed_requests)||void 0===i?void 0:i.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Total Tokens"}),(0,c.jsx)(k.Z,{className:"text-2xl font-bold mt-2",children:(null===(m=b.metadata)||void 0===m?void 0:null===(o=m.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Average Cost per Request"}),(0,c.jsxs)(k.Z,{className:"text-2xl font-bold mt-2",children:["$",eE((z||0)/((null===(u=b.metadata)||void 0===u?void 0:u.total_api_requests)||1),4)]})]})]})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend"}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsx)(s3.Z,{data:[...b.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:aQ,yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.date}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.metrics.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Requests: ",l.metrics.api_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Successful: ",l.metrics.successful_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Failed: ",l.metrics.failed_requests]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",l.metrics.total_tokens]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:l.metadata.key_alias,team_id:null}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests,e[t].metrics.failed_requests+=l.metrics.failed_requests,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{api_key:s,key_alias:t.metadata.key_alias||"-",spend:t.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:x,userID:p,userRole:h,teams:null,premiumUser:f})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"groups"===M?"Top Public Model Names":"Top Litellm Models"}),(0,c.jsxs)("div",{className:"flex bg-gray-100 rounded-lg p-1",children:[(0,c.jsx)("button",{className:"px-3 py-1 text-sm rounded-md transition-colors ".concat("groups"===M?"bg-white shadow-sm text-gray-900":"text-gray-600 hover:text-gray-900"),onClick:()=>O("groups"),children:"Public Model Name"}),(0,c.jsx)("button",{className:"px-3 py-1 text-sm rounded-md transition-colors ".concat("individual"===M?"bg-white shadow-sm text-gray-900":"text-gray-600 hover:text-gray-900"),onClick:()=>O("individual"),children:"Litellm Model Name"})]})]}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:"groups"===M?(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.model_groups||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})():(()=>{let e={};return b.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[t,l]=s;e[t]||(e[t]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{},api_key_breakdown:{}}),e[t].metrics.spend+=l.metrics.spend,e[t].metrics.prompt_tokens+=l.metrics.prompt_tokens,e[t].metrics.completion_tokens+=l.metrics.completion_tokens,e[t].metrics.total_tokens+=l.metrics.total_tokens,e[t].metrics.api_requests+=l.metrics.api_requests,e[t].metrics.successful_requests+=l.metrics.successful_requests||0,e[t].metrics.failed_requests+=l.metrics.failed_requests||0,e[t].metrics.cache_read_input_tokens+=l.metrics.cache_read_input_tokens||0,e[t].metrics.cache_creation_input_tokens+=l.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,t]=e;return{key:s,spend:t.metrics.spend,requests:t.metrics.api_requests,successful_requests:t.metrics.successful_requests,failed_requests:t.metrics.failed_requests,tokens:t.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:aQ,layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let l=s[0].payload;return(0,c.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,c.jsx)("p",{className:"font-bold",children:l.key}),(0,c.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",eE(l.spend,2)]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",l.requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-green-600",children:["Successful: ",l.successful_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-red-600",children:["Failed: ",l.failed_requests.toLocaleString()]}),(0,c.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",l.tokens.toLocaleString()]})]})}})]})}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(S.Z,{children:"Spend by Provider"})}),N?(0,c.jsx)(rl,{isDateChanging:w}):(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",data:U(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(eE(e,2)),colors:["cyan"]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{className:"text-green-600",children:"Successful"}),(0,c.jsx)(sI.Z,{className:"text-red-600",children:"Failed"}),(0,c.jsx)(sI.Z,{children:"Tokens"})]})}),(0,c.jsx)(sk.Z,{children:U().filter(e=>e.spend>0).map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[e.provider&&(0,c.jsx)("img",{src:(0,sU.dr)(e.provider).logo,alt:"".concat(e.provider," logo"),className:"w-4 h-4",onError:s=>{let t=s.target,l=t.parentElement;if(l){var a;let s=document.createElement("div");s.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",s.textContent=(null===(a=e.provider)||void 0===a?void 0:a.charAt(0))||"-",l.replaceChild(s,t)}}}),(0,c.jsx)("span",{children:e.provider})]})}),(0,c.jsxs)(sS.Z,{children:["$",eE(e.spend,2)]}),(0,c.jsx)(sS.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,c.jsx)(sS.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:V})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:K})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(a4,{modelMetrics:H})})]})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(rr,{accessToken:x,entityType:"team",userID:p,userRole:h,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null,premiumUser:f})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(rr,{accessToken:x,entityType:"tag",userID:p,userRole:h,entityList:P,premiumUser:f})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(ra,{accessToken:x,userRole:h})})]})]}),(0,c.jsx)(ri,{isOpen:D,onClose:()=>F(!1),accessToken:x})]})},ro=e=>{let{proxySettings:s}=e,t="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(t=s.PROXY_BASE_URL),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,c.jsxs)("div",{className:"mb-5",children:[(0,c.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,c.jsx)(k.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,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{children:[(0,c.jsx)(e0.Z,{children:"OpenAI Python SDK"}),(0,c.jsx)(e0.Z,{children:"LlamaIndex"}),(0,c.jsx)(e0.Z,{children:"Langchain Py"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(am.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(t,'" # 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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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(t,'", # 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(t,'",\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,c.jsx)(e4.Z,{children:(0,c.jsx)(am.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(t,'",\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 ')})})]})]})]})})})},rc=t(243),rd=t(93837);async function rm(e,s,t,l,a,r,i,n,o,c,d,m,u,x){console.log=function(){},console.log("isLocal:",!1);let h=(0,j.getProxyBaseUrl)(),p={};a&&a.length>0&&(p["x-litellm-tags"]=a.join(","));let g=new aa.ZP.OpenAI({apiKey:l,baseURL:h,dangerouslyAllowBrowser:!0,defaultHeaders:p});try{let a;let p=Date.now(),j=!1,k=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"".concat(h,"/mcp"),require_approval:"never",allowed_tools:u,headers:{"x-litellm-api-key":"Bearer ".concat(l)}}]:void 0;for await(let l of(await g.chat.completions.create({model:t,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:c,messages:e,...d?{vector_store_ids:d}:{},...m?{guardrails:m}:{},...k?{tools:k,tool_choice:"auto"}:{}},{signal:r}))){var f,v,y,b,_,N,Z,w;console.log("Stream chunk:",l);let e=null===(f=l.choices[0])||void 0===f?void 0:f.delta;if(console.log("Delta content:",null===(y=l.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!j&&((null===(_=l.choices[0])||void 0===_?void 0:null===(b=_.delta)||void 0===b?void 0:b.content)||e&&e.reasoning_content)&&(j=!0,a=Date.now()-p,console.log("First token received! Time:",a,"ms"),n?(console.log("Calling onTimingData with:",a),n(a)):console.log("onTimingData callback is not defined!")),null===(Z=l.choices[0])||void 0===Z?void 0:null===(N=Z.delta)||void 0===N?void 0:N.content){let e=l.choices[0].delta.content;s(e,l.model)}if(e&&e.image&&x&&(console.log("Image generated:",e.image),x(e.image.url,l.model)),e&&e.reasoning_content){let s=e.reasoning_content;i&&i(s)}if(l.usage&&o){console.log("Usage data found:",l.usage);let e={completionTokens:l.usage.completion_tokens,promptTokens:l.usage.prompt_tokens,totalTokens:l.usage.total_tokens};(null===(w=l.usage.completion_tokens_details)||void 0===w?void 0:w.reasoning_tokens)&&(e.reasoningTokens=l.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function ru(e,s,t,l,a,r){console.log=function(){},console.log("isLocal:",!1);let i=(0,j.getProxyBaseUrl)(),n=new aa.ZP.OpenAI({apiKey:l,baseURL:i,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let l=await n.images.generate({model:t,prompt:e},{signal:r});if(console.log(l.data),l.data&&l.data[0]){if(l.data[0].url)s(l.data[0].url,t);else if(l.data[0].b64_json){let e=l.data[0].b64_json;s("data:image/png;base64,".concat(e),t)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):eo.Z.fromBackend("Error occurred while generating image. Please try again. Error: ".concat(e)),e}}async function rx(e,s,t,l,a,r,i){console.log=function(){},console.log("isLocal:",!1);let n=(0,j.getProxyBaseUrl)(),o=new aa.ZP.OpenAI({apiKey:a,baseURL:n,dangerouslyAllowBrowser:!0,defaultHeaders:r&&r.length>0?{"x-litellm-tags":r.join(",")}:void 0});try{let a=Array.isArray(e)?e:[e],r=[];for(let e=0;e1&&eo.Z.success("Successfully processed ".concat(r.length," images"))}catch(e){if(console.error("Error making image edit request:",e),null==i?void 0:i.aborted)console.log("Image edits request was cancelled");else{var c;let s="Failed to edit image(s)";(null==e?void 0:null===(c=e.error)||void 0===c?void 0:c.message)?s=e.error.message:(null==e?void 0:e.message)&&(s=e.message),eo.Z.fromBackend("Image edit failed: ".concat(s))}throw e}}async function rh(e,s,t,l){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,c=arguments.length>9?arguments[9]:void 0,d=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0,u=arguments.length>12?arguments[12]:void 0,x=arguments.length>13?arguments[13]:void 0,h=arguments.length>14?arguments[14]:void 0,p=arguments.length>15?arguments[15]:void 0;if(!l)throw Error("API key is required");console.log=function(){};let g=(0,j.getProxyBaseUrl)(),f={};a&&a.length>0&&(f["x-litellm-tags"]=a.join(","));let v=new aa.ZP.OpenAI({apiKey:l,baseURL:g,dangerouslyAllowBrowser:!0,defaultHeaders:f});try{let l=Date.now(),a=!1,g=e.map(e=>(Array.isArray(e.content),{role:e.role,content:e.content,type:"message"})),j=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"litellm_proxy/mcp",require_approval:"never",allowed_tools:u}]:void 0,f=await v.responses.create({model:t,input:g,stream:!0,litellm_trace_id:c,...x?{previous_response_id:x}:{},...d?{vector_store_ids:d}:{},...m?{guardrails:m}:{},...j?{tools:j,tool_choice:"required"}:{}},{signal:r}),S="";for await(let e of f)if(console.log("Response event:",e),"object"==typeof e&&null!==e){var y,b,_,N,Z,w,k;if(((null===(y=e.type)||void 0===y?void 0:y.startsWith("response.mcp_"))||"response.output_item.done"===e.type&&((null===(b=e.item)||void 0===b?void 0:b.type)==="mcp_list_tools"||(null===(_=e.item)||void 0===_?void 0:_.type)==="mcp_call"))&&(console.log("MCP event received:",e),p)){let s={type:e.type,sequence_number:e.sequence_number,output_index:e.output_index,item_id:e.item_id||(null===(w=e.item)||void 0===w?void 0:w.id),item:e.item,delta:e.delta,arguments:e.arguments,timestamp:Date.now()};p(s)}if("response.output_item.done"===e.type&&(null===(N=e.item)||void 0===N?void 0:N.type)==="mcp_call"&&(null===(Z=e.item)||void 0===Z?void 0:Z.name)&&(S=e.item.name,console.log("MCP tool used:",S)),"response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,t),!a)){a=!0;let e=Date.now()-l;console.log("First token received! Time:",e,"ms"),n&&n(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&i&&i(s)}if("response.completed"===e.type&&"response"in e){let s=e.response,t=s.usage;if(console.log("Usage data:",t),console.log("Response completed event:",s),s.id&&h&&(console.log("Response ID for session management:",s.id),h(s.id)),t&&o){console.log("Usage data:",t);let e={completionTokens:t.output_tokens,promptTokens:t.input_tokens,totalTokens:t.total_tokens};(null===(k=t.completion_tokens_details)||void 0===k?void 0:k.reasoning_tokens)&&(e.reasoningTokens=t.completion_tokens_details.reasoning_tokens),o(e,S)}}}return f}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e)),e}}var rp=t(85498);async function rg(e,s,t,l){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,c=arguments.length>9?arguments[9]:void 0,d=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0,u=arguments.length>12?arguments[12]:void 0;if(!l)throw Error("API key is required");console.log=function(){};let x=(0,j.getProxyBaseUrl)(),h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let p=new rp.ZP({apiKey:l,baseURL:x,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let a=Date.now(),h=!1,g=u&&u.length>0?[{type:"mcp",server_label:"litellm",server_url:"".concat(x,"/mcp"),require_approval:"never",allowed_tools:u,headers:{"x-litellm-api-key":"Bearer ".concat(l)}}]:void 0,j={model:t,messages:e.map(e=>({role:e.role,content:e.content})),stream:!0,max_tokens:1024,litellm_trace_id:c};for await(let e of(d&&(j.vector_store_ids=d),m&&(j.guardrails=m),g&&(j.tools=g,j.tool_choice="auto"),p.messages.stream(j,{signal:r}))){if(console.log("Stream event:",e),"content_block_delta"===e.type){let l=e.delta;if(!h){h=!0;let e=Date.now()-a;console.log("First token received! Time:",e,"ms"),n&&n(e)}"text_delta"===l.type?s("assistant",l.text,t):"reasoning_delta"===l.type&&i&&i(l.text)}if("message_delta"===e.type&&e.usage&&o){let s=e.usage;console.log("Usage data found:",s);let t={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.input_tokens+s.output_tokens};o(t)}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Anthropic messages request was cancelled"):eo.Z.fromBackend("Error occurred while generating model response. Please try again. Error: ".concat(e)),e}}async function rj(e){try{return(await (0,j.mcpToolsCall)(e)).tools||[]}catch(e){return console.error("Error fetching MCP tools:",e),[]}}var rf=t(49817),rv=t(94263),ry=e=>{let{endpointType:s,onEndpointChange:t,className:l}=e,a=[{value:rf.KP.CHAT,label:"/v1/chat/completions"},{value:rf.KP.RESPONSES,label:"/v1/responses"},{value:rf.KP.ANTHROPIC_MESSAGES,label:"/v1/messages"},{value:rf.KP.IMAGE,label:"/v1/images/generations"},{value:rf.KP.IMAGE_EDITS,label:"/v1/images/edits"}];return(0,c.jsxs)("div",{className:l,children:[(0,c.jsx)(k.Z,{children:"Endpoint Type:"}),(0,c.jsx)(I.default,{showSearch:!0,value:s,style:{width:"100%"},onChange:t,options:a,className:"rounded-md"})]})},rb=e=>{let{onChange:s,value:t,className:l,accessToken:a}=e,[r,i]=(0,d.useState)([]),[n,o]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,j.tagListCall)(a);console.log("List tags response:",e),i(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:t,loading:n,className:l,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},r_=t(88658),rN=t(83322),rZ=e=>{let{reasoningContent:s}=e,[t,l]=(0,d.useState)(!0);return s?(0,c.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,c.jsxs)(P.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>l(!t),icon:(0,c.jsx)(rN.Z,{}),children:[t?"Hide reasoning":"Show reasoning",t?(0,c.jsx)(tZ.Z,{className:"ml-1"}):(0,c.jsx)(la.Z,{className:"ml-1"})]}),t&&(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,c.jsx)(rc.U,{components:{code(e){let{node:s,inline:t,className:l,children:a,...r}=e,i=/language-(\w+)/.exec(l||"");return!t&&i?(0,c.jsx)(am.Z,{style:rv.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,c.jsx)("code",{className:"".concat(l," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},rw=t(71282),rk=t(11741),rS=t(16601),rC=t(58630),rI=e=>{let{timeToFirstToken:s,usage:t,toolName:l}=e;return s||t?(0,c.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,c.jsx)(V.Z,{title:"Time to first token",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(t2.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==t?void 0:t.promptTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Prompt tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rw.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["In: ",t.promptTokens]})]})}),(null==t?void 0:t.completionTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Completion tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rk.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Out: ",t.completionTokens]})]})}),(null==t?void 0:t.reasoningTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Reasoning tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rN.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Reasoning: ",t.reasoningTokens]})]})}),(null==t?void 0:t.totalTokens)!==void 0&&(0,c.jsx)(V.Z,{title:"Total tokens",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rS.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Total: ",t.totalTokens]})]})}),l&&(0,c.jsx)(V.Z,{title:"Tool used",children:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-1"}),(0,c.jsxs)("span",{children:["Tool: ",l]})]})})]}):null},rA=t(53508);let{Dragger:rL}=ed.default;var rT=e=>{let{responsesUploadedImage:s,responsesImagePreviewUrl:t,onImageUpload:l,onRemoveImage:a}=e;return(0,c.jsx)(c.Fragment,{children:!s&&(0,c.jsx)(rL,{beforeUpload:l,accept:"image/*,.pdf",showUploadList:!1,className:"inline-block",style:{padding:0,border:"none",background:"none"},children:(0,c.jsx)(V.Z,{title:"Attach image or PDF",children:(0,c.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-md transition-colors",children:(0,c.jsx)(rA.Z,{style:{fontSize:"16px"}})})})})})};let rP=e=>new Promise((s,t)=>{let l=new FileReader;l.onload=()=>{s(l.result.split(",")[1])},l.onerror=t,l.readAsDataURL(e)}),rE=async(e,s)=>{let t=await rP(s),l=s.type||(s.name.toLowerCase().endsWith(".pdf")?"application/pdf":"image/jpeg");return{role:"user",content:[{type:"input_text",text:e},{type:"input_image",image_url:"data:".concat(l,";base64,").concat(t)}]}},rM=(e,s,t,l)=>{let a="";s&&l&&(a=l.toLowerCase().endsWith(".pdf")?"[PDF attached]":"[Image attached]");let r={role:"user",content:s?"".concat(e," ").concat(a):e};return s&&t&&(r.imagePreviewUrl=t),r},rO=e=>"user"===e.role&&"string"==typeof e.content&&(e.content.includes("[Image attached]")||e.content.includes("[PDF attached]"))&&!!e.imagePreviewUrl;var rD=t(50010),rF=e=>{let{message:s}=e;if(!rO(s))return null;let t="string"==typeof s.content&&s.content.includes("[PDF attached]");return(0,c.jsx)("div",{className:"mb-2",children:t?(0,c.jsx)("div",{className:"w-64 h-32 rounded-md border border-gray-200 bg-red-50 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"48px",color:"#dc2626"}})}):(0,c.jsx)("img",{src:s.imagePreviewUrl,alt:"User uploaded image",className:"max-w-64 rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"200px"}})})};let{Dragger:rR}=ed.default;var rz=e=>{let{chatUploadedImage:s,chatImagePreviewUrl:t,onImageUpload:l,onRemoveImage:a}=e;return(0,c.jsx)(c.Fragment,{children:!s&&(0,c.jsx)(rR,{beforeUpload:l,accept:"image/*,.pdf",showUploadList:!1,className:"inline-block",style:{padding:0,border:"none",background:"none"},children:(0,c.jsx)(V.Z,{title:"Attach image or PDF",children:(0,c.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-md transition-colors",children:(0,c.jsx)(rA.Z,{style:{fontSize:"16px"}})})})})})};let rU=e=>new Promise((s,t)=>{let l=new FileReader;l.onload=()=>{s(l.result)},l.onerror=t,l.readAsDataURL(e)}),rq=async(e,s)=>({role:"user",content:[{type:"text",text:e},{type:"image_url",image_url:{url:await rU(s)}}]}),rB=(e,s,t,l)=>{let a="";s&&l&&(a=l.toLowerCase().endsWith(".pdf")?"[PDF attached]":"[Image attached]");let r={role:"user",content:s?"".concat(e," ").concat(a):e};return s&&t&&(r.imagePreviewUrl=t),r},rV=e=>"user"===e.role&&"string"==typeof e.content&&(e.content.includes("[Image attached]")||e.content.includes("[PDF attached]"))&&!!e.imagePreviewUrl;var rK=e=>{let{message:s}=e;if(!rV(s))return null;let t="string"==typeof s.content&&s.content.includes("[PDF attached]");return(0,c.jsx)("div",{className:"mb-2",children:t?(0,c.jsx)("div",{className:"w-64 h-32 rounded-md border border-gray-200 bg-red-50 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"48px",color:"#dc2626"}})}):(0,c.jsx)("img",{src:s.imagePreviewUrl,alt:"User uploaded image",className:"max-w-64 rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"200px"}})})},rG=e=>{let{endpointType:s,responsesSessionId:t,useApiSessionManagement:l,onToggleSessionManagement:a}=e;return s!==rf.KP.RESPONSES?null:(0,c.jsxs)("div",{className:"mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Session Management"}),(0,c.jsx)(V.Z,{title:"Choose between LiteLLM API session management (using previous_response_id) or UI-based session management (using chat history)",children:(0,c.jsx)(B.Z,{className:"text-gray-400",style:{fontSize:"12px"}})})]}),(0,c.jsx)(tj.Z,{checked:l,onChange:a,checkedChildren:"API",unCheckedChildren:"UI",size:"small"})]}),(0,c.jsxs)("div",{className:"text-xs p-2 rounded-md ".concat(t?"bg-green-50 text-green-700 border border-green-200":"bg-blue-50 text-blue-700 border border-blue-200"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1",children:[(0,c.jsx)(B.Z,{style:{fontSize:"12px"}}),(()=>{if(!t)return l?"API Session: Ready":"UI Session: Ready";let e=l?"Response ID":"UI Session",s=t.slice(0,10);return"".concat(e,": ").concat(s,"...")})()]}),t&&(0,c.jsx)(V.Z,{title:(0,c.jsxs)("div",{className:"text-xs",children:[(0,c.jsx)("div",{className:"mb-1",children:"Copy response ID to continue session:"}),(0,c.jsx)("div",{className:"bg-gray-800 text-gray-100 p-2 rounded font-mono text-xs whitespace-pre-wrap",children:'curl -X POST "your-proxy-url/v1/responses" \\\n -H "Authorization: Bearer your-api-key" \\\n -H "Content-Type: application/json" \\\n -d \'{\n "model": "your-model",\n "input": [{"role": "user", "content": "your message", "type": "message"}],\n "previous_response_id": "'.concat(t,'",\n "stream": true\n }\'')})]}),overlayStyle:{maxWidth:"500px"},children:(0,c.jsx)("button",{onClick:()=>{t&&(navigator.clipboard.writeText(t),eo.Z.success("Response ID copied to clipboard!"))},className:"ml-2 p-1 hover:bg-green-100 rounded transition-colors",children:(0,c.jsx)(tR.Z,{style:{fontSize:"12px"}})})})]}),(0,c.jsx)("div",{className:"text-xs opacity-75 mt-1",children:t?l?"LiteLLM API session active - context maintained server-side":"UI session active - context maintained client-side":l?"LiteLLM will manage session using previous_response_id":"UI will manage session using chat history"})]})]})};let{Text:rH}=en.default,{Panel:rJ}=t_.default;var rY=e=>{var s,t;let{events:l,className:a}=e;if(console.log("MCPEventsDisplay: Received events:",l),!l||0===l.length)return console.log("MCPEventsDisplay: No events, returning null"),null;let r=l.find(e=>{var s;return"response.output_item.done"===e.type&&(null===(s=e.item)||void 0===s?void 0:s.type)==="mcp_list_tools"&&e.item.tools&&e.item.tools.length>0}),i=l.filter(e=>{var s;return"response.output_item.done"===e.type&&(null===(s=e.item)||void 0===s?void 0:s.type)==="mcp_call"});return(console.log("MCPEventsDisplay: toolsEvent:",r),console.log("MCPEventsDisplay: mcpCallEvents:",i),r||0!==i.length)?(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 "+"mcp-events-display ".concat(a||""),children:[(0,c.jsx)(tF(),{id:"92ff055d899e6f71",children:'.openai-mcp-tools.jsx-92ff055d899e6f71{position:relative;margin:0;padding:0}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse.jsx-92ff055d899e6f71{background:transparent!important;border:none!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-item.jsx-92ff055d899e6f71{border:none!important;background:transparent!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-header.jsx-92ff055d899e6f71{padding:0 0 0 20px!important;background:transparent!important;border:none!important;font-size:14px!important;color:#9ca3af!important;font-weight:400!important;line-height:20px!important;min-height:20px!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-header.jsx-92ff055d899e6f71:hover{background:transparent!important;color:#6b7280!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-content.jsx-92ff055d899e6f71{border:none!important;background:transparent!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-content-box.jsx-92ff055d899e6f71{padding:4px 0 0 20px!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-expand-icon.jsx-92ff055d899e6f71{position:absolute!important;left:2px!important;top:2px!important;color:#9ca3af!important;font-size:10px!important;width:16px!important;height:16px!important;display:-webkit-box!important;display:-webkit-flex!important;display:-moz-box!important;display:-ms-flexbox!important;display:flex!important;-webkit-box-align:center!important;-webkit-align-items:center!important;-moz-box-align:center!important;-ms-flex-align:center!important;align-items:center!important;-webkit-box-pack:center!important;-webkit-justify-content:center!important;-moz-box-pack:center!important;-ms-flex-pack:center!important;justify-content:center!important}.openai-mcp-tools.jsx-92ff055d899e6f71 .ant-collapse-expand-icon.jsx-92ff055d899e6f71:hover{color:#6b7280!important}.openai-vertical-line.jsx-92ff055d899e6f71{position:absolute;left:9px;top:18px;bottom:0;width:.5px;background-color:#f3f4f6;opacity:.8}.tool-item.jsx-92ff055d899e6f71{font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:13px;color:#4b5563;line-height:18px;padding:0;margin:0;background:white;position:relative;z-index:1}.mcp-section.jsx-92ff055d899e6f71{margin-bottom:12px;background:white;position:relative;z-index:1}.mcp-section.jsx-92ff055d899e6f71:last-child{margin-bottom:0}.mcp-section-header.jsx-92ff055d899e6f71{font-size:13px;color:#6b7280;font-weight:500;margin-bottom:4px}.mcp-code-block.jsx-92ff055d899e6f71{background:#f9fafb;border:1px solid#f3f4f6;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;padding:8px;font-size:12px}.mcp-json.jsx-92ff055d899e6f71{font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace;color:#374151;margin:0;white-space:pre-wrap;word-wrap:break-word}.mcp-approved.jsx-92ff055d899e6f71{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-moz-box-align:center;-ms-flex-align:center;align-items:center;font-size:13px;color:#6b7280}.mcp-checkmark.jsx-92ff055d899e6f71{color:#10b981;margin-right:6px;font-weight:bold}.mcp-response-content.jsx-92ff055d899e6f71{font-size:13px;color:#374151;line-height:1.5;white-space:pre-wrap;font-family:ui-monospace,SFMono-Regular,"SF Mono",Monaco,Consolas,"Liberation Mono","Courier New",monospace}'}),(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 openai-mcp-tools",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 openai-vertical-line"}),(0,c.jsxs)(t_.default,{ghost:!0,size:"small",expandIconPosition:"start",defaultActiveKey:r?["list-tools"]:i.map((e,s)=>"mcp-call-".concat(s)),children:[r&&(0,c.jsx)(rJ,{header:"List tools",children:(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71",children:null===(t=r.item)||void 0===t?void 0:null===(s=t.tools)||void 0===s?void 0:s.map((e,s)=>(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 tool-item",children:e.name},s))})},"list-tools"),i.map((e,s)=>{var t,l,a;return(0,c.jsx)(rJ,{header:(null===(t=e.item)||void 0===t?void 0:t.name)||"Tool call",children:(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71",children:[(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section-header",children:"Request"}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-code-block",children:(null===(l=e.item)||void 0===l?void 0:l.arguments)&&(0,c.jsx)("pre",{className:"jsx-92ff055d899e6f71 mcp-json",children:(()=>{try{return JSON.stringify(JSON.parse(e.item.arguments),null,2)}catch(s){return e.item.arguments}})()})})]}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-approved",children:[(0,c.jsx)("span",{className:"jsx-92ff055d899e6f71 mcp-checkmark",children:"✓"})," Approved"]})}),(null===(a=e.item)||void 0===a?void 0:a.output)&&(0,c.jsxs)("div",{className:"jsx-92ff055d899e6f71 mcp-section",children:[(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-section-header",children:"Response"}),(0,c.jsx)("div",{className:"jsx-92ff055d899e6f71 mcp-response-content",children:e.item.output})]})]})},"mcp-call-".concat(s))})]})]})]}):(console.log("MCPEventsDisplay: No valid events found, returning null"),null)},rW=t(61935),r$=t(71891),rQ=t(44625),rX=t(57400),r0=t(26430),r1=t(11894),r2=t(15883),r4=t(99890),r5=t(79276);let{TextArea:r6}=E.default,{Dragger:r3}=ed.default;var r8=e=>{let{accessToken:s,token:t,userRole:l,userID:a,disabledPersonalKeyCreation:r}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedMCPTools");try{let s=e?JSON.parse(e):[];return Array.isArray(s)?s:s?[s]:[]}catch(e){return console.error("Error parsing selectedMCPTools from sessionStorage",e),[]}}),[h,p]=(0,d.useState)(!1),[g,j]=(0,d.useState)(()=>{let e=sessionStorage.getItem("apiKeySource");if(e)try{return JSON.parse(e)}catch(e){console.error("Error parsing apiKeySource from sessionStorage",e)}return r?"custom":"session"}),[f,v]=(0,d.useState)(()=>sessionStorage.getItem("apiKey")||""),[y,N]=(0,d.useState)(""),[Z,w]=(0,d.useState)(()=>{try{let e=sessionStorage.getItem("chatHistory");return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing chatHistory from sessionStorage",e),[]}}),[C,A]=(0,d.useState)(()=>sessionStorage.getItem("selectedModel")||void 0),[T,E]=(0,d.useState)(!1),[M,O]=(0,d.useState)([]),D=(0,d.useRef)(null),[F,R]=(0,d.useState)(()=>sessionStorage.getItem("endpointType")||rf.KP.CHAT),[z,q]=(0,d.useState)(!1),K=(0,d.useRef)(null),[H,J]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedTags");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedTags from sessionStorage",e),[]}}),[Y,W]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedVectorStores");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedVectorStores from sessionStorage",e),[]}}),[$,Q]=(0,d.useState)(()=>{let e=sessionStorage.getItem("selectedGuardrails");try{return e?JSON.parse(e):[]}catch(e){return console.error("Error parsing selectedGuardrails from sessionStorage",e),[]}}),[X,ee]=(0,d.useState)(()=>sessionStorage.getItem("messageTraceId")||null),[es,et]=(0,d.useState)(()=>sessionStorage.getItem("responsesSessionId")||null),[el,ea]=(0,d.useState)(()=>{let e=sessionStorage.getItem("useApiSessionManagement");return!e||JSON.parse(e)}),[er,ei]=(0,d.useState)([]),[ec,ed]=(0,d.useState)([]),[em,eu]=(0,d.useState)(null),[ex,eh]=(0,d.useState)(null),[eg,ej]=(0,d.useState)(null),[ef,ev]=(0,d.useState)(null),[ey,eb]=(0,d.useState)(!1),[e_,eN]=(0,d.useState)(""),[eZ,ew]=(0,d.useState)("openai"),[ek,eS]=(0,d.useState)([]),eC=(0,d.useRef)(null),eI=async()=>{let e="session"===g?s:f;if(e){p(!0);try{let s=await rj(e);m(s)}catch(e){console.error("Error fetching MCP tools:",e)}finally{p(!1)}}};(0,d.useEffect)(()=>{i&&eI()},[i,s,f,g]),(0,d.useEffect)(()=>{ey&&eN((0,r_.L)({apiKeySource:g,accessToken:s,apiKey:f,inputMessage:y,chatHistory:Z,selectedTags:H,selectedVectorStores:Y,selectedGuardrails:$,selectedMCPTools:u,endpointType:F,selectedModel:C,selectedSdk:eZ}))},[ey,eZ,g,s,f,y,Z,H,Y,$,u,F,C]),(0,d.useEffect)(()=>{let e=setTimeout(()=>{sessionStorage.setItem("chatHistory",JSON.stringify(Z))},500);return()=>{clearTimeout(e)}},[Z]),(0,d.useEffect)(()=>{sessionStorage.setItem("apiKeySource",JSON.stringify(g)),sessionStorage.setItem("apiKey",f),sessionStorage.setItem("endpointType",F),sessionStorage.setItem("selectedTags",JSON.stringify(H)),sessionStorage.setItem("selectedVectorStores",JSON.stringify(Y)),sessionStorage.setItem("selectedGuardrails",JSON.stringify($)),sessionStorage.setItem("selectedMCPTools",JSON.stringify(u)),C?sessionStorage.setItem("selectedModel",C):sessionStorage.removeItem("selectedModel"),X?sessionStorage.setItem("messageTraceId",X):sessionStorage.removeItem("messageTraceId"),es?sessionStorage.setItem("responsesSessionId",es):sessionStorage.removeItem("responsesSessionId"),sessionStorage.setItem("useApiSessionManagement",JSON.stringify(el))},[g,f,C,F,H,Y,$,X,es,el,u]),(0,d.useEffect)(()=>{let e="session"===g?s:f;if(!e||!t||!l||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,t,l,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await eU(e);console.log("Fetched models:",s),s.length>0&&(O(s),C||A(s[0].model_group))}catch(e){console.error("Error fetching model info:",e)}})(),eI()},[s,a,l,g,f,t]),(0,d.useEffect)(()=>{eC.current&&setTimeout(()=>{var e;null===(e=eC.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[Z]);let eA=(e,s,t)=>{console.log("updateTextUI called with:",e,s,t),w(l=>{let a=l[l.length-1];if(!a||a.role!==e||a.isImage)return[...l,{role:e,content:s,model:t}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:t};return[...l.slice(0,-1),e]}})},eL=e=>{w(s=>{let t=s[s.length-1];return t&&"assistant"===t.role&&!t.isImage?[...s.slice(0,s.length-1),{...t,reasoningContent:(t.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},eT=e=>{console.log("updateTimingData called with:",e),w(s=>{let t=s[s.length-1];if(console.log("Current last message:",t),t&&"assistant"===t.role){console.log("Updating assistant message with timeToFirstToken:",e);let l=[...s.slice(0,s.length-1),{...t,timeToFirstToken:e}];return console.log("Updated chat history:",l),l}return t&&"user"===t.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},eP=(e,s)=>{console.log("Received usage data:",e),w(t=>{let l=t[t.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let a={...l,usage:e,toolName:s};return console.log("Updated message:",a),[...t.slice(0,t.length-1),a]}return t})},eE=e=>{console.log("Received response ID for session management:",e),el&&et(e)},eM=e=>{console.log("ChatUI: Received MCP event:",e),eS(s=>{if(s.some(s=>s.item_id===e.item_id&&s.type===e.type&&s.sequence_number===e.sequence_number))return console.log("ChatUI: Duplicate MCP event, skipping"),s;let t=[...s,e];return console.log("ChatUI: Updated MCP events:",t),t})},eO=(e,s)=>{w(t=>[...t,{role:"assistant",content:e,model:s,isImage:!0}])},eD=(e,s)=>{w(t=>{let l=t[t.length-1];if(!l||"assistant"!==l.role||l.isImage)return[...t,{role:"assistant",content:"",model:s,image:{url:e,detail:"auto"}}];{var a;let r={...l,image:{url:e,detail:"auto"},model:null!==(a=l.model)&&void 0!==a?a:s};return[...t.slice(0,-1),r]}})},eF=e=>{ei(s=>[...s,e]);let s=URL.createObjectURL(e);return ed(e=>[...e,s]),!1},eR=e=>{ec[e]&&URL.revokeObjectURL(ec[e]),ei(s=>s.filter((s,t)=>t!==e)),ed(s=>s.filter((s,t)=>t!==e))},eq=()=>{ec.forEach(e=>{URL.revokeObjectURL(e)}),ei([]),ed([])},eB=()=>{ex&&URL.revokeObjectURL(ex),eu(null),eh(null)},eV=()=>{ef&&URL.revokeObjectURL(ef),ej(null),ev(null)},eK=async()=>{let e;if(""===y.trim())return;if(F===rf.KP.IMAGE_EDITS&&0===er.length){eo.Z.fromBackend("Please upload at least one image for editing");return}if(!t||!l||!a)return;let r="session"===g?s:f;if(!r){eo.Z.fromBackend("Please provide an API key or select Current UI Session");return}K.current=new AbortController;let i=K.current.signal;if(F===rf.KP.RESPONSES&&em)try{e=await rE(y,em)}catch(e){eo.Z.fromBackend("Failed to process image. Please try again.");return}else if(F===rf.KP.CHAT&&eg)try{e=await rq(y,eg)}catch(e){eo.Z.fromBackend("Failed to process image. Please try again.");return}else e={role:"user",content:y};let n=X||(0,rd.Z)();X||ee(n),w([...Z,F===rf.KP.RESPONSES&&em?rM(y,!0,ex||void 0,em.name):F===rf.KP.CHAT&&eg?rB(y,!0,ef||void 0,eg.name):rM(y,!1)]),eS([]),q(!0);try{if(C){if(F===rf.KP.CHAT){let s=[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:"string"==typeof t?t:""}}),e];await rm(s,(e,s)=>eA("assistant",e,s),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u,eD)}else if(F===rf.KP.IMAGE)await ru(y,(e,s)=>eO(e,s),C,r,H,i);else if(F===rf.KP.IMAGE_EDITS)er.length>0&&await rx(1===er.length?er[0]:er,y,(e,s)=>eO(e,s),C,r,H,i);else if(F===rf.KP.RESPONSES){let s;s=el&&es?[e]:[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:t}}),e],await rh(s,(e,s,t)=>eA(e,s,t),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u,el?es:null,eE,eM)}else if(F===rf.KP.ANTHROPIC_MESSAGES){let s=[...Z.filter(e=>!e.isImage).map(e=>{let{role:s,content:t}=e;return{role:s,content:t}}),e];await rg(s,(e,s,t)=>eA(e,s,t),C,r,H,i,eL,eT,eP,n,Y.length>0?Y:void 0,$.length>0?$:void 0,u)}}}catch(e){i.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),eA("assistant","Error fetching response:"+e))}finally{q(!1),K.current=null,F===rf.KP.IMAGE_EDITS&&eq(),F===rf.KP.RESPONSES&&em&&eB(),F===rf.KP.CHAT&&eg&&eV()}N("")};if(l&&"Admin Viewer"===l){let{Title:e,Paragraph:s}=en.default;return(0,c.jsxs)("div",{children:[(0,c.jsx)(e,{level:1,children:"Access Denied"}),(0,c.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let eG=(0,c.jsx)(rW.Z,{style:{fontSize:24},spin:!0});return(0,c.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,c.jsx)(G.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,c.jsxs)("div",{className:"flex h-[80vh] w-full gap-4",children:[(0,c.jsxs)("div",{className:"w-1/4 p-4 bg-gray-50 overflow-y-auto",children:[(0,c.jsx)(S.Z,{className:"text-xl font-semibold mb-6 mt-2",children:"Configurations"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(lJ.Z,{className:"mr-2"})," API Key Source"]}),(0,c.jsx)(I.default,{disabled:r,value:g,style:{width:"100%"},onChange:e=>{j(e)},options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===g&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:v,value:f,icon:lJ.Z})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(ez.Z,{className:"mr-2"})," Select Model"]}),(0,c.jsx)(I.default,{value:C,placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),A(e),E("custom"===e)},options:[...Array.from(new Set(M.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),T&&(0,c.jsx)(_.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{A(e)},500)}})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(lt.Z,{className:"mr-2"})," Endpoint Type"]}),(0,c.jsx)(ry,{endpointType:F,onEndpointChange:e=>{R(e)},className:"mb-4"}),(0,c.jsx)(rG,{endpointType:F,responsesSessionId:es,useApiSessionManagement:el,onToggleSessionManagement:e=>{ea(e),e||et(null)}})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(r$.Z,{className:"mr-2"})," Tags"]}),(0,c.jsx)(rb,{value:H,onChange:J,className:"mb-4",accessToken:s||""})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2"})," MCP Tool",(0,c.jsx)(V.Z,{className:"ml-1",title:"Select MCP tools to use in your conversation, only available for /v1/responses endpoint",children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select MCP tools",value:u,onChange:e=>x(e),loading:h,className:"mb-4",allowClear:!0,optionLabelProp:"label",disabled:F!==rf.KP.RESPONSES,maxTagCount:"responsive",children:Array.isArray(o)&&o.map(e=>(0,c.jsx)(I.default.Option,{value:e.name,label:(0,c.jsx)("div",{className:"font-medium",children:e.name}),children:(0,c.jsxs)("div",{className:"flex flex-col py-1",children:[(0,c.jsx)("span",{className:"font-medium",children:e.name}),(0,c.jsx)("span",{className:"text-xs text-gray-500 mt-1",children:e.description})]})},e.name))})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rQ.Z,{className:"mr-2"})," Vector Store",(0,c.jsx)(V.Z,{className:"ml-1",title:(0,c.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,c.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(U,{value:Y,onChange:W,className:"mb-4",accessToken:s||""})]}),(0,c.jsxs)("div",{children:[(0,c.jsxs)(k.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,c.jsx)(rX.Z,{className:"mr-2"})," Guardrails",(0,c.jsx)(V.Z,{className:"ml-1",title:(0,c.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,c.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,c.jsx)(B.Z,{})})]}),(0,c.jsx)(st,{value:$,onChange:Q,className:"mb-4",accessToken:s||""})]})]})]}),(0,c.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,c.jsxs)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:[(0,c.jsx)(S.Z,{className:"text-xl font-semibold mb-0",children:"Test Key"}),(0,c.jsxs)("div",{className:"flex gap-2",children:[(0,c.jsx)(b.Z,{onClick:()=>{w([]),ee(null),et(null),eS([]),eq(),eB(),eV(),sessionStorage.removeItem("chatHistory"),sessionStorage.removeItem("messageTraceId"),sessionStorage.removeItem("responsesSessionId"),eo.Z.success("Chat history cleared.")},className:"bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300",icon:r0.Z,children:"Clear Chat"}),(0,c.jsx)(b.Z,{onClick:()=>eb(!0),className:"bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300",icon:r1.Z,children:"Get Code"})]})]}),(0,c.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===Z.length&&(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(ez.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(k.Z,{children:"Start a conversation or generate an image"})]}),Z.map((e,s)=>(0,c.jsx)("div",{children:(0,c.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,c.jsx)(r2.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,c.jsx)(ez.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,c.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,c.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,c.jsx)(rZ,{reasoningContent:e.reasoningContent}),"assistant"===e.role&&s===Z.length-1&&ek.length>0&&F===rf.KP.RESPONSES&&(0,c.jsx)("div",{className:"mb-3",children:(0,c.jsx)(rY,{events:ek})}),(0,c.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,c.jsx)("img",{src:"string"==typeof e.content?e.content:"",alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,c.jsxs)(c.Fragment,{children:[F===rf.KP.RESPONSES&&(0,c.jsx)(rF,{message:e}),F===rf.KP.CHAT&&(0,c.jsx)(rK,{message:e}),(0,c.jsx)(rc.U,{components:{code(e){let{node:s,inline:t,className:l,children:a,...r}=e,i=/language-(\w+)/.exec(l||"");return!t&&i?(0,c.jsx)(am.Z,{style:rv.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,c.jsx)("code",{className:"".concat(l," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...t}=e;return(0,c.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...t})}},children:"string"==typeof e.content?e.content:""}),e.image&&(0,c.jsx)("div",{className:"mt-3",children:(0,c.jsx)("img",{src:e.image.url,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}})})]}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,c.jsx)(rI,{timeToFirstToken:e.timeToFirstToken,usage:e.usage,toolName:e.toolName})]})]})})},s)),z&&ek.length>0&&F===rf.KP.RESPONSES&&Z.length>0&&"user"===Z[Z.length-1].role&&(0,c.jsx)("div",{className:"text-left mb-4",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"#ffffff",border:"1px solid #f0f0f0",textAlign:"left"},children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,c.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"#f5f5f5"},children:(0,c.jsx)(ez.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,c.jsx)("strong",{className:"text-sm capitalize",children:"Assistant"})]}),(0,c.jsx)(rY,{events:ek})]})}),z&&(0,c.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,c.jsx)(lI.Z,{indicator:eG})}),(0,c.jsx)("div",{ref:eC,style:{height:"1px"}})]}),(0,c.jsxs)("div",{className:"p-4 border-t border-gray-200 bg-white",children:[F===rf.KP.IMAGE_EDITS&&(0,c.jsx)("div",{className:"mb-4",children:0===er.length?(0,c.jsxs)(r3,{beforeUpload:eF,accept:"image/*",showUploadList:!1,className:"border-dashed border-2 border-gray-300 rounded-lg p-4",children:[(0,c.jsx)("p",{className:"ant-upload-drag-icon",children:(0,c.jsx)(r4.Z,{style:{fontSize:"24px",color:"#666"}})}),(0,c.jsx)("p",{className:"ant-upload-text text-sm",children:"Click or drag images to upload"}),(0,c.jsx)("p",{className:"ant-upload-hint text-xs text-gray-500",children:"Support for PNG, JPG, JPEG formats. Multiple images supported."})]}):(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[er.map((e,s)=>(0,c.jsxs)("div",{className:"relative inline-block",children:[(0,c.jsx)("img",{src:ec[s]||"",alt:"Upload preview ".concat(s+1),className:"max-w-32 max-h-32 rounded-md border border-gray-200 object-cover"}),(0,c.jsx)("button",{className:"absolute top-1 right-1 bg-white shadow-sm border border-gray-200 rounded px-1 py-1 text-red-500 hover:bg-red-50 text-xs",onClick:()=>eR(s),children:(0,c.jsx)(ep.Z,{})})]},s)),(0,c.jsxs)("div",{className:"flex items-center justify-center w-32 h-32 border-2 border-dashed border-gray-300 rounded-md hover:border-gray-400 cursor-pointer",onClick:()=>{var e;return null===(e=document.getElementById("additional-image-upload"))||void 0===e?void 0:e.click()},children:[(0,c.jsxs)("div",{className:"text-center",children:[(0,c.jsx)(r4.Z,{style:{fontSize:"24px",color:"#666"}}),(0,c.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Add more"})]}),(0,c.jsx)("input",{id:"additional-image-upload",type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{Array.from(e.target.files||[]).forEach(e=>eF(e))}})]})]})}),F===rf.KP.RESPONSES&&em&&(0,c.jsx)("div",{className:"mb-2",children:(0,c.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"relative inline-block",children:em.name.toLowerCase().endsWith(".pdf")?(0,c.jsx)("div",{className:"w-10 h-10 rounded-md bg-red-500 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"16px",color:"white"}})}):(0,c.jsx)("img",{src:ex||"",alt:"Upload preview",className:"w-10 h-10 rounded-md border border-gray-200 object-cover"})}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-900 truncate",children:em.name}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:em.name.toLowerCase().endsWith(".pdf")?"PDF":"Image"})]}),(0,c.jsx)("button",{className:"flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-600 hover:bg-gray-200 rounded-full transition-colors",onClick:eB,children:(0,c.jsx)(ep.Z,{style:{fontSize:"12px"}})})]})}),F===rf.KP.CHAT&&eg&&(0,c.jsx)("div",{className:"mb-2",children:(0,c.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"relative inline-block",children:eg.name.toLowerCase().endsWith(".pdf")?(0,c.jsx)("div",{className:"w-10 h-10 rounded-md bg-red-500 flex items-center justify-center",children:(0,c.jsx)(rD.Z,{style:{fontSize:"16px",color:"white"}})}):(0,c.jsx)("img",{src:ef||"",alt:"Upload preview",className:"w-10 h-10 rounded-md border border-gray-200 object-cover"})}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("div",{className:"text-sm font-medium text-gray-900 truncate",children:eg.name}),(0,c.jsx)("div",{className:"text-xs text-gray-500",children:eg.name.toLowerCase().endsWith(".pdf")?"PDF":"Image"})]}),(0,c.jsx)("button",{className:"flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-600 hover:bg-gray-200 rounded-full transition-colors",onClick:eV,children:(0,c.jsx)(ep.Z,{style:{fontSize:"12px"}})})]})}),(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsxs)("div",{className:"flex items-center flex-1 bg-white border border-gray-300 rounded-xl px-3 py-1 min-h-[44px]",children:[(0,c.jsxs)("div",{className:"flex-shrink-0 mr-2",children:[F===rf.KP.RESPONSES&&!em&&(0,c.jsx)(rT,{responsesUploadedImage:em,responsesImagePreviewUrl:ex,onImageUpload:e=>(eu(e),eh(URL.createObjectURL(e)),!1),onRemoveImage:eB}),F===rf.KP.CHAT&&!eg&&(0,c.jsx)(rz,{chatUploadedImage:eg,chatImagePreviewUrl:ef,onImageUpload:e=>(ej(e),ev(URL.createObjectURL(e)),!1),onRemoveImage:eV})]}),(0,c.jsx)(r6,{value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),eK())},placeholder:F===rf.KP.CHAT||F===rf.KP.RESPONSES||F===rf.KP.ANTHROPIC_MESSAGES?"Type your message... (Shift+Enter for new line)":F===rf.KP.IMAGE_EDITS?"Describe how you want to edit the image...":"Describe the image you want to generate...",disabled:z,className:"flex-1",autoSize:{minRows:1,maxRows:4},style:{resize:"none",border:"none",boxShadow:"none",background:"transparent",padding:"4px 0",fontSize:"14px",lineHeight:"20px"}}),(0,c.jsx)(b.Z,{onClick:eK,disabled:z||!y.trim(),className:"flex-shrink-0 ml-2 !w-8 !h-8 !min-w-8 !p-0 !rounded-full !bg-blue-600 hover:!bg-blue-700 disabled:!bg-gray-300 !border-none !text-white disabled:!text-gray-500 !flex !items-center !justify-center",children:(0,c.jsx)(r5.Z,{style:{fontSize:"14px"}})})]}),z&&(0,c.jsx)(b.Z,{onClick:()=>{K.current&&(K.current.abort(),K.current=null,q(!1),eo.Z.info("Request cancelled"))},className:"bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ep.Z,children:"Cancel"})]})]})]})]})}),(0,c.jsxs)(L.Z,{title:"Generated Code",visible:ey,onCancel:()=>eb(!1),footer:null,width:800,children:[(0,c.jsxs)("div",{className:"flex justify-between items-end my-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium block mb-1 text-gray-700",children:"SDK Type"}),(0,c.jsx)(I.default,{value:eZ,onChange:e=>ew(e),style:{width:150},options:[{value:"openai",label:"OpenAI SDK"},{value:"azure",label:"Azure SDK"}]})]}),(0,c.jsx)(P.ZP,{onClick:()=>{navigator.clipboard.writeText(e_),eo.Z.success("Copied to clipboard!")},children:"Copy to Clipboard"})]}),(0,c.jsx)(am.Z,{language:"python",style:rv.Z,wrapLines:!0,wrapLongLines:!0,className:"rounded-md",customStyle:{maxHeight:"60vh",overflowY:"auto"},children:e_})]}),"custom"===g&&(0,c.jsx)(L.Z,{title:"Select MCP Tool",visible:i,onCancel:()=>n(!1),onOk:()=>{n(!1),eo.Z.success("MCP tool selection updated")},width:800,children:h?(0,c.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,c.jsx)(lI.Z,{indicator:(0,c.jsx)(rW.Z,{style:{fontSize:24},spin:!0})})}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsx)(k.Z,{className:"text-gray-600 block mb-4",children:"Select the MCP tools you want to use in your conversation."}),(0,c.jsx)(I.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select MCP tools",value:u,onChange:e=>x(e),optionLabelProp:"label",allowClear:!0,maxTagCount:"responsive",children:o.map(e=>(0,c.jsx)(I.default.Option,{value:e.name,label:(0,c.jsx)("div",{className:"font-medium",children:e.name}),children:(0,c.jsxs)("div",{className:"flex flex-col py-1",children:[(0,c.jsx)("span",{className:"font-medium",children:e.name}),(0,c.jsx)("span",{className:"text-xs text-gray-500 mt-1",children:e.description})]})},e.name))})]})})]})},r7=t(19226),r9=t(45937),ie=t(28595),is=t(68208),it=t(9775),il=t(41361),ia=t(37527),ir=t(88009),ii=t(48231),io=t(41169),ic=t(55322),id=t(11429),im=t(70525),iu=t(95805),ix=t(51817),ih=t(21047);t(22135),t(40875);var ip=t(49663);let ig=function(){for(var e=arguments.length,s=Array(e),t=0;t{(async()=>{if(s){u(!0),h(null);try{let e=await (0,j.getRemainingUsers)(s);o(e)}catch(e){console.error("Failed to fetch usage data:",e),h("Failed to load usage data")}finally{u(!1)}}})()},[s]);let{isOverLimit:p,isNearLimit:g,usagePercentage:f,userMetrics:v,teamMetrics:y}=(e=>{if(!e)return{isOverLimit:!1,isNearLimit:!1,usagePercentage:0,userMetrics:{isOverLimit:!1,isNearLimit:!1,usagePercentage:0},teamMetrics:{isOverLimit:!1,isNearLimit:!1,usagePercentage:0}};let s=!!e.total_users_remaining&&e.total_users_remaining<=0,t=!!e.total_users_remaining&&e.total_users_remaining<=5&&e.total_users_remaining>0,l=e.total_users?e.total_users_used/e.total_users*100:0,a=!!e.total_teams_remaining&&e.total_teams_remaining<=0,r=!!e.total_teams_remaining&&e.total_teams_remaining<=5&&e.total_teams_remaining>0,i=e.total_teams?e.total_teams_used/e.total_teams*100:0,n=s||a;return{isOverLimit:n,isNearLimit:(t||r)&&!n,usagePercentage:Math.max(l,i),userMetrics:{isOverLimit:s,isNearLimit:t,usagePercentage:l},teamMetrics:{isOverLimit:a,isNearLimit:r,usagePercentage:i}}})(n),b=()=>p?"red":g?"yellow":"green",_=()=>p?"Over Limit":g?"Near Limit":"Active",N=()=>p?(0,c.jsx)(lD.Z,{className:"h-3 w-3"}):g?(0,c.jsx)(im.Z,{className:"h-3 w-3"}):null;return s&&((null==n?void 0:n.total_users)!==null||(null==n?void 0:n.total_teams)!==null)?(0,c.jsx)("div",{className:"fixed bottom-4 left-4 z-50",style:{width:"".concat(Math.min(t,220),"px")},children:(0,c.jsx)(()=>{if(r){let e=p||g;return(0,c.jsx)("button",{onClick:()=>i(!1),className:ig("bg-white border border-gray-200 rounded-lg shadow-sm p-3 hover:shadow-md transition-all w-full",e&&p&&"border-red-200 bg-red-50",e&&g&&"border-yellow-200 bg-yellow-50"),title:"Show usage details",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(iu.Z,{className:"h-4 w-4 flex-shrink-0"}),e&&(0,c.jsx)("span",{className:"flex-shrink-0",children:N()}),(0,c.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium truncate",children:[n&&null!==n.total_users&&(0,c.jsxs)("span",{className:"flex-shrink-0",children:["U: ",n.total_users_used,"/",n.total_users]}),n&&null!==n.total_teams&&(0,c.jsxs)("span",{className:"flex-shrink-0",children:["T: ",n.total_teams_used,"/",n.total_teams]}),!n||null===n.total_users&&null===n.total_teams&&(0,c.jsx)("span",{className:"truncate",children:"Usage"})]})]})})}return m?(0,c.jsx)("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 w-full",children:(0,c.jsxs)("div",{className:"flex items-center justify-center gap-2 py-2",children:[(0,c.jsx)(ix.Z,{className:"h-4 w-4 animate-spin"}),(0,c.jsx)("span",{className:"text-sm text-gray-500 truncate",children:"Loading..."})]})}):x||!n?(0,c.jsx)("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 group w-full",children:(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex-1 min-w-0",children:(0,c.jsx)("span",{className:"text-sm text-gray-500 truncate block",children:x||"No data"})}),(0,c.jsx)("button",{onClick:()=>i(!0),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-gray-100 rounded transition-all flex-shrink-0",title:"Minimize",children:(0,c.jsx)(ih.Z,{className:"h-3 w-3 text-gray-400"})})]})}):(0,c.jsxs)("div",{className:ig("bg-white border rounded-lg shadow-sm p-3 transition-all duration-200 group w-full",p&&"border-red-200 bg-red-50",g&&"border-yellow-200 bg-yellow-50"),children:[(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-3",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,c.jsx)(iu.Z,{className:"h-4 w-4 flex-shrink-0"}),(0,c.jsx)("span",{className:"font-medium text-sm truncate",children:"Usage"}),(p||g)&&(0,c.jsx)(eX.Z,{color:b(),className:"text-xs px-1.5 py-0.5 flex-shrink-0",children:_()})]}),(0,c.jsx)("button",{onClick:()=>i(!0),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-gray-100 rounded transition-all flex-shrink-0",title:"Minimize",children:(0,c.jsx)(ih.Z,{className:"h-3 w-3 text-gray-400"})})]}),(0,c.jsxs)("div",{className:"space-y-3 text-sm",children:[null!==n.total_users&&(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-600 mb-1",children:[(0,c.jsx)(iu.Z,{className:"h-3 w-3"}),(0,c.jsx)("span",{className:"font-medium",children:"Users"})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Used:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[n.total_users_used,"/",n.total_users]})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Remaining:"}),(0,c.jsx)("span",{className:ig("font-medium text-right",v.isOverLimit&&"text-red-600",v.isNearLimit&&"text-yellow-600"),children:n.total_users_remaining})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Usage:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[Math.round(v.usagePercentage),"%"]})]}),(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,c.jsx)("div",{className:ig("h-2 rounded-full transition-all duration-300",v.isOverLimit&&"bg-red-500",v.isNearLimit&&"bg-yellow-500",!v.isOverLimit&&!v.isNearLimit&&"bg-green-500"),style:{width:"".concat(Math.min(v.usagePercentage,100),"%")}})})]}),null!==n.total_teams&&(0,c.jsxs)("div",{className:"space-y-1",children:[(0,c.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-600 mb-1",children:[(0,c.jsx)(ip.Z,{className:"h-3 w-3"}),(0,c.jsx)("span",{className:"font-medium",children:"Teams"})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Used:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[n.total_teams_used,"/",n.total_teams]})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Remaining:"}),(0,c.jsx)("span",{className:ig("font-medium text-right",y.isOverLimit&&"text-red-600",y.isNearLimit&&"text-yellow-600"),children:n.total_teams_remaining})]}),(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)("span",{className:"text-gray-600 text-xs",children:"Usage:"}),(0,c.jsxs)("span",{className:"font-medium text-right",children:[Math.round(y.usagePercentage),"%"]})]}),(0,c.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,c.jsx)("div",{className:ig("h-2 rounded-full transition-all duration-300",y.isOverLimit&&"bg-red-500",y.isNearLimit&&"bg-yellow-500",!y.isOverLimit&&!y.isNearLimit&&"bg-green-500"),style:{width:"".concat(Math.min(y.usagePercentage,100),"%")}})})]})]})]})},{})}):null}var iv=t(13959);let{Sider:iy}=r7.default;var ib=e=>{let{accessToken:s,setPage:t,userRole:l,defaultSelectedKey:a,collapsed:r=!1}=e,i=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,c.jsx)(lJ.Z,{style:{fontSize:"18px"}})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,c.jsx)(ie.Z,{style:{fontSize:"18px"}}),roles:eI.LQ},{key:"2",page:"models",label:"Models + Endpoints",icon:(0,c.jsx)(is.Z,{style:{fontSize:"18px"}}),roles:eI.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,c.jsx)(it.Z,{style:{fontSize:"18px"}}),roles:[...eI.ZL,...eI.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,c.jsx)(il.Z,{style:{fontSize:"18px"}})},{key:"17",page:"organizations",label:"Organizations",icon:(0,c.jsx)(ia.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,c.jsx)(r2.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,c.jsx)(lt.Z,{style:{fontSize:"18px"}})},{key:"16",page:"model-hub-table",label:"Model Hub",icon:(0,c.jsx)(ir.Z,{style:{fontSize:"18px"}})},{key:"15",page:"logs",label:"Logs",icon:(0,c.jsx)(ii.Z,{style:{fontSize:"18px"}})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,c.jsx)(rX.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"26",page:"tools",label:"Tools",icon:(0,c.jsx)(rC.Z,{style:{fontSize:"18px"}}),children:[{key:"18",page:"mcp-servers",label:"MCP Servers",icon:(0,c.jsx)(rC.Z,{style:{fontSize:"18px"}})},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,c.jsx)(rQ.Z,{style:{fontSize:"18px"}}),roles:eI.ZL}]},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,c.jsx)(io.Z,{style:{fontSize:"18px"}}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,c.jsx)(rQ.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"25",page:"prompts",label:"Prompts",icon:(0,c.jsx)(eh.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,c.jsx)(ia.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,c.jsx)(lt.Z,{style:{fontSize:"18px"}}),roles:[...eI.ZL,...eI.lo]},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,c.jsx)(r$.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,c.jsx)(it.Z,{style:{fontSize:"18px"}})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,c.jsx)(ic.Z,{style:{fontSize:"18px"}}),roles:eI.ZL},{key:"14",page:"ui-theme",label:"UI Theme",icon:(0,c.jsx)(id.Z,{style:{fontSize:"18px"}}),roles:eI.ZL}]}],n=(e=>{let s=i.find(s=>s.page===e);if(s)return s.key;for(let s of i)if(s.children){let t=s.children.find(s=>s.page===e);if(t)return t.key}return"1"})(a),o=i.filter(e=>{let s=!e.roles||e.roles.includes(l);return console.log("Menu item ".concat(e.label,": roles=").concat(e.roles,", userRole=").concat(l,", hasAccess=").concat(s)),!!s&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0)});return(0,c.jsx)(r7.default,{style:{minHeight:"100vh"},children:(0,c.jsxs)(iy,{theme:"light",width:220,collapsed:r,collapsedWidth:80,collapsible:!0,trigger:null,style:{transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",position:"relative"},children:[(0,c.jsx)(iv.ZP,{theme:{components:{Menu:{iconSize:18,fontSize:14}}},children:(0,c.jsx)(r9.Z,{mode:"inline",selectedKeys:[n],defaultOpenKeys:r?[]:["llm-tools"],inlineCollapsed:r,className:"custom-sidebar-menu",style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:o.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())),t(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())),t(e.page)}}})})}),(0,eI.tY)(l)&&!r&&(0,c.jsx)(ij,{accessToken:s,width:220})]})})},i_=t(96889),iN=t(92414),iZ=t(46030);console.log("process.env.NODE_ENV","production");let iw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ik=e=>{let{accessToken:s,token:t,userRole:l,userID:a,keys:r,premiumUser:i}=e,n=new Date,[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)([]),[_,N]=(0,d.useState)([]),[Z,w]=(0,d.useState)([]),[C,I]=(0,d.useState)([]),[A,L]=(0,d.useState)([]),[T,P]=(0,d.useState)([]),[E,M]=(0,d.useState)([]),[O,D]=(0,d.useState)({}),[F,R]=(0,d.useState)([]),[z,U]=(0,d.useState)(""),[q,B]=(0,d.useState)(["all-tags"]),[V,K]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,d.useState)(null),[Y,W]=(0,d.useState)(0),$=new Date(n.getFullYear(),n.getMonth(),1),Q=new Date(n.getFullYear(),n.getMonth()+1,0),X=er($),ee=er(Q);function es(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",i);let et=async()=>{if(s)try{let e=await (0,j.getProxyUISettings)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,d.useEffect)(()=>{ea(V.from,V.to)},[V,q]);let el=async(e,t,l)=>{if(!e||!t||!s)return;console.log("uiSelectedKey",l);let a=await (0,j.adminTopEndUsersCall)(s,l,e.toISOString(),t.toISOString());console.log("End user data updated successfully",a),f(a)},ea=async(e,t)=>{if(!e||!t||!s)return;let l=await et();null!=l&&l.DISABLE_EXPENSIVE_DB_QUERIES||(w((await (0,j.tagsSpendLogsCall)(s,e.toISOString(),t.toISOString(),0===q.length?void 0:q)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),t=e.getMonth()+1,l=e.getDate();return"".concat(s,"-").concat(t<10?"0"+t:t,"-").concat(l<10?"0"+l:l)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(ee));let en=async(e,s,t)=>{try{let t=await e();s(t)}catch(e){console.error(t,e)}},eo=(e,s,t,l)=>{let a=[],r=new Date(s),i=e=>{if(e.includes("-"))return e;{let[s,t]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(t)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let s=i(e.date);return[s,{...e,date:s}]}));for(;r<=t;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let s={date:e,api_requests:0,total_tokens:0};l.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},ec=async()=>{if(s)try{let e=await (0,j.adminSpendLogsCall)(s),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=eo(e,l,a,[]),i=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(i),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>en(()=>s&&t?(0,j.adminspendByProvider)(s,t,X,ee):Promise.reject("No access token or token"),M,"Error fetching provider spend"),em=async()=>{s&&await en(async()=>(await (0,j.adminTopKeysCall)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),x,"Error fetching top keys")},eu=async()=>{s&&await en(async()=>(await (0,j.adminTopModelsCall)(s)).map(e=>({key:e.model,spend:eE(e.total_spend,2)})),p,"Error fetching top models")},ex=async()=>{s&&await en(async()=>{let e=await (0,j.teamSpendLogsCall)(s),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0);return N(eo(e.daily_spend,l,a,e.teams)),L(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:eE(e.total_spend||0,2)}))},P,"Error fetching team spend")},eh=()=>{s&&en(async()=>(await (0,j.allTagNamesCall)(s)).tag_names,I,"Error fetching tag names")},ep=()=>{s&&en(()=>{var e,t;return(0,j.tagsSpendLogsCall)(s,null===(e=V.from)||void 0===e?void 0:e.toISOString(),null===(t=V.to)||void 0===t?void 0:t.toISOString(),void 0)},e=>w(e.spend_per_tag),"Error fetching top tags")},eg=()=>{s&&en(()=>(0,j.adminTopEndUsersCall)(s,null,void 0,void 0),f,"Error fetching top end users")},ej=async()=>{if(s)try{let e=await (0,j.adminGlobalActivity)(s,X,ee),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=eo(e.daily_data||[],l,a,["api_requests","total_tokens"]);D({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ef=async()=>{if(s)try{let e=await (0,j.adminGlobalActivityPerModel)(s,X,ee),t=new Date,l=new Date(t.getFullYear(),t.getMonth(),1),a=new Date(t.getFullYear(),t.getMonth()+1,0),r=e.map(e=>({...e,daily_data:eo(e.daily_data||[],l,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,d.useEffect)(()=>{(async()=>{if(s&&t&&l&&a){let e=await et();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),ec(),ed(),em(),eu(),ej(),ef(),iw(l)&&(ex(),eh(),ep(),eg()))}})()},[s,t,l,a,X,ee]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,c.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Database Query Limit Reached"}),(0,c.jsxs)(k.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,c.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,c.jsx)(b.Z,{className:"mt-4",children:(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,c.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mt-2",children:[(0,c.jsx)(e0.Z,{children:"All Up"}),iw(l)?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(e0.Z,{children:"Team Based Usage"}),(0,c.jsx)(e0.Z,{children:"Customer Usage"}),(0,c.jsx)(e0.Z,{children:"Tag Based Usage"})]}):(0,c.jsx)(c.Fragment,{children:(0,c.jsx)("div",{})})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{variant:"solid",className:"mt-1",children:[(0,c.jsx)(e0.Z,{children:"Cost"}),(0,c.jsx)(e0.Z,{children:"Activity"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(k.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,c.jsx)(aJ,{userID:a,userRole:l,accessToken:s,userSpend:Y,selectedTeam:null,userMaxBudget:null})]}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Monthly Spend"}),(0,c.jsx)(s3.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(eE(e,2)),yAxisWidth:100,tickGap:5})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top API Keys"}),(0,c.jsx)(aW,{topKeys:u,accessToken:s,userID:a,userRole:l,teams:null,premiumUser:i})]})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(G.Z,{className:"h-full",children:[(0,c.jsx)(S.Z,{children:"Top Models"}),(0,c.jsx)(s3.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(eE(e,2))})]})}),(0,c.jsx)(v.Z,{numColSpan:1}),(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{className:"mb-2",children:[(0,c.jsx)(S.Z,{children:"Spend by Provider"}),(0,c.jsx)(c.Fragment,{children:(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(aV.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(eE(e,2))})}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsxs)(sw.Z,{children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Provider"}),(0,c.jsx)(sI.Z,{children:"Spend"})]})}),(0,c.jsx)(sk.Z,{children:E.map(e=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.provider}),(0,c.jsx)(sS.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":eE(e.spend,2)})]},e.provider))})]})})]})})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"All Up"}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",es(O.sum_api_requests)]}),(0,c.jsx)(s6.Z,{className:"h-40",data:O.daily_data,valueFormatter:es,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",es(O.sum_total_tokens)]}),(0,c.jsx)(s3.Z,{className:"h-40",data:O.daily_data,valueFormatter:es,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,c.jsx)(c.Fragment,{children:F.map((e,s)=>(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:e.model}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",es(e.sum_api_requests)]}),(0,c.jsx)(s6.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:es,onValueChange:e=>console.log(e)})]}),(0,c.jsxs)(v.Z,{children:[(0,c.jsxs)(sz.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",es(e.sum_total_tokens)]}),(0,c.jsx)(s3.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:es,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,c.jsxs)(v.Z,{numColSpan:2,children:[(0,c.jsxs)(G.Z,{className:"mb-2",children:[(0,c.jsx)(S.Z,{children:"Total Spend Per Team"}),(0,c.jsx)(i_.Z,{data:T})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Daily Spend Per Team"}),(0,c.jsx)(s3.Z,{className:"h-72",data:_,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,c.jsx)(v.Z,{numColSpan:2})]})}),(0,c.jsxs)(e4.Z,{children:[(0,c.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,c.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:V,onValueChange:e=>{K(e),el(e.from,e.to,null)}})}),(0,c.jsxs)(v.Z,{children:[(0,c.jsx)(k.Z,{children:"Select Key"}),(0,c.jsxs)(eQ.Z,{defaultValue:"all-keys",children:[(0,c.jsx)(ei.Z,{value:"all-keys",onClick:()=>{el(V.from,V.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,c.jsx)(ei.Z,{value:String(s),onClick:()=>{el(V.from,V.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,c.jsx)(G.Z,{className:"mt-4",children:(0,c.jsxs)(sw.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,c.jsx)(sC.Z,{children:(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sI.Z,{children:"Customer"}),(0,c.jsx)(sI.Z,{children:"Spend"}),(0,c.jsx)(sI.Z,{children:"Total Events"})]})}),(0,c.jsx)(sk.Z,{children:null==g?void 0:g.map((e,s)=>(0,c.jsxs)(sA.Z,{children:[(0,c.jsx)(sS.Z,{children:e.end_user}),(0,c.jsx)(sS.Z,{children:eE(e.total_spend,2)}),(0,c.jsx)(sS.Z,{children:e.total_count})]},s))})]})})]}),(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:2,children:[(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(s5,{className:"mb-4",value:V,onValueChange:e=>{K(e),ea(e.from,e.to)}})}),(0,c.jsx)(v.Z,{children:i?(0,c.jsx)("div",{children:(0,c.jsxs)(iN.Z,{value:q,onValueChange:e=>B(e),children:[(0,c.jsx)(iZ.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,s)=>(0,c.jsx)(iZ.Z,{value:String(e),children:e},e))]})}):(0,c.jsx)("div",{children:(0,c.jsxs)(iN.Z,{value:q,onValueChange:e=>B(e),children:[(0,c.jsx)(iZ.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,s)=>(0,c.jsxs)(ei.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,c.jsxs)(y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,c.jsx)(v.Z,{numColSpan:2,children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{children:"Spend Per Tag"}),(0,c.jsxs)(k.Z,{children:["Get Started by Tracking cost per tag ",(0,c.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,c.jsx)(s3.Z,{className:"h-72",data:Z,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,c.jsx)(v.Z,{numColSpan:2})]})]})]})]})})},iS=t(51853);let iC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,c.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,c.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,c.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,c.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},iI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},iA=e=>{let{label:s,value:t}=e,[l,a]=d.useState(!1),[r,i]=d.useState(!1),n=(null==t?void 0:t.toString())||"N/A",o=n.length>50?n.substring(0,50)+"...":n;return(0,c.jsx)("tr",{className:"hover:bg-gray-50",children:(0,c.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,c.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,c.jsxs)("div",{className:"flex items-center flex-1",children:[(0,c.jsx)("button",{onClick:()=>a(!l),className:"text-gray-400 hover:text-gray-600 mr-2",children:l?"▼":"▶"}),(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,c.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:l?n:o})]})]}),(0,c.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,c.jsx)(iS.Z,{className:"h-4 w-4"})})]})})})},iL=e=>{var s,t,l,a,r,i,n,o,d,m,u,x,h,p;let{response:g}=e,j=null,f={},v={};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=iI(j.litellm_params)||{},v=iI(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=iI(null==g?void 0:g.litellm_cache_params)||{},v=iI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},v={}}let y={redis_host:(null==v?void 0:null===(l=v.redis_client)||void 0===l?void 0:null===(t=l.connection_pool)||void 0===t?void 0:null===(s=t.connection_kwargs)||void 0===s?void 0:s.host)||(null==v?void 0:null===(i=v.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)||(null==v?void 0:null===(n=v.connection_kwargs)||void 0===n?void 0:n.host)||(null==v?void 0:v.host)||"N/A",redis_port:(null==v?void 0:null===(m=v.redis_client)||void 0===m?void 0:null===(d=m.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==v?void 0:null===(h=v.redis_async_client)||void 0===h?void 0:null===(x=h.connection_pool)||void 0===x?void 0:null===(u=x.connection_kwargs)||void 0===u?void 0:u.port)||(null==v?void 0:null===(p=v.connection_kwargs)||void 0===p?void 0:p.port)||(null==v?void 0:v.port)||"N/A",redis_version:(null==v?void 0:v.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,t,l,a,r,i,n,o,c,d,m,u;if(null==v?void 0:null===(e=v.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(v.redis_kwargs.startup_nodes);let x=(null==v?void 0:null===(l=v.redis_client)||void 0===l?void 0:null===(t=l.connection_pool)||void 0===t?void 0:null===(s=t.connection_kwargs)||void 0===s?void 0:s.host)||(null==v?void 0:null===(i=v.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),h=(null==v?void 0:null===(c=v.redis_client)||void 0===c?void 0:null===(o=c.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==v?void 0:null===(u=v.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(d=m.connection_kwargs)||void 0===d?void 0:d.port);return x&&h?JSON.stringify([{host:x,port:h}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==v?void 0:v.namespace)||"N/A"};return(0,c.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"border-b border-gray-200 px-4",children:[(0,c.jsx)(e0.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,c.jsx)(e0.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{className:"p-4",children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,c.jsx)(eb.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,c.jsx)(ey.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,c.jsxs)(k.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,c.jsx)("table",{className:"w-full border-collapse",children:(0,c.jsxs)("tbody",{children:[j&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,c.jsx)(iA,{label:"Error Message",value:j.message}),(0,c.jsx)(iA,{label:"Traceback",value:j.traceback})]}),(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,c.jsx)(iA,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,c.jsx)(iA,{label:"Ping Response",value:String(g.ping_response)}),(0,c.jsx)(iA,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,c.jsx)(iA,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("tr",{children:(0,c.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,c.jsx)(iA,{label:"Redis Host",value:y.redis_host||"N/A"}),(0,c.jsx)(iA,{label:"Redis Port",value:y.redis_port||"N/A"}),(0,c.jsx)(iA,{label:"Redis Version",value:y.redis_version||"N/A"}),(0,c.jsx)(iA,{label:"Startup Nodes",value:y.startup_nodes||"N/A"}),(0,c.jsx)(iA,{label:"Namespace",value:y.namespace||"N/A"})]})]})})]})}),(0,c.jsx)(e4.Z,{className:"p-4",children:(0,c.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,c.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:v},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},iT=e=>{let{accessToken:s,healthCheckResponse:t,runCachingHealthCheck:l,responseTimeMs:a}=e,[r,i]=d.useState(null),[n,o]=d.useState(!1),m=async()=>{o(!0);let e=performance.now();await l(),i(performance.now()-e),o(!1)};return(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)(b.Z,{onClick:m,disabled:n,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:n?"Running Health Check...":"Run Health Check"}),(0,c.jsx)(iC,{responseTimeMs:r})]}),t&&(0,c.jsx)(iL,{response:t})]})},iP=e=>{if(e)return e.toISOString().split("T")[0]};function iE(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var iM=e=>{let{accessToken:s,token:t,userRole:l,userID:a,premiumUser:r}=e,[i,n]=(0,d.useState)([]),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)([]),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)("0"),[b,_]=(0,d.useState)("0"),[N,Z]=(0,d.useState)("0"),[w,S]=(0,d.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[C,I]=(0,d.useState)(""),[A,L]=(0,d.useState)("");(0,d.useEffect)(()=>{s&&w&&((async()=>{p(await (0,j.adminGlobalCacheActivity)(s,iP(w.from),iP(w.to)))})(),I(new Date().toLocaleString()))},[s]);let T=Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),P=Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(h.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let E=async(e,t)=>{e&&t&&s&&p(await (0,j.adminGlobalCacheActivity)(s,iP(e),iP(t)))};(0,d.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",h);let e=h;o.length>0&&(e=e.filter(e=>o.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 s=0,t=0,l=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"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),t+=a.cache_hit_true_rows||0,l+=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(iE(t)),_(iE(l));let r=t+s;r>0?Z((t/r*100).toFixed(2)):Z("0"),n(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,u,w,h]);let M=async()=>{try{eo.Z.info("Running cache health check..."),L("");let e=await (0,j.cachingHealthCheckCall)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),L(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let t=JSON.parse(s.message);t.error&&(t=t.error),e=t}catch(t){e={message:s.message}}else e={message:"Unknown error occurred"};L({error:e})}};return(0,c.jsxs)(e1.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,c.jsxs)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"Cache Analytics"}),(0,c.jsx)(e0.Z,{children:(0,c.jsx)("pre",{children:"Cache Health"})})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[C&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",C]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{I(new Date().toLocaleString())}})]})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)(y.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,c.jsx)(v.Z,{children:(0,c.jsx)(iN.Z,{placeholder:"Select API Keys",value:o,onValueChange:m,children:T.map(e=>(0,c.jsx)(iZ.Z,{value:e,children:e},e))})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(iN.Z,{placeholder:"Select Models",value:u,onValueChange:x,children:P.map(e=>(0,c.jsx)(iZ.Z,{value:e,children:e},e))})}),(0,c.jsx)(v.Z,{children:(0,c.jsx)(s5,{value:w,onValueChange:e=>{S(e),E(e.from,e.to)}})})]}),(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[N,"%"]})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,c.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,c.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:b})})]})]}),(0,c.jsx)(sz.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,c.jsx)(s3.Z,{title:"Cache Hits vs API Requests",data:i,stack:!0,index:"name",valueFormatter:iE,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,c.jsx)(sz.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,c.jsx)(s3.Z,{className:"mt-6",data:i,stack:!0,index:"name",valueFormatter:iE,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(iT,{accessToken:s,healthCheckResponse:A,runCachingHealthCheck:M})})]})]})},iO=t(91810);(a=n||(n={})).PresidioPII="Presidio PII",a.Bedrock="Bedrock Guardrail",a.Lakera="Lakera";let iD={},iF=e=>{let s={};return s.PresidioPII="Presidio PII",s.Bedrock="Bedrock Guardrail",s.Lakera="Lakera",Object.entries(e).forEach(e=>{let[t,l]=e;l&&"object"==typeof l&&"ui_friendly_name"in l&&(s[t.split("_").map((e,s)=>e.charAt(0).toUpperCase()+e.slice(1)).join("")]=l.ui_friendly_name)}),iD=s,s},iR=()=>Object.keys(iD).length>0?iD:n,iz={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},iU=e=>{Object.entries(e).forEach(e=>{let[s,t]=e;t&&"object"==typeof t&&"ui_friendly_name"in t&&(iz[s.split("_").map((e,s)=>e.charAt(0).toUpperCase()+e.slice(1)).join("")]=s)})},iq=e=>!!e&&"Presidio PII"===iR()[e],iB="../ui/assets/logos/",iV={"Presidio PII":"".concat(iB,"presidio.png"),"Bedrock Guardrail":"".concat(iB,"bedrock.svg"),Lakera:"".concat(iB,"lakeraai.jpeg"),"Azure Content Safety Prompt Shield":"".concat(iB,"presidio.png"),"Azure Content Safety Text Moderation":"".concat(iB,"presidio.png")},iK=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(iz).find(s=>iz[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let t=iR()[s];return{logo:iV[t]||"",displayName:t||e}};var iG=t(33866),iH=t(97416),iJ=t(10798),iY=t(49638);let{Text:iW}=en.default,{Option:i$}=I.default,iQ=e=>e.replace(/_/g," "),iX=e=>{switch(e){case"MASK":return(0,c.jsx)(iH.Z,{style:{marginRight:4}});case"BLOCK":return(0,c.jsx)(t4.Z,{style:{marginRight:4}});default:return null}},i0=e=>{let{categories:s,selectedCategories:t,onChange:l}=e;return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center mb-2",children:[(0,c.jsx)(iJ.Z,{className:"text-gray-500 mr-1"}),(0,c.jsx)(iW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:l,value:t,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,c.jsx)(t1.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,c.jsx)(i$,{value:e.category,children:e.category},e.category))})]})},i1=e=>{let{onSelectAll:s,onUnselectAll:t,hasSelectedEntities:l}=e;return(0,c.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(iW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,c.jsx)(V.Z,{title:"Apply action to all PII types at once",children:(0,c.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,c.jsx)(P.ZP,{type:"default",onClick:t,disabled:!l,icon:(0,c.jsx)(iY.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,c.jsx)(P.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,c.jsx)(iH.Z,{}),children:"Select All & Mask"}),(0,c.jsx)(P.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,c.jsx)(t4.Z,{}),children:"Select All & Block"})]})]})},i2=e=>{let{entities:s,selectedEntities:t,selectedActions:l,actions:a,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:n}=e;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,c.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,c.jsx)(iW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,c.jsx)(iW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,c.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,c.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,c.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(t.includes(e)?"bg-blue-50":""),children:[(0,c.jsxs)("div",{className:"flex items-center flex-1",children:[(0,c.jsx)(ts.Z,{checked:t.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,c.jsx)(iW,{className:t.includes(e)?"font-medium text-gray-900":"text-gray-700",children:iQ(e)}),n.get(e)&&(0,c.jsx)(t1.Z,{className:"ml-2 text-xs",color:"blue",children:n.get(e)})]}),(0,c.jsx)("div",{className:"w-32",children:(0,c.jsx)(I.default,{value:t.includes(e)&&l[e]||"MASK",onChange:s=>i(e,s),style:{width:120},disabled:!t.includes(e),className:"".concat(t.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,c.jsx)(i$,{value:e,children:(0,c.jsxs)("div",{className:"flex items-center",children:[iX(e),e]})},e))})})]},e))})]})},{Title:i4,Text:i5}=en.default;var i6=e=>{let{entities:s,actions:t,selectedEntities:l,selectedActions:a,onEntitySelect:r,onActionSelect:i,entityCategories:n=[]}=e,[o,m]=(0,d.useState)([]),u=new Map;n.forEach(e=>{e.entities.forEach(s=>{u.set(s,e.category)})});let x=s.filter(e=>0===o.length||o.includes(u.get(e)||""));return(0,c.jsxs)("div",{className:"pii-configuration",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,c.jsx)("div",{className:"flex items-center",children:(0,c.jsx)(i4,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,c.jsx)(iG.Z,{count:l.length,showZero:!0,style:{backgroundColor:l.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,c.jsxs)(i5,{className:"text-gray-500",children:[l.length," items selected"]})})]}),(0,c.jsxs)("div",{className:"mb-6",children:[(0,c.jsx)(i0,{categories:n,selectedCategories:o,onChange:m}),(0,c.jsx)(i1,{onSelectAll:e=>{s.forEach(s=>{l.includes(s)||r(s),i(s,e)})},onUnselectAll:()=>{l.forEach(e=>{r(e)})},hasSelectedEntities:l.length>0})]}),(0,c.jsx)(i2,{entities:x,selectedEntities:l,selectedActions:a,actions:t,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:u})]})},i3=e=>{var s;let{selectedProvider:t,accessToken:l,providerParams:a=null,value:r=null}=e,[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(a),[u,x]=(0,d.useState)(null);if((0,d.useEffect)(()=>{if(a){m(a);return}let e=async()=>{if(l){n(!0),x(null);try{let e=await (0,j.getGuardrailProviderSpecificParams)(l);console.log("Provider params API response:",e),m(e),iF(e),iU(e)}catch(e){console.error("Error fetching provider params:",e),x("Failed to load provider parameters")}finally{n(!1)}}};a||e()},[l,a]),!t)return null;if(i)return(0,c.jsx)(lI.Z,{tip:"Loading provider parameters..."});if(u)return(0,c.jsx)("div",{className:"text-red-500",children:u});let h=null===(s=iz[t])||void 0===s?void 0:s.toLowerCase(),p=o&&o[h];if(console.log("Provider key:",h),console.log("Provider fields:",p),!p||0===Object.keys(p).length)return(0,c.jsx)("div",{children:"No configuration fields available for this provider."});console.log("Value:",r);let g=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2?arguments[2]:void 0;return Object.entries(e).map(e=>{let[l,a]=e,i=s?"".concat(s,".").concat(l):l,n=t?t[l]:null==r?void 0:r[l];return(console.log("Field value:",n),"ui_friendly_name"===l||"optional_params"===l&&"nested"===a.type&&a.fields)?null:"nested"===a.type&&a.fields?(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"mb-2 font-medium",children:l}),(0,c.jsx)("div",{className:"ml-4 border-l-2 border-gray-200 pl-4",children:g(a.fields,i,n)})]},i):(0,c.jsx)(A.Z.Item,{name:i,label:l,tooltip:a.description,rules:a.required?[{required:!0,message:"".concat(l," is required")}]:void 0,children:"select"===a.type&&a.options?(0,c.jsx)(I.default,{placeholder:a.description,defaultValue:n||a.default_value,children:a.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"multiselect"===a.type&&a.options?(0,c.jsx)(I.default,{mode:"multiple",placeholder:a.description,defaultValue:n||a.default_value,children:a.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"bool"===a.type||"boolean"===a.type?(0,c.jsxs)(I.default,{placeholder:a.description,defaultValue:void 0!==n?String(n):a.default_value,children:[(0,c.jsx)(I.default.Option,{value:"true",children:"True"}),(0,c.jsx)(I.default.Option,{value:"false",children:"False"})]}):"number"===a.type?(0,c.jsx)(O,{step:1,width:400,placeholder:a.description,defaultValue:void 0!==n?Number(n):void 0}):l.includes("password")||l.includes("secret")||l.includes("key")?(0,c.jsx)(sW.o,{placeholder:a.description,type:"password",defaultValue:n||""}):(0,c.jsx)(sW.o,{placeholder:a.description,type:"text",defaultValue:n||""})},i)})};return(0,c.jsx)(c.Fragment,{children:g(p)})};let{Title:i8}=en.default,i7=e=>{let{field:s,fieldKey:t,fullFieldKey:l,value:a}=e,[r,i]=d.useState([]),[n,o]=d.useState(s.dict_key_options||[]);d.useEffect(()=>{if(a&&"object"==typeof a){let e=Object.keys(a);i(e.map(e=>({key:e,id:"".concat(e,"_").concat(Date.now(),"_").concat(Math.random())}))),o((s.dict_key_options||[]).filter(s=>!e.includes(s)))}},[a,s.dict_key_options]);let m=e=>{e&&(i([...r,{key:e,id:"".concat(e,"_").concat(Date.now())}]),o(n.filter(s=>s!==e)))},u=(e,s)=>{i(r.filter(s=>s.id!==e)),o([...n,s].sort())};return(0,c.jsxs)("div",{className:"space-y-3",children:[r.map(e=>(0,c.jsxs)("div",{className:"flex items-center space-x-3 p-3 border rounded-lg",children:[(0,c.jsx)("div",{className:"w-24 font-medium text-sm",children:e.key}),(0,c.jsx)("div",{className:"flex-1",children:(0,c.jsx)(A.Z.Item,{name:Array.isArray(l)?[...l,e.key]:[l,e.key],style:{marginBottom:0},initialValue:a&&"object"==typeof a?a[e.key]:void 0,normalize:"number"===s.dict_value_type?e=>{if(null==e||""===e)return;let s=Number(e);return isNaN(s)?e:s}:void 0,children:"number"===s.dict_value_type?(0,c.jsx)(O,{step:1,width:200,placeholder:"Enter ".concat(e.key," value")}):"boolean"===s.dict_value_type?(0,c.jsxs)(I.default,{placeholder:"Select ".concat(e.key," value"),children:[(0,c.jsx)(I.default.Option,{value:!0,children:"True"}),(0,c.jsx)(I.default.Option,{value:!1,children:"False"})]}):(0,c.jsx)(sW.o,{placeholder:"Enter ".concat(e.key," value"),type:"text"})})}),(0,c.jsx)("button",{type:"button",className:"text-red-500 hover:text-red-700 text-sm",onClick:()=>u(e.id,e.key),children:"Remove"})]},e.id)),n.length>0&&(0,c.jsxs)("div",{className:"flex items-center space-x-3 mt-2",children:[(0,c.jsx)(I.default,{placeholder:"Select category to configure",style:{width:200},onSelect:e=>e&&m(e),value:void 0,children:n.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}),(0,c.jsx)("span",{className:"text-sm text-gray-500",children:"Select a category to add threshold configuration"})]})]})};var i9=e=>{let{optionalParams:s,parentFieldKey:t,values:l}=e,a=(e,s)=>{let a="".concat(t,".").concat(e),r=null==l?void 0:l[e];return(console.log("value",r),"dict"===s.type&&s.dict_key_options)?(0,c.jsxs)("div",{className:"mb-8 p-6 bg-gray-50 rounded-lg border border-gray-200",children:[(0,c.jsx)("div",{className:"mb-4 font-medium text-gray-900 text-base",children:e}),(0,c.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:s.description}),(0,c.jsx)(i7,{field:s,fieldKey:e,fullFieldKey:[t,e],value:r})]},a):(0,c.jsx)("div",{className:"mb-8 p-6 bg-white rounded-lg border border-gray-200 shadow-sm",children:(0,c.jsx)(A.Z.Item,{name:[t,e],label:(0,c.jsxs)("div",{className:"mb-2",children:[(0,c.jsx)("div",{className:"font-medium text-gray-900 text-base",children:e}),(0,c.jsx)("p",{className:"text-sm text-gray-600 mt-1",children:s.description})]}),rules:s.required?[{required:!0,message:"".concat(e," is required")}]:void 0,className:"mb-0",initialValue:void 0!==r?r:s.default_value,normalize:"number"===s.type?e=>{if(null==e||""===e)return;let s=Number(e);return isNaN(s)?e:s}:void 0,children:"select"===s.type&&s.options?(0,c.jsx)(I.default,{placeholder:s.description,children:s.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"multiselect"===s.type&&s.options?(0,c.jsx)(I.default,{mode:"multiple",placeholder:s.description,children:s.options.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:e},e))}):"bool"===s.type||"boolean"===s.type?(0,c.jsxs)(I.default,{placeholder:s.description,children:[(0,c.jsx)(I.default.Option,{value:"true",children:"True"}),(0,c.jsx)(I.default.Option,{value:"false",children:"False"})]}):"number"===s.type?(0,c.jsx)(O,{step:1,width:400,placeholder:s.description}):e.includes("password")||e.includes("secret")||e.includes("key")?(0,c.jsx)(sW.o,{placeholder:s.description,type:"password"}):(0,c.jsx)(sW.o,{placeholder:s.description,type:"text"})})},a)};return s.fields&&0!==Object.keys(s.fields).length?(0,c.jsxs)("div",{className:"guardrail-optional-params",children:[(0,c.jsxs)("div",{className:"mb-8 pb-4 border-b border-gray-100",children:[(0,c.jsx)(i8,{level:3,className:"mb-2 font-semibold text-gray-900",children:"Optional Parameters"}),(0,c.jsx)("p",{className:"text-gray-600 text-sm",children:s.description||"Configure additional settings for this guardrail provider"})]}),(0,c.jsx)("div",{className:"space-y-8",children:Object.entries(s.fields).map(e=>{let[s,t]=e;return a(s,t)})})]}):null};let{Title:ne,Text:ns,Link:nt}=en.default,{Option:nl}=I.default,{Step:na}=iO.default,nr={pre_call:"Before LLM Call - Runs before the LLM call and checks the input (Recommended)",during_call:"During LLM Call - Runs in parallel with the LLM call, with response held until check completes",post_call:"After LLM Call - Runs after the LLM call and checks only the output",logging_only:"Logging Only - Only runs on logging callbacks without affecting the LLM call",pre_mcp_call:"Before MCP Tool Call - Runs before MCP tool execution and validates tool calls",during_mcp_call:"During MCP Tool Call - Runs in parallel with MCP tool execution for monitoring"};var ni=e=>{let{visible:s,onClose:t,accessToken:l,onSuccess:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(null),[h,p]=(0,d.useState)([]),[g,f]=(0,d.useState)({}),[v,y]=(0,d.useState)(0),[N,Z]=(0,d.useState)(null),[w,k]=(0,d.useState)([]),[S,C]=(0,d.useState)(2),[T,P]=(0,d.useState)({});(0,d.useEffect)(()=>{l&&(async()=>{try{let[e,s]=await Promise.all([(0,j.getGuardrailUISettings)(l),(0,j.getGuardrailProviderSpecificParams)(l)]);x(e),Z(s),iF(s),iU(s)}catch(e){console.error("Error fetching guardrail data:",e),eo.Z.fromBackend("Failed to load guardrail configuration")}})()},[l]);let E=e=>{m(e),r.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),p([]),f({}),k([]),C(2),P({})},M=e=>{p(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},O=(e,s)=>{f(t=>({...t,[e]:s}))},D=async()=>{try{if(0===v&&(await r.validateFields(["guardrail_name","provider","mode","default_on"]),o)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===o&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await r.validateFields(e)}if(1===v&&iq(o)&&0===h.length){eo.Z.fromBackend("Please select at least one PII entity to continue");return}y(v+1)}catch(e){console.error("Form validation failed:",e)}},F=()=>{r.resetFields(),m(null),p([]),f({}),k([]),C(2),P({}),y(0)},R=()=>{F(),t()},z=async()=>{try{n(!0),await r.validateFields();let s=r.getFieldsValue(!0),i=iz[s.provider],c={guardrail_name:s.guardrail_name,litellm_params:{guardrail:i,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&h.length>0){let e={};h.forEach(s=>{e[s]=g[s]||"MASK"}),c.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(c.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(c.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);c.guardrail_info=e}catch(e){eo.Z.fromBackend("Invalid JSON in configuration"),n(!1);return}if(console.log("values: ",JSON.stringify(s)),N&&o){var e;let t=null===(e=iz[o])||void 0===e?void 0:e.toLowerCase();console.log("providerKey: ",t);let l=N[t]||{},a=new Set;console.log("providerSpecificParams: ",JSON.stringify(l)),Object.keys(l).forEach(e=>{"optional_params"!==e&&a.add(e)}),l.optional_params&&l.optional_params.fields&&Object.keys(l.optional_params.fields).forEach(e=>{a.add(e)}),console.log("allowedParams: ",a),a.forEach(e=>{let t=s[e];if(null==t||""===t){var l;t=null===(l=s.optional_params)||void 0===l?void 0:l[e]}null!=t&&""!==t&&(c.litellm_params[e]=t)})}if(!l)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(c)),await (0,j.createGuardrailCall)(l,c),eo.Z.success("Guardrail created successfully"),F(),a(),t()}catch(e){console.error("Failed to create guardrail:",e),eo.Z.fromBackend("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{n(!1)}},U=()=>{var e;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter a name for this guardrail"})}),(0,c.jsx)(A.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{placeholder:"Select a guardrail provider",onChange:E,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(iR()).map(e=>{let[s,t]=e;return(0,c.jsx)(nl,{value:s,label:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]}),children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(A.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,c.jsx)(I.default,{optionLabelProp:"label",mode:"multiple",children:(null==u?void 0:null===(e=u.supported_modes)||void 0===e?void 0:e.map(e=>(0,c.jsx)(nl,{value:e,label:e,children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:e}),"pre_call"===e&&(0,c.jsx)(t1.Z,{color:"green",style:{marginLeft:"8px"},children:"Recommended"})]}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr[e]})]})},e)))||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(nl,{value:"pre_call",label:"pre_call",children:(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("strong",{children:"pre_call"})," ",(0,c.jsx)(t1.Z,{color:"green",children:"Recommended"})]}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.pre_call})]})}),(0,c.jsx)(nl,{value:"during_call",label:"during_call",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"during_call"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.during_call})]})}),(0,c.jsx)(nl,{value:"post_call",label:"post_call",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"post_call"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.post_call})]})}),(0,c.jsx)(nl,{value:"logging_only",label:"logging_only",children:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:(0,c.jsx)("strong",{children:"logging_only"})}),(0,c.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:nr.logging_only})]})})]})})}),(0,c.jsx)(A.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default.",children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:!0,children:"Yes"}),(0,c.jsx)(I.default.Option,{value:!1,children:"No"})]})}),(0,c.jsx)(i3,{selectedProvider:o,accessToken:l,providerParams:N})]})},q=()=>u&&"PresidioPII"===o?(0,c.jsx)(i6,{entities:u.supported_entities,actions:u.supported_actions,selectedEntities:h,selectedActions:g,onEntitySelect:M,onActionSelect:O,entityCategories:u.pii_entity_categories}):null,B=()=>{var e;if(!o||!N)return null;console.log("guardrail_provider_map: ",iz),console.log("selectedProvider: ",o);let s=null===(e=iz[o])||void 0===e?void 0:e.toLowerCase(),t=N&&N[s];return t&&t.optional_params?(0,c.jsx)(i9,{optionalParams:t.optional_params,parentFieldKey:"optional_params"}):null};return(0,c.jsx)(L.Z,{title:"Add Guardrail",open:s,onCancel:R,footer:null,width:700,children:(0,c.jsxs)(A.Z,{form:r,layout:"vertical",initialValues:{mode:"pre_call",default_on:!1},children:[(0,c.jsxs)(iO.default,{current:v,className:"mb-6",children:[(0,c.jsx)(na,{title:"Basic Info"}),(0,c.jsx)(na,{title:iq(o)?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(v){case 0:return U();case 1:if(iq(o))return q();return B();default:return null}})(),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[v>0&&(0,c.jsx)(b.Z,{variant:"secondary",onClick:()=>{y(v-1)},children:"Previous"}),v<2&&(0,c.jsx)(b.Z,{onClick:D,children:"Next"}),2===v&&(0,c.jsx)(b.Z,{onClick:z,loading:i,children:"Create Guardrail"}),(0,c.jsx)(b.Z,{variant:"secondary",onClick:R,children:"Cancel"})]})]})})};let{Title:nn,Text:no}=en.default,{Option:nc}=I.default;var nd=e=>{var s;let{visible:t,onClose:l,accessToken:a,onSuccess:r,guardrailId:i,initialValues:n}=e,[o]=A.Z.useForm(),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)((null==n?void 0:n.provider)||null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)([]),[y,N]=(0,d.useState)({});(0,d.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,j.getGuardrailUISettings)(a);g(e)}catch(e){console.error("Error fetching guardrail settings:",e),eo.Z.fromBackend("Failed to load guardrail settings")}})()},[a]),(0,d.useEffect)(()=>{(null==n?void 0:n.pii_entities_config)&&Object.keys(n.pii_entities_config).length>0&&(v(Object.keys(n.pii_entities_config)),N(n.pii_entities_config))},[n]);let Z=e=>{v(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},w=(e,s)=>{N(t=>({...t,[e]:s}))},k=async()=>{try{u(!0);let e=await o.validateFields(),s=iz[e.provider],t={guardrail_id:i,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=y[s]||"MASK"}),t.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(t.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(t.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):t.guardrail.guardrail_info=s}catch(e){eo.Z.fromBackend("Invalid JSON in configuration"),u(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(t));let n=await fetch("/guardrails/".concat(i),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let e=await n.text();throw Error(e||"Failed to update guardrail")}eo.Z.success("Guardrail updated successfully"),r(),l()}catch(e){console.error("Failed to update guardrail:",e),eo.Z.fromBackend("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{u(!1)}},S=()=>p&&x&&"PresidioPII"===x?(0,c.jsx)(i6,{entities:p.supported_entities,actions:p.supported_actions,selectedEntities:f,selectedActions:y,onEntitySelect:Z,onActionSelect:w,entityCategories:p.pii_entity_categories}):null;return(0,c.jsx)(L.Z,{title:"Edit Guardrail",open:t,onCancel:l,footer:null,width:700,children:(0,c.jsxs)(A.Z,{form:o,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,c.jsx)(_.Z,{placeholder:"Enter a name for this guardrail"})}),(0,c.jsx)(A.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{placeholder:"Select a guardrail provider",onChange:e=>{h(e),o.setFieldsValue({config:void 0}),v([]),N({})},disabled:!0,optionLabelProp:"label",children:Object.entries(iR()).map(e=>{let[s,t]=e;return(0,c.jsx)(nc,{value:s,label:t,children:(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[iV[t]&&(0,c.jsx)("img",{src:iV[t],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,c.jsx)("span",{children:t})]})},s)})})}),(0,c.jsx)(A.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,c.jsx)(I.default,{children:(null==p?void 0:null===(s=p.supported_modes)||void 0===s?void 0:s.map(e=>(0,c.jsx)(nc,{value:e,children:e},e)))||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(nc,{value:"pre_call",children:"pre_call"}),(0,c.jsx)(nc,{value:"post_call",children:"post_call"})]})})}),(0,c.jsx)(A.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,c.jsx)(tj.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return S();switch(x){case"Aporia":return(0,c.jsx)(A.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,c.jsx)(A.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,c.jsx)(A.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,c.jsx)(A.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,c.jsx)(A.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,c.jsx)(A.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,c.jsx)(A.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,c.jsx)(E.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,c.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:k,loading:m,children:"Update Guardrail"})]})]})})},nm=e=>{let{guardrailsList:s,isLoading:t,onDeleteClick:l,accessToken:a,onGuardrailUpdated:r,isAdmin:i=!1,onGuardrailClick:n}=e,[o,m]=(0,d.useState)([{id:"created_at",desc:!0}]),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),g=e=>e?new Date(e).toLocaleString():"-",j=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.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:()=>e.getValue()&&n(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.guardrail_name,children:(0,c.jsx)("span",{className:"text-xs font-medium",children:t.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:t,displayName:l}=iK(s.original.litellm_params.guardrail);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,c.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.litellm_params.mode})}},{header:"Default On",accessorKey:"litellm_params.default_on",cell:e=>{var s,t;let{row:l}=e,a=l.original;return(0,c.jsx)(eX.Z,{color:(null===(s=a.litellm_params)||void 0===s?void 0:s.default_on)?"green":"gray",className:"text-xs font-normal",size:"xs",children:(null===(t=a.litellm_params)||void 0===t?void 0:t.default_on)?"Default On":"Default Off"})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.created_at,children:(0,c.jsx)("span",{className:"text-xs",children:g(t.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.updated_at,children:(0,c.jsx)("span",{className:"text-xs",children:g(t.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"flex space-x-2",children:(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>t.guardrail_id&&l(t.guardrail_id,t.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],f=(0,s_.b7)({data:s,columns:j,state:{sorting:o},onSortingChange:m,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:f.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:t?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:j.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"Loading..."})})})}):s.length>0?f.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:j.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No guardrails found"})})})})})]})}),h&&(0,c.jsx)(nd,{visible:u,onClose:()=>x(!1),accessToken:a,onSuccess:()=>{x(!1),p(null),r()},guardrailId:h.guardrail_id||"",initialValues:{guardrail_name:h.guardrail_name||"",provider:Object.keys(iz).find(e=>iz[e]===(null==h?void 0:h.litellm_params.guardrail))||"",mode:h.litellm_params.mode,default_on:h.litellm_params.default_on,pii_entities_config:h.litellm_params.pii_entities_config,...h.guardrail_info}})]})},nu=e=>{var s,t,l,a,r,i,n,o,m,u,x;let{guardrailId:h,onClose:p,accessToken:g,isAdmin:f}=e,[v,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(null),[C,L]=(0,d.useState)(!0),[T,M]=(0,d.useState)(!1),[O]=A.Z.useForm(),[D,F]=(0,d.useState)([]),[R,z]=(0,d.useState)({}),[U,q]=(0,d.useState)(null),[B,V]=(0,d.useState)({}),H=async()=>{try{var e;if(L(!0),!g)return;let s=await (0,j.getGuardrailInfo)(g,h);if(N(s),null===(e=s.litellm_params)||void 0===e?void 0:e.pii_entities_config){let e=s.litellm_params.pii_entities_config;if(F([]),z({}),Object.keys(e).length>0){let s=[],t={};Object.entries(e).forEach(e=>{let[l,a]=e;s.push(l),t[l]="string"==typeof a?a:"MASK"}),F(s),z(t)}}else F([]),z({})}catch(e){eo.Z.fromBackend("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{L(!1)}},J=async()=>{try{if(!g)return;let e=await (0,j.getGuardrailProviderSpecificParams)(g);w(e)}catch(e){console.error("Error fetching guardrail provider specific params:",e)}},Y=async()=>{try{if(!g)return;let e=await (0,j.getGuardrailUISettings)(g);q(e)}catch(e){console.error("Error fetching guardrail UI settings:",e)}};(0,d.useEffect)(()=>{J()},[g]),(0,d.useEffect)(()=>{H(),Y()},[h,g]),(0,d.useEffect)(()=>{if(v&&O){var e;O.setFieldsValue({guardrail_name:v.guardrail_name,...v.litellm_params,guardrail_info:v.guardrail_info?JSON.stringify(v.guardrail_info,null,2):"",...(null===(e=v.litellm_params)||void 0===e?void 0:e.optional_params)&&{optional_params:v.litellm_params.optional_params}})}},[v,Z,O]);let W=async e=>{try{var s,t,l;if(!g)return;let a={litellm_params:{}};e.guardrail_name!==v.guardrail_name&&(a.guardrail_name=e.guardrail_name),e.default_on!==(null===(s=v.litellm_params)||void 0===s?void 0:s.default_on)&&(a.litellm_params.default_on=e.default_on);let r=v.guardrail_info,i=e.guardrail_info?JSON.parse(e.guardrail_info):void 0;JSON.stringify(r)!==JSON.stringify(i)&&(a.guardrail_info=i);let n=(null===(t=v.litellm_params)||void 0===t?void 0:t.pii_entities_config)||{},o={};D.forEach(e=>{o[e]=R[e]||"MASK"}),JSON.stringify(n)!==JSON.stringify(o)&&(a.litellm_params.pii_entities_config=o);let c=Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)});if(console.log("values: ",JSON.stringify(e)),console.log("currentProvider: ",c),Z&&c){let s=Z[null===(l=iz[c])||void 0===l?void 0:l.toLowerCase()]||{},t=new Set;console.log("providerSpecificParams: ",JSON.stringify(s)),Object.keys(s).forEach(e=>{"optional_params"!==e&&t.add(e)}),s.optional_params&&s.optional_params.fields&&Object.keys(s.optional_params.fields).forEach(e=>{t.add(e)}),console.log("allowedParams: ",t),t.forEach(s=>{var t,l;let r=e[s];(null==r||""===r)&&(r=null===(l=e.optional_params)||void 0===l?void 0:l[s]);let i=null===(t=v.litellm_params)||void 0===t?void 0:t[s];JSON.stringify(r)!==JSON.stringify(i)&&(null!=r&&""!==r?a.litellm_params[s]=r:null!=i&&""!==i&&(a.litellm_params[s]=null))})}if(0===Object.keys(a.litellm_params).length&&delete a.litellm_params,0===Object.keys(a).length){eo.Z.info("No changes detected"),M(!1);return}await (0,j.updateGuardrailCall)(g,h,a),eo.Z.success("Guardrail updated successfully"),H(),M(!1)}catch(e){console.error("Error updating guardrail:",e),eo.Z.fromBackend("Failed to update guardrail")}};if(C)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!v)return(0,c.jsx)("div",{className:"p-4",children:"Guardrail not found"});let $=e=>e?new Date(e).toLocaleString():"-",{logo:Q,displayName:X}=iK((null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)||""),ee=async(e,s)=>{await eM(e)&&(V(e=>({...e,[s]:!0})),setTimeout(()=>{V(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:p,className:"mb-4",children:"Back to Guardrails"}),(0,c.jsx)(S.Z,{children:v.guardrail_name||"Unnamed Guardrail"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:v.guardrail_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:B["guardrail-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>ee(v.guardrail_id,"guardrail-id"),className:"left-2 z-10 transition-all duration-200 ".concat(B["guardrail-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),f?(0,c.jsx)(e0.Z,{children:"Settings"},"settings"):(0,c.jsx)(c.Fragment,{})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Provider"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[Q&&(0,c.jsx)("img",{src:Q,alt:"".concat(X," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,c.jsx)(S.Z,{children:X})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Mode"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:(null===(t=v.litellm_params)||void 0===t?void 0:t.mode)||"-"}),(0,c.jsx)(eX.Z,{color:(null===(l=v.litellm_params)||void 0===l?void 0:l.default_on)?"green":"gray",children:(null===(a=v.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Created At"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:$(v.created_at)}),(0,c.jsxs)(k.Z,{children:["Last Updated: ",$(v.updated_at)]})]})]})]}),(null===(r=v.litellm_params)||void 0===r?void 0:r.pii_entities_config)&&Object.keys(v.litellm_params.pii_entities_config).length>0&&(0,c.jsx)(G.Z,{className:"mt-6",children:(0,c.jsxs)("div",{className:"flex justify-between items-center",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"PII Protection"}),(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(v.litellm_params.pii_entities_config).length," PII entities configured"]})]})}),v.guardrail_info&&Object.keys(v.guardrail_info).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsx)(k.Z,{children:"Guardrail Info"}),(0,c.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(v.guardrail_info).map(e=>{let[s,t]=e;return(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(k.Z,{className:"font-medium w-1/3",children:s}),(0,c.jsx)(k.Z,{className:"w-2/3",children:"object"==typeof t?JSON.stringify(t,null,2):String(t)})]},s)})})]})]}),f&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Guardrail Settings"}),!T&&(0,c.jsx)(b.Z,{onClick:()=>M(!0),children:"Edit Settings"})]}),T?(0,c.jsxs)(A.Z,{form:O,onFinish:W,initialValues:{guardrail_name:v.guardrail_name,...v.litellm_params,guardrail_info:v.guardrail_info?JSON.stringify(v.guardrail_info,null,2):"",...(null===(i=v.litellm_params)||void 0===i?void 0:i.optional_params)&&{optional_params:v.litellm_params.optional_params}},layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Default On",name:"default_on",children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:!0,children:"Yes"}),(0,c.jsx)(I.default.Option,{value:!1,children:"No"})]})}),(null===(n=v.litellm_params)||void 0===n?void 0:n.guardrail)==="presidio"&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(K.Z,{orientation:"left",children:"PII Protection"}),(0,c.jsx)("div",{className:"mb-6",children:U&&(0,c.jsx)(i6,{entities:U.supported_entities,actions:U.supported_actions,selectedEntities:D,selectedActions:R,onEntitySelect:e=>{F(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},onActionSelect:(e,s)=>{z(t=>({...t,[e]:s}))},entityCategories:U.pii_entity_categories})})]}),(0,c.jsx)(K.Z,{orientation:"left",children:"Provider Settings"}),(0,c.jsx)(i3,{selectedProvider:Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)})||null,accessToken:g,providerParams:Z,value:v.litellm_params}),Z&&(()=>{var e;let s=Object.keys(iz).find(e=>{var s;return iz[e]===(null===(s=v.litellm_params)||void 0===s?void 0:s.guardrail)});if(!s)return null;let t=Z[null===(e=iz[s])||void 0===e?void 0:e.toLowerCase()];return t&&t.optional_params?(0,c.jsx)(i9,{optionalParams:t.optional_params,parentFieldKey:"optional_params",values:v.litellm_params}):null})(),(0,c.jsx)(K.Z,{orientation:"left",children:"Advanced Settings"}),(0,c.jsx)(A.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,c.jsx)(E.default.TextArea,{rows:5})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,c.jsx)(P.ZP,{onClick:()=>M(!1),children:"Cancel"}),(0,c.jsx)(b.Z,{children:"Save Changes"})]})]}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Guardrail ID"}),(0,c.jsx)("div",{className:"font-mono",children:v.guardrail_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Guardrail Name"}),(0,c.jsx)("div",{children:v.guardrail_name||"Unnamed Guardrail"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Provider"}),(0,c.jsx)("div",{children:X})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Mode"}),(0,c.jsx)("div",{children:(null===(o=v.litellm_params)||void 0===o?void 0:o.mode)||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Default On"}),(0,c.jsx)(eX.Z,{color:(null===(m=v.litellm_params)||void 0===m?void 0:m.default_on)?"green":"gray",children:(null===(u=v.litellm_params)||void 0===u?void 0:u.default_on)?"Yes":"No"})]}),(null===(x=v.litellm_params)||void 0===x?void 0:x.pii_entities_config)&&Object.keys(v.litellm_params.pii_entities_config).length>0&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"PII Protection"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsxs)(eX.Z,{color:"blue",children:[Object.keys(v.litellm_params.pii_entities_config).length," PII entities configured"]})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:$(v.created_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)("div",{children:$(v.updated_at)})]})]})]})})]})]})]})},nx=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)([]),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(!1),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),f=!!t&&(0,eI.tY)(t),v=async()=>{if(s){o(!0);try{let e=await (0,j.getGuardrailsList)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,d.useEffect)(()=>{v()},[s]);let y=async()=>{if(x&&s){u(!0);try{await (0,j.deleteGuardrailCall)(s,x.id),eo.Z.success('Guardrail "'.concat(x.name,'" deleted successfully')),v()}catch(e){console.error("Error deleting guardrail:",e),eo.Z.fromBackend("Failed to delete guardrail")}finally{u(!1),h(null)}}};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(b.Z,{onClick:()=>{p&&g(null),i(!0)},disabled:!s,children:"+ Add New Guardrail"})}),p?(0,c.jsx)(nu,{guardrailId:p,onClose:()=>g(null),accessToken:s,isAdmin:f}):(0,c.jsx)(nm,{guardrailsList:l,isLoading:n,onDeleteClick:(e,s)=>{h({id:e,name:s})},accessToken:s,onGuardrailUpdated:v,isAdmin:f,onGuardrailClick:e=>g(e)}),(0,c.jsx)(ni,{visible:r,onClose:()=>{i(!1)},accessToken:s,onSuccess:()=>{v()}}),x&&(0,c.jsxs)(L.Z,{title:"Delete Guardrail",open:null!==x,onOk:y,onCancel:()=>{h(null)},confirmLoading:m,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",x.name," ?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})},nh=e=>{let{promptsList:s,isLoading:t,onPromptClick:l,onDeleteClick:a,accessToken:r,isAdmin:i}=e,[n,o]=(0,d.useState)([{id:"created_at",desc:!0}]),m=e=>e?new Date(e).toLocaleString():"-",u=[{header:"Prompt ID",accessorKey:"prompt_id",cell:e=>(0,c.jsx)(V.Z,{title:String(e.getValue()||""),children:(0,c.jsx)(b.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:()=>e.getValue()&&(null==l?void 0:l(e.getValue())),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.created_at,children:(0,c.jsx)("span",{className:"text-xs",children:m(t.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.updated_at,children:(0,c.jsx)("span",{className:"text-xs",children:m(t.updated_at)})})}},{header:"Type",accessorKey:"prompt_info.prompt_type",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.prompt_info.prompt_type,children:(0,c.jsx)("span",{className:"text-xs",children:t.prompt_info.prompt_type})})}},...i?[{header:"Actions",id:"actions",enableSorting:!1,cell:e=>{let{row:s}=e,t=s.original,l=t.prompt_id||"Unknown Prompt";return(0,c.jsx)("div",{className:"flex items-center gap-1",children:(0,c.jsx)(V.Z,{title:"Delete prompt",children:(0,c.jsx)(b.Z,{size:"xs",variant:"light",color:"red",onClick:e=>{e.stopPropagation(),null==a||a(t.prompt_id,l)},icon:W.Z,className:"text-red-500 hover:text-red-700 hover:bg-red-50"})})})}}]:[]],x=(0,s_.b7)({data:s,columns:u,state:{sorting:n},onSortingChange:o,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:x.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.Z,{className:"py-1 h-8",onClick:e.column.getToggleSortingHandler(),children:(0,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:t?(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:u.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"Loading..."})})})}):s.length>0?x.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:u.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No prompts found"})})})})})]})})})},np=e=>{var s,t,l;let{promptId:a,onClose:r,accessToken:i,isAdmin:n,onDelete:o}=e,[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null),[f,v]=(0,d.useState)(!0),[_,N]=(0,d.useState)({}),[Z,w]=(0,d.useState)(!1),[C,I]=(0,d.useState)(!1),A=async()=>{try{if(v(!0),!i)return;let e=await (0,j.getPromptInfo)(i,a);u(e.prompt_spec),h(e.raw_prompt_template),g(e)}catch(e){eo.Z.fromBackend("Failed to load prompt information"),console.error("Error fetching prompt info:",e)}finally{v(!1)}};if((0,d.useEffect)(()=>{A()},[a,i]),f)return(0,c.jsx)("div",{className:"p-4",children:"Loading..."});if(!m)return(0,c.jsx)("div",{className:"p-4",children:"Prompt not found"});let T=e=>e?new Date(e).toLocaleString():"-",E=async(e,s)=>{await eM(e)&&(N(e=>({...e,[s]:!0})),setTimeout(()=>{N(e=>({...e,[s]:!1}))},2e3))},M=async()=>{if(i&&m){I(!0);try{await (0,j.deletePromptCall)(i,m.prompt_id),eo.Z.success('Prompt "'.concat(m.prompt_id,'" deleted successfully')),null==o||o(),r()}catch(e){console.error("Error deleting prompt:",e),eo.Z.fromBackend("Failed to delete prompt")}finally{I(!1),w(!1)}}};return(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",onClick:r,className:"mb-4",children:"Back to Prompts"}),(0,c.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{children:"Prompt Details"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:m.prompt_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["prompt-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>E(m.prompt_id,"prompt-id"),className:"left-2 z-10 transition-all duration-200 ".concat(_["prompt-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),n&&(0,c.jsx)(b.Z,{icon:W.Z,variant:"secondary",onClick:()=>{w(!0)},className:"flex items-center",children:"Delete Prompt"})]})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),x?(0,c.jsx)(e0.Z,{children:"Prompt Template"},"prompt-template"):(0,c.jsx)(c.Fragment,{}),n?(0,c.jsx)(e0.Z,{children:"Details"},"details"):(0,c.jsx)(c.Fragment,{}),(0,c.jsx)(e0.Z,{children:"Raw JSON"},"raw-json")]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Prompt ID"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{className:"font-mono text-sm",children:m.prompt_id})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Prompt Type"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:(null===(s=m.prompt_info)||void 0===s?void 0:s.prompt_type)||"-"}),(0,c.jsx)(eX.Z,{color:"blue",className:"mt-1",children:(null===(t=m.prompt_info)||void 0===t?void 0:t.prompt_type)||"Unknown"})]})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Created At"}),(0,c.jsxs)("div",{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:T(m.created_at)}),(0,c.jsxs)(k.Z,{children:["Last Updated: ",T(m.updated_at)]})]})]})]}),m.litellm_params&&Object.keys(m.litellm_params).length>0&&(0,c.jsxs)(G.Z,{className:"mt-6",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Parameters"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(m.litellm_params,null,2)})})]})]}),x&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Prompt Template"}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["prompt-content"]?(0,c.jsx)(sm.Z,{size:16}):(0,c.jsx)(su.Z,{size:16}),onClick:()=>E(x.content,"prompt-content"),className:"transition-all duration-200 ".concat(_["prompt-content"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:_["prompt-content"]?"Copied!":"Copy Content"})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Template ID"}),(0,c.jsx)("div",{className:"font-mono text-sm bg-gray-50 p-2 rounded",children:x.litellm_prompt_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Content"}),(0,c.jsx)("div",{className:"mt-2 p-4 bg-gray-50 rounded-md border overflow-auto max-h-96",children:(0,c.jsx)("pre",{className:"text-sm text-gray-800 whitespace-pre-wrap",children:x.content})})]}),x.metadata&&Object.keys(x.metadata).length>0&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Template Metadata"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap overflow-auto max-h-64",children:JSON.stringify(x.metadata,null,2)})})]})]})]})}),n&&(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(S.Z,{className:"mb-4",children:"Prompt Details"}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt ID"}),(0,c.jsx)("div",{className:"font-mono text-sm bg-gray-50 p-2 rounded",children:m.prompt_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt Type"}),(0,c.jsx)("div",{children:(null===(l=m.prompt_info)||void 0===l?void 0:l.prompt_type)||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created At"}),(0,c.jsx)("div",{children:T(m.created_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)("div",{children:T(m.updated_at)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"LiteLLM Parameters"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap overflow-auto max-h-96",children:JSON.stringify(m.litellm_params,null,2)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Prompt Info"}),(0,c.jsx)("div",{className:"mt-2 p-3 bg-gray-50 rounded-md border",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(m.prompt_info,null,2)})})]})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Raw API Response"}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:_["raw-json"]?(0,c.jsx)(sm.Z,{size:16}):(0,c.jsx)(su.Z,{size:16}),onClick:()=>E(JSON.stringify(p,null,2),"raw-json"),className:"transition-all duration-200 ".concat(_["raw-json"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:_["raw-json"]?"Copied!":"Copy JSON"})]}),(0,c.jsx)("div",{className:"p-4 bg-gray-50 rounded-md border overflow-auto",children:(0,c.jsx)("pre",{className:"text-xs text-gray-800 whitespace-pre-wrap",children:JSON.stringify(p,null,2)})})]})})]})]}),(0,c.jsxs)(L.Z,{title:"Delete Prompt",open:Z,onOk:M,onCancel:()=>{w(!1)},confirmLoading:C,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete prompt: ",(0,c.jsx)("strong",{children:null==m?void 0:m.prompt_id}),"?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})};let{Option:ng}=I.default;var nj=e=>{let{visible:s,onClose:t,accessToken:l,onSuccess:a}=e,[r]=A.Z.useForm(),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)("dotprompt"),h=()=>{r.resetFields(),m([]),x("dotprompt"),t()},p=async()=>{try{let e=await r.validateFields();if(console.log("values: ",e),!l){eo.Z.fromBackend("Access token is required");return}if("dotprompt"===u&&0===o.length){eo.Z.fromBackend("Please upload a .prompt file");return}n(!0);let s={};if("dotprompt"===u&&o.length>0){let t=o[0].originFileObj;try{let a=await (0,j.convertPromptFileToJson)(l,t);console.log("Conversion result:",a),s={prompt_id:e.prompt_id,litellm_params:{prompt_integration:"dotprompt",prompt_id:a.prompt_id,prompt_data:a.json_data},prompt_info:{prompt_type:"db"}}}catch(e){console.error("Error converting prompt file:",e),eo.Z.fromBackend("Failed to convert prompt file to JSON"),n(!1);return}}try{await (0,j.createPromptCall)(l,s),eo.Z.success("Prompt created successfully!"),h(),a()}catch(e){console.error("Error creating prompt:",e),eo.Z.fromBackend("Failed to create prompt")}}catch(e){console.error("Form validation error:",e)}finally{n(!1)}};return(0,c.jsx)(L.Z,{title:"Add New Prompt",open:s,onCancel:h,footer:[(0,c.jsx)(P.ZP,{onClick:h,children:"Cancel"},"cancel"),(0,c.jsx)(P.ZP,{loading:i,onClick:p,children:"Create Prompt"},"submit")],width:600,children:(0,c.jsxs)(A.Z,{form:r,layout:"vertical",requiredMark:!1,children:[(0,c.jsx)(A.Z.Item,{label:"Prompt ID",name:"prompt_id",rules:[{required:!0,message:"Please enter a prompt ID"},{pattern:/^[a-zA-Z0-9_-]+$/,message:"Prompt ID can only contain letters, numbers, underscores, and hyphens"}],children:(0,c.jsx)(sW.o,{placeholder:"Enter unique prompt ID (e.g., my_prompt_id)"})}),(0,c.jsx)(A.Z.Item,{label:"Prompt Integration",name:"prompt_integration",initialValue:"dotprompt",children:(0,c.jsx)(I.default,{value:u,onChange:x,children:(0,c.jsx)(ng,{value:"dotprompt",children:"dotprompt"})})}),"dotprompt"===u&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(K.Z,{}),(0,c.jsxs)(A.Z.Item,{label:"Prompt File",extra:"Upload a .prompt file that follows the Dotprompt specification",children:[(0,c.jsx)(ed.default,{beforeUpload:e=>(e.name.endsWith(".prompt")||eo.Z.fromBackend("Please upload a .prompt file"),!1),fileList:o,onChange:e=>{let{fileList:s}=e;m(s.slice(-1))},onRemove:()=>{m([])},children:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(ej.Z,{}),children:"Select .prompt File"})}),o.length>0&&(0,c.jsxs)("div",{className:"mt-2 text-sm text-gray-600",children:["Selected: ",o[0].name]})]})]})]})})},nf=e=>{let{accessToken:s,userRole:t}=e,[l,a]=(0,d.useState)([]),[r,i]=(0,d.useState)(!1),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(!1),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)(null),f=!!t&&(0,eI.tY)(t),v=async()=>{if(s){i(!0);try{let e=await (0,j.getPromptsList)(s);console.log("prompts: ".concat(JSON.stringify(e))),a(e.prompts)}catch(e){console.error("Error fetching prompts:",e)}finally{i(!1)}}};(0,d.useEffect)(()=>{v()},[s]);let y=async()=>{if(p&&s){h(!0);try{await (0,j.deletePromptCall)(s,p.id),eo.Z.success('Prompt "'.concat(p.name,'" deleted successfully')),v()}catch(e){console.error("Error deleting prompt:",e),eo.Z.fromBackend("Failed to delete prompt")}finally{h(!1),g(null)}}};return(0,c.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[n?(0,c.jsx)(np,{promptId:n,onClose:()=>o(null),accessToken:s,isAdmin:f,onDelete:v}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(b.Z,{onClick:()=>{n&&o(null),u(!0)},disabled:!s,children:"+ Add New Prompt"})}),(0,c.jsx)(nh,{promptsList:l,isLoading:r,onPromptClick:e=>{o(e)},onDeleteClick:(e,s)=>{g({id:e,name:s})},accessToken:s,isAdmin:f})]}),(0,c.jsx)(nj,{visible:m,onClose:()=>{u(!1)},accessToken:s,onSuccess:()=>{v()}}),p&&(0,c.jsxs)(L.Z,{title:"Delete Prompt",open:null!==p,onOk:y,onCancel:()=>{g(null)},confirmLoading:x,okText:"Delete",okButtonProps:{danger:!0},children:[(0,c.jsxs)("p",{children:["Are you sure you want to delete prompt: ",p.name," ?"]}),(0,c.jsx)("p",{children:"This action cannot be undone."})]})]})},nv=e=>{let{accessToken:s}=e,[t,l]=(0,d.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,d.useState)(""),[i,n]=(0,d.useState)(!1),o=(e,s,t)=>{let l=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(t).map(e=>{let[s,t]=e;return"-H '".concat(s,": ").concat(t,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(l,"\n }'")},m=async()=>{n(!0);try{let e;try{e=JSON.parse(t)}catch(e){eo.Z.fromBackend("Invalid JSON in request body"),n(!1);return}let l={call_type:"completion",request_body:e};if(!s){eo.Z.fromBackend("No access token found"),n(!1);return}let a=await (0,j.transformRequestCall)(s,l);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),eo.Z.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),eo.Z.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),eo.Z.fromBackend("Failed to transform request")}finally{n(!1)}};return(0,c.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,c.jsx)(S.Z,{children:"Playground"}),(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,c.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,c.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,c.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,c.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,c.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,c.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:t,onChange:e=>l(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),m())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,c.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,c.jsxs)(P.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:m,loading:i,children:[(0,c.jsx)("span",{children:"Transform"}),(0,c.jsx)("span",{children:"→"})]})})]}),(0,c.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,c.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,c.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,c.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,c.jsx)("br",{}),(0,c.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,c.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,c.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,c.jsx)(P.ZP,{type:"text",icon:(0,c.jsx)(tR.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),eo.Z.success("Copied to clipboard")}})]})]})]}),(0,c.jsx)("div",{className:"mt-4 text-right w-full",children:(0,c.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,c.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})};let ny=e=>{try{let s=e.indexOf("/mcp/");if(-1===s)return{token:null,baseUrl:e};let t=e.split("/mcp/");if(2!==t.length)return{token:null,baseUrl:e};let l=t[0]+"/mcp/",a=t[1];if(!a)return{token:null,baseUrl:e};return{token:a,baseUrl:l}}catch(s){return console.error("Error parsing MCP URL:",s),{token:null,baseUrl:e}}},nb=e=>{let{token:s,baseUrl:t}=ny(e);return s?t+"...":e},n_=e=>{let{token:s}=ny(e);return{maskedUrl:nb(e),hasToken:!!s}},nN=e=>e?/^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(e)?Promise.resolve():Promise.reject("Please enter a valid URL (e.g., http://service-name.domain:1234/path or https://example.com)"):Promise.resolve(),nZ=e=>e&&e.includes("-")?Promise.reject("Server name cannot contain '-' (hyphen). Please use '_' (underscore) instead."):Promise.resolve(),nw=(e,s,t,l)=>[{accessorKey:"server_id",header:"Server ID",cell:e=>{let{row:t}=e;return(0,c.jsxs)("button",{onClick:()=>s(t.original.server_id),className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",children:[t.original.server_id.slice(0,7),"..."]})}},{accessorKey:"server_name",header:"Name"},{accessorKey:"alias",header:"Alias"},{id:"url",header:"URL",cell:e=>{let{row:s}=e,{maskedUrl:t}=n_(s.original.url);return(0,c.jsx)("span",{className:"font-mono text-sm",children:t})}},{accessorKey:"transport",header:"Transport",cell:e=>{let{getValue:s}=e;return(0,c.jsx)("span",{children:(s()||"http").toUpperCase()})}},{accessorKey:"auth_type",header:"Auth Type",cell:e=>{let{getValue:s}=e;return(0,c.jsx)("span",{children:s()||"none"})}},{id:"mcp_access_groups",header:"Access Groups",cell:e=>{let{row:s}=e,t=s.original.mcp_access_groups;if(Array.isArray(t)&&t.length>0&&"string"==typeof t[0]){let e=t.join(", ");return(0,c.jsx)(V.Z,{title:e,children:(0,c.jsx)("span",{className:"max-w-[200px] truncate block",children:e.length>30?"".concat(e.slice(0,30),"..."):e})})}return(0,c.jsx)("span",{className:"text-gray-400 italic",children:"None"})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.created_at?new Date(t.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:t.updated_at?new Date(t.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e;return(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>t(s.original.server_id),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(s.original.server_id),className:"cursor-pointer"})]})}}];var nk=t(82376),nS=t(71437);let nC={NONE:"none",API_KEY:"api_key",BEARER_TOKEN:"bearer_token",BASIC:"basic"},nI={SSE:"sse"},nA=e=>(console.log(e),null==e)?nI.SSE:e,nL=e=>null==e?nC.NONE:e,nT=e=>nL(e)!==nC.NONE;var nP=t(62670),nE=e=>{let{value:s={},onChange:t,tools:l=[],disabled:a=!1}=e,r=(e,l)=>{let a={...s,tool_name_to_cost_per_query:{...s.tool_name_to_cost_per_query,[e]:l}};null==t||t(a)};return(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,c.jsx)(nP.Z,{className:"text-green-600"}),(0,c.jsx)(S.Z,{children:"Cost Configuration"}),(0,c.jsx)(V.Z,{title:"Configure costs for this MCP server's tool calls. Set a default rate and per-tool overrides.",children:(0,c.jsx)(B.Z,{className:"text-gray-400"})})]}),(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Default Cost per Query ($)",(0,c.jsx)(V.Z,{title:"Default cost charged for each tool call to this server.",children:(0,c.jsx)(B.Z,{className:"ml-1 text-gray-400"})})]}),(0,c.jsx)(eW.Z,{min:0,step:1e-4,precision:4,placeholder:"0.0000",value:s.default_cost_per_query,onChange:e=>{let l={...s,default_cost_per_query:e};null==t||t(l)},disabled:a,style:{width:"200px"},addonBefore:"$"}),(0,c.jsx)(k.Z,{className:"block mt-1 text-gray-500 text-sm",children:"Set a default cost for all tool calls to this server"})]}),l.length>0&&(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("label",{className:"block text-sm font-medium text-gray-700",children:["Tool-Specific Costs ($)",(0,c.jsx)(V.Z,{title:"Override the default cost for specific tools. Leave blank to use the default rate.",children:(0,c.jsx)(B.Z,{className:"ml-1 text-gray-400"})})]}),(0,c.jsx)(t_.default,{items:[{key:"1",label:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2 text-blue-500"}),(0,c.jsx)("span",{className:"font-medium",children:"Available Tools"}),(0,c.jsx)(iG.Z,{count:l.length,style:{backgroundColor:"#52c41a",marginLeft:"8px"}})]}),children:(0,c.jsx)("div",{className:"space-y-3 max-h-64 overflow-y-auto",children:l.map((e,t)=>{var l;return(0,c.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-lg",children:[(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900",children:e.name}),e.description&&(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm block mt-1",children:e.description})]}),(0,c.jsx)("div",{className:"ml-4",children:(0,c.jsx)(eW.Z,{min:0,step:1e-4,precision:4,placeholder:"Use default",value:null===(l=s.tool_name_to_cost_per_query)||void 0===l?void 0:l[e.name],onChange:s=>r(e.name,s),disabled:a,style:{width:"120px"},addonBefore:"$"})})]},t)})})}]})]})]}),(s.default_cost_per_query||s.tool_name_to_cost_per_query&&Object.keys(s.tool_name_to_cost_per_query).length>0)&&(0,c.jsxs)("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"text-blue-800 font-medium",children:"Cost Summary:"}),(0,c.jsxs)("div",{className:"mt-2 space-y-1",children:[s.default_cost_per_query&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• Default cost: $",s.default_cost_per_query.toFixed(4)," per query"]}),s.tool_name_to_cost_per_query&&Object.entries(s.tool_name_to_cost_per_query).map(e=>{let[s,t]=e;return null!=t&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• ",s,": $",t.toFixed(4)," per query"]},s)})]})]})]})})},nM=e=>{let{mcpServer:s,accessToken:t,onCancel:l,onSuccess:a,availableAccessGroups:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)({}),[m,u]=(0,d.useState)([]),[x,h]=(0,d.useState)(!1),[p,g]=(0,d.useState)(""),[f,v]=(0,d.useState)(!1);(0,d.useEffect)(()=>{var e;(null===(e=s.mcp_info)||void 0===e?void 0:e.mcp_server_cost_info)&&o(s.mcp_info.mcp_server_cost_info)},[s]),(0,d.useEffect)(()=>{if(s.mcp_access_groups){let e=s.mcp_access_groups.map(e=>"string"==typeof e?e:e.name||String(e));i.setFieldValue("mcp_access_groups",e)}},[s]),(0,d.useEffect)(()=>{y()},[s,t]);let y=async()=>{if(t&&s.url){h(!0);try{let e={server_id:s.server_id,server_name:s.server_name,url:s.url,transport:s.transport,auth_type:s.auth_type,mcp_info:s.mcp_info},l=await (0,j.testMCPToolsListRequest)(t,e);l.tools&&!l.error?u(l.tools):(console.error("Failed to fetch tools:",l.message),u([]))}catch(e){console.error("Tools fetch error:",e),u([])}finally{h(!1)}}},N=async e=>{if(t)try{let l=(e.mcp_access_groups||[]).map(e=>"string"==typeof e?e:e.name||String(e)),r={...e,server_id:s.server_id,mcp_info:{server_name:e.server_name||e.url,description:e.description,mcp_server_cost_info:Object.keys(n).length>0?n:null},mcp_access_groups:l,alias:e.alias},i=await (0,j.updateMCPServer)(t,r);eo.Z.success("MCP Server updated successfully"),a(i)}catch(e){eo.Z.fromBackend("Failed to update MCP Server"+((null==e?void 0:e.message)?": ".concat(e.message):""))}};return(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"grid w-full grid-cols-2",children:[(0,c.jsx)(e0.Z,{children:"Server Configuration"}),(0,c.jsx)(e0.Z,{children:"Cost Configuration"})]}),(0,c.jsxs)(e5.Z,{className:"mt-6",children:[(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:N,initialValues:s,layout:"vertical",children:[(0,c.jsx)(A.Z.Item,{label:"MCP Server Name",name:"server_name",rules:[{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Alias",name:"alias",rules:[{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{onChange:()=>v(!0)})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"MCP Server URL",name:"url",rules:[{required:!0,message:"Please enter a server URL"},{validator:(e,s)=>nN(s)}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Transport Type",name:"transport",rules:[{required:!0}],children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:"sse",children:"Server-Sent Events (SSE)"}),(0,c.jsx)(I.default.Option,{value:"http",children:"HTTP"})]})}),(0,c.jsx)(A.Z.Item,{label:"Authentication",name:"auth_type",rules:[{required:!0}],children:(0,c.jsxs)(I.default,{children:[(0,c.jsx)(I.default.Option,{value:"none",children:"None"}),(0,c.jsx)(I.default.Option,{value:"api_key",children:"API Key"}),(0,c.jsx)(I.default.Option,{value:"bearer_token",children:"Bearer Token"}),(0,c.jsx)(I.default.Option,{value:"basic",children:"Basic Auth"})]})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Access Groups",(0,c.jsx)(V.Z,{title:"Define access groups for this MCP server. Each group represents a set of permissions.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"mcp_access_groups",getValueFromEvent:e=>e,children:(0,c.jsx)(I.default,{mode:"tags",style:{width:"100%"},showSearch:!0,placeholder:"Add or select access groups",tokenSeparators:[","],optionFilterProp:"value",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.value)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},onSearch:e=>g(e),options:(()=>{let e=r.map(e=>({value:e,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})}));return p&&!r.some(e=>e.toLowerCase().includes(p.toLowerCase()))&&e.push({value:p,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:p}),(0,c.jsx)("span",{className:"text-gray-400 text-xs ml-1",children:"create new group"})]})}),e})(),getPopupContainer:e=>e.parentNode})}),(0,c.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,c.jsx)(P.ZP,{onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{type:"submit",children:"Save Changes"})]})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsx)(nE,{value:n,onChange:o,tools:m,disabled:x}),(0,c.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,c.jsx)(P.ZP,{onClick:l,children:"Cancel"}),(0,c.jsx)(b.Z,{onClick:()=>i.submit(),children:"Save Changes"})]})]})})]})]})},nO=e=>{let{costConfig:s}=e,t=(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null,l=(null==s?void 0:s.tool_name_to_cost_per_query)&&Object.keys(s.tool_name_to_cost_per_query).length>0;return t||l?(0,c.jsx)("div",{className:"mt-6 pt-6 border-t border-gray-200",children:(0,c.jsxs)("div",{className:"space-y-4",children:[t&&(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Default Cost per Query"}),(0,c.jsxs)("div",{className:"text-green-600 font-mono",children:["$",s.default_cost_per_query.toFixed(4)]})]}),l&&(null==s?void 0:s.tool_name_to_cost_per_query)&&(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Tool-Specific Costs"}),(0,c.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(s.tool_name_to_cost_per_query).map(e=>{let[s,t]=e;return null!=t&&(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 bg-gray-50 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"font-medium",children:s}),(0,c.jsxs)(k.Z,{className:"text-green-600 font-mono",children:["$",t.toFixed(4)," per query"]})]},s)})})]}),(0,c.jsxs)("div",{className:"mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"text-blue-800 font-medium",children:"Cost Summary:"}),(0,c.jsxs)("div",{className:"mt-2 space-y-1",children:[t&&(null==s?void 0:s.default_cost_per_query)!==void 0&&(null==s?void 0:s.default_cost_per_query)!==null&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• Default cost: $",s.default_cost_per_query.toFixed(4)," per query"]}),l&&(null==s?void 0:s.tool_name_to_cost_per_query)&&(0,c.jsxs)(k.Z,{className:"text-blue-700",children:["• ",Object.keys(s.tool_name_to_cost_per_query).length," tool(s) with custom pricing"]})]})]})]})}):(0,c.jsx)("div",{className:"mt-6 pt-6 border-t border-gray-200",children:(0,c.jsx)("div",{className:"space-y-4",children:(0,c.jsx)("div",{className:"p-4 bg-gray-50 border border-gray-200 rounded-lg",children:(0,c.jsx)(k.Z,{className:"text-gray-600",children:"No cost configuration set for this server. Tool calls will be charged at $0.00 per tool call."})})})})};let nD=e=>{var s,t,l,a;let{mcpServer:r,onBack:i,isEditing:n,isProxyAdmin:o,accessToken:m,userRole:u,userID:x,availableAccessGroups:h}=e,[p,g]=(0,d.useState)(n),[j,f]=(0,d.useState)(!1),[v,_]=(0,d.useState)({}),{maskedUrl:N,hasToken:Z}=n_(r.url),w=(e,s)=>Z?s?e:N:e,C=async(e,s)=>{await eM(e)&&(_(e=>({...e,[s]:!0})),setTimeout(()=>{_(e=>({...e,[s]:!1}))},2e3))};return(0,c.jsxs)("div",{className:"p-4 max-w-full",children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",className:"mb-4",onClick:i,children:"Back to All Servers"}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(S.Z,{children:r.server_name}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-server_name"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.server_name,"mcp-server_name"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-server_name"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")}),r.alias&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("span",{className:"ml-4 text-gray-500",children:"Alias:"}),(0,c.jsx)("span",{className:"ml-1 font-mono text-blue-600",children:r.alias}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-alias"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.alias,"mcp-alias"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-alias"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]}),(0,c.jsxs)("div",{className:"flex items-center cursor-pointer",children:[(0,c.jsx)(k.Z,{className:"text-gray-500 font-mono",children:r.server_id}),(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:v["mcp-server-id"]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>C(r.server_id,"mcp-server-id"),className:"left-2 z-10 transition-all duration-200 ".concat(v["mcp-server-id"]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")})]})]})}),(0,c.jsxs)(e1.Z,{defaultIndex:p?2:0,children:[(0,c.jsx)(e2.Z,{className:"mb-4",children:[(0,c.jsx)(e0.Z,{children:"Overview"},"overview"),(0,c.jsx)(e0.Z,{children:"MCP Tools"},"tools"),...o?[(0,c.jsx)(e0.Z,{children:"Settings"},"settings")]:[]]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsxs)(e4.Z,{children:[(0,c.jsxs)(y.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Transport"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(S.Z,{children:nA(null!==(l=r.transport)&&void 0!==l?l:void 0)})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Auth Type"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(k.Z,{children:nL(null!==(a=r.auth_type)&&void 0!==a?a:void 0)})})]}),(0,c.jsxs)(G.Z,{children:[(0,c.jsx)(k.Z,{children:"Host Url"}),(0,c.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,c.jsx)(k.Z,{className:"break-all overflow-wrap-anywhere",children:w(r.url,j)}),Z&&(0,c.jsx)("button",{onClick:()=>f(!j),className:"p-1 hover:bg-gray-100 rounded",children:(0,c.jsx)(sZ.Z,{icon:j?nk.Z:nS.Z,size:"sm",className:"text-gray-500"})})]})]})]}),(0,c.jsxs)(G.Z,{className:"mt-2",children:[(0,c.jsx)(S.Z,{children:"Cost Configuration"}),(0,c.jsx)(nO,{costConfig:null===(s=r.mcp_info)||void 0===s?void 0:s.mcp_server_cost_info})]})]}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(os,{serverId:r.server_id,accessToken:m,auth_type:r.auth_type,userRole:u,userID:x,serverAlias:r.alias})}),(0,c.jsx)(e4.Z,{children:(0,c.jsxs)(G.Z,{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"MCP Server Settings"}),p?null:(0,c.jsx)(b.Z,{variant:"light",onClick:()=>g(!0),children:"Edit Settings"})]}),p?(0,c.jsx)(nM,{mcpServer:r,accessToken:m,onCancel:()=>g(!1),onSuccess:e=>{g(!1),i()},availableAccessGroups:h}):(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Server Name"}),(0,c.jsx)("div",{children:r.server_name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Alias"}),(0,c.jsx)("div",{children:r.alias})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Description"}),(0,c.jsx)("div",{children:r.description})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"URL"}),(0,c.jsxs)("div",{className:"font-mono break-all overflow-wrap-anywhere max-w-full flex items-center gap-2",children:[w(r.url,j),Z&&(0,c.jsx)("button",{onClick:()=>f(!j),className:"p-1 hover:bg-gray-100 rounded",children:(0,c.jsx)(sZ.Z,{icon:j?nk.Z:nS.Z,size:"sm",className:"text-gray-500"})})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Transport"}),(0,c.jsx)("div",{children:nA(r.transport)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Auth Type"}),(0,c.jsx)("div",{children:nL(r.auth_type)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Access Groups"}),(0,c.jsx)("div",{children:r.mcp_access_groups&&r.mcp_access_groups.length>0?(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:r.mcp_access_groups.map((e,s)=>{var t;return(0,c.jsx)("span",{className:"px-2 py-1 bg-gray-100 rounded-md text-sm",children:"string"==typeof e?e:null!==(t=null==e?void 0:e.name)&&void 0!==t?t:""},s)})}):(0,c.jsx)(k.Z,{className:"text-gray-500",children:"No access groups defined"})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Cost Configuration"}),(0,c.jsx)(nO,{costConfig:null===(t=r.mcp_info)||void 0===t?void 0:t.mcp_server_cost_info})]})]})]})})]})]})]})};var nF=t(83669);let{Panel:nR}=t_.default;var nz=e=>{let{accessToken:s,formValues:t,onToolsLoaded:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),h=t.url&&t.transport&&t.auth_type&&s,p=async()=>{if(s&&t.url){n(!0),m(null);try{let e={server_id:t.server_id||"",server_name:t.server_name||"",url:t.url,transport:t.transport,auth_type:t.auth_type,mcp_info:t.mcp_info},a=await (0,j.testMCPToolsListRequest)(s,e);if(a.tools&&!a.error)r(a.tools),m(null),null==l||l(a.tools),a.tools.length>0&&!u&&x(!0);else{let e=a.message||"Failed to retrieve tools list";m(e),r([]),null==l||l([]),x(!1)}}catch(e){console.error("Tools fetch error:",e),m(e instanceof Error?e.message:String(e)),r([]),null==l||l([]),x(!1)}finally{n(!1)}}};return((0,d.useEffect)(()=>{h?p():(r([]),m(null),x(!1),null==l||l([]))},[t.url,t.transport,t.auth_type,s]),h||t.url)?(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)(nF.Z,{className:"text-blue-600"}),(0,c.jsx)(S.Z,{children:"Connection Status"})]}),!h&&t.url&&(0,c.jsxs)("div",{className:"text-center py-6 text-gray-400 border rounded-lg border-dashed",children:[(0,c.jsx)(rC.Z,{className:"text-2xl mb-2"}),(0,c.jsx)(k.Z,{children:"Complete required fields to test connection"}),(0,c.jsx)("br",{}),(0,c.jsx)(k.Z,{className:"text-sm",children:"Fill in URL, Transport, and Authentication to test MCP server connection"})]}),h&&(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-gray-700 font-medium",children:i?"Testing connection to MCP server...":a.length>0?"Connection successful":o?"Connection failed":"Ready to test connection"}),(0,c.jsx)("br",{}),(0,c.jsxs)(k.Z,{className:"text-gray-500 text-sm",children:["Server: ",t.url]})]}),i&&(0,c.jsxs)("div",{className:"flex items-center text-blue-600",children:[(0,c.jsx)(lI.Z,{size:"small",className:"mr-2"}),(0,c.jsx)(k.Z,{className:"text-blue-600",children:"Connecting..."})]}),!i&&!o&&a.length>0&&(0,c.jsxs)("div",{className:"flex items-center text-green-600",children:[(0,c.jsx)(nF.Z,{className:"mr-1"}),(0,c.jsx)(k.Z,{className:"text-green-600 font-medium",children:"Connected"})]}),o&&(0,c.jsxs)("div",{className:"flex items-center text-red-600",children:[(0,c.jsx)(lY.Z,{className:"mr-1"}),(0,c.jsx)(k.Z,{className:"text-red-600 font-medium",children:"Failed"})]})]}),i&&(0,c.jsxs)("div",{className:"flex items-center justify-center py-6",children:[(0,c.jsx)(lI.Z,{size:"large"}),(0,c.jsx)(k.Z,{className:"ml-3",children:"Testing connection and loading tools..."})]}),o&&(0,c.jsx)(ls.Z,{message:"Connection Failed",description:o,type:"error",showIcon:!0,action:(0,c.jsx)(P.ZP,{icon:(0,c.jsx)(tl.Z,{}),onClick:p,size:"small",children:"Retry"})}),!i&&a.length>0&&(0,c.jsx)(t_.default,{items:[{key:"1",label:(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2 text-green-500"}),(0,c.jsx)("span",{className:"font-medium",children:"Available Tools"}),(0,c.jsx)(iG.Z,{count:a.length,style:{backgroundColor:"#52c41a",marginLeft:"8px"}})]}),children:(0,c.jsx)("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:a.map((e,s)=>(0,c.jsxs)("div",{className:"p-3 bg-gray-50 rounded-lg",children:[(0,c.jsx)(k.Z,{className:"font-medium text-gray-900",children:e.name}),e.description&&(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm block mt-1",children:e.description})]},s))})}]}),!i&&0===a.length&&!o&&(0,c.jsxs)("div",{className:"text-center py-6 text-gray-500 border rounded-lg border-dashed",children:[(0,c.jsx)(nF.Z,{className:"text-2xl mb-2 text-green-500"}),(0,c.jsx)(k.Z,{className:"text-green-600 font-medium",children:"Connection successful!"}),(0,c.jsx)("br",{}),(0,c.jsx)(k.Z,{className:"text-gray-500",children:"No tools found for this MCP server"})]})]})]})}):null},nU=e=>{let{isVisible:s}=e;return s?(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Stdio Configuration (JSON)",(0,c.jsx)(V.Z,{title:"Paste your stdio MCP server configuration in JSON format. You can use the full mcpServers structure from config.yaml or just the inner server configuration.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"stdio_config",rules:[{required:!0,message:"Please enter stdio configuration"},{validator:(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}}}],children:(0,c.jsx)(E.default.TextArea,{placeholder:'{\n "mcpServers": {\n "circleci-mcp-server": {\n "command": "npx",\n "args": ["-y", "@circleci/mcp-server-circleci"],\n "env": {\n "CIRCLECI_TOKEN": "your-circleci-token",\n "CIRCLECI_BASE_URL": "https://circleci.com"\n }\n }\n }\n}',rows:12,className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500 font-mono text-sm"})}):null};let nq="".concat("../ui/assets/logos/","mcp_logo.png");var nB=e=>{let{userRole:s,accessToken:t,onCreateSuccess:l,isModalVisible:a,setModalVisible:r,availableAccessGroups:i}=e,[n]=A.Z.useForm(),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)({}),[h,p]=(0,d.useState)({}),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)([]),[N,Z]=(0,d.useState)("sse"),[w,k]=(0,d.useState)(""),[S,C]=(0,d.useState)(""),T=(e,s)=>{if(!e){C("");return}"sse"!==s||e.endsWith("/sse")?"http"!==s||e.endsWith("/mcp")?C(""):C("Typically MCP HTTP URLs end with /mcp. You can add this url but this is a warning."):C("Typically MCP SSE URLs end with /sse. You can add this url but this is a warning.")},P=async e=>{m(!0);try{let s=e.mcp_access_groups,a={};if(e.stdio_config&&"stdio"===N)try{let s=JSON.parse(e.stdio_config),t=s;if(s.mcpServers&&"object"==typeof s.mcpServers){let l=Object.keys(s.mcpServers);if(l.length>0){let a=l[0];t=s.mcpServers[a],e.server_name||(e.server_name=a.replace(/-/g,"_"))}}a={command:t.command,args:t.args,env:t.env},console.log("Parsed stdio config:",a)}catch(e){eo.Z.fromBackend("Invalid JSON in stdio configuration");return}let i={...e,...a,stdio_config:void 0,mcp_info:{server_name:e.server_name||e.url,description:e.description,mcp_server_cost_info:Object.keys(u).length>0?u:null},mcp_access_groups:s,alias:e.alias};if(console.log("Payload: ".concat(JSON.stringify(i))),null!=t){let e=await (0,j.createMCPServer)(t,i);eo.Z.success("MCP Server created successfully"),n.resetFields(),x({}),y([]),C(""),r(!1),l(e)}}catch(e){eo.Z.fromBackend("Error creating MCP Server: "+e)}finally{m(!1)}},E=()=>{n.resetFields(),x({}),y([]),C(""),r(!1)};return(d.useEffect(()=>{if(!g&&h.server_name){let e=h.server_name.replace(/\s+/g,"_");n.setFieldsValue({alias:e}),p(s=>({...s,alias:e}))}},[h.server_name]),(0,eI.tY)(s))?(0,c.jsx)(L.Z,{title:(0,c.jsxs)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:[(0,c.jsx)("img",{src:nq,alt:"MCP Logo",className:"w-8 h-8 object-contain",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"}}),(0,c.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add New MCP Server"})]}),open:a,width:1e3,onCancel:E,footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsxs)(A.Z,{form:n,onFinish:P,onValuesChange:(e,s)=>p(s),layout:"vertical",className:"space-y-6",children:[(0,c.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Server Name",(0,c.jsx)(V.Z,{title:"Best practice: Use a descriptive name that indicates the server's purpose (e.g., 'GitHub_MCP', 'Email_Service'). Hyphens '-' are not allowed; use underscores '_' instead.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"server_name",rules:[{required:!1,message:"Please enter a server name"},{validator:(e,s)=>nZ(s)}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., GitHub_MCP, Zapier_MCP, etc.",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["Alias",(0,c.jsx)(V.Z,{title:"A short, unique identifier for this server. Defaults to the server name with spaces replaced by underscores.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"alias",rules:[{required:!1},{validator:(e,s)=>s&&s.includes("-")?Promise.reject("Alias cannot contain '-' (hyphen). Please use '_' (underscore) instead."):Promise.resolve()}],children:(0,c.jsx)(_.Z,{placeholder:"e.g., GitHub_MCP, Zapier_MCP, etc.",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500",onChange:()=>f(!0)})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Description"}),name:"description",rules:[{required:!1,message:"Please enter a server description"}],children:(0,c.jsx)(_.Z,{placeholder:"Brief description of what this server does",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Transport Type"}),name:"transport",rules:[{required:!0,message:"Please select a transport type"}],children:(0,c.jsxs)(I.default,{placeholder:"Select transport",className:"rounded-lg",size:"large",onChange:e=>{if(Z(e),"stdio"===e)n.setFieldsValue({url:void 0,auth_type:void 0}),C("");else{n.setFieldsValue({command:void 0,args:void 0,env:void 0});let s=n.getFieldValue("url");s&&T(s,e)}},value:N,children:[(0,c.jsx)(I.default.Option,{value:"http",children:"HTTP"}),(0,c.jsx)(I.default.Option,{value:"sse",children:"Server-Sent Events (SSE)"}),(0,c.jsx)(I.default.Option,{value:"stdio",children:"Standard Input/Output (stdio)"})]})}),"stdio"!==N&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"MCP Server URL"}),name:"url",rules:[{required:!0,message:"Please enter a server URL"},{validator:(e,s)=>nN(s)}],children:(0,c.jsxs)("div",{children:[(0,c.jsx)(_.Z,{placeholder:"https://your-mcp-server.com",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500",onChange:e=>T(e.target.value,N)}),S&&(0,c.jsx)("div",{className:"mt-1 text-red-500 text-sm font-medium",children:S})]})}),"stdio"!==N&&(0,c.jsx)(A.Z.Item,{label:(0,c.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Authentication"}),name:"auth_type",rules:[{required:!0,message:"Please select an auth type"}],children:(0,c.jsxs)(I.default,{placeholder:"Select auth type",className:"rounded-lg",size:"large",children:[(0,c.jsx)(I.default.Option,{value:"none",children:"None"}),(0,c.jsx)(I.default.Option,{value:"api_key",children:"API Key"}),(0,c.jsx)(I.default.Option,{value:"bearer_token",children:"Bearer Token"}),(0,c.jsx)(I.default.Option,{value:"basic",children:"Basic Auth"})]})}),(0,c.jsx)(nU,{isVisible:"stdio"===N}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:["MCP Access Groups",(0,c.jsx)(V.Z,{title:"Specify access groups for this MCP server. Users must be in at least one of these groups to access the server.",children:(0,c.jsx)(B.Z,{className:"ml-2 text-blue-400 hover:text-blue-600 cursor-help"})})]}),name:"mcp_access_groups",className:"mb-4",children:(0,c.jsx)(I.default,{mode:"tags",showSearch:!0,placeholder:"Select existing groups or type to create new ones",optionFilterProp:"value",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.value)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},onSearch:e=>k(e),tokenSeparators:[","],options:(()=>{let e=i.map(e=>({value:e,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})}));return w&&!i.some(e=>e.toLowerCase().includes(w.toLowerCase()))&&e.push({value:w,label:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:w}),(0,c.jsx)("span",{className:"text-gray-400 text-xs ml-1",children:"create new group"})]})}),e})(),maxTagCount:"responsive",allowClear:!0})})]}),(0,c.jsx)("div",{className:"mt-8 pt-6 border-t border-gray-200",children:(0,c.jsx)(nz,{accessToken:t,formValues:h,onToolsLoaded:y})}),(0,c.jsx)("div",{className:"mt-6",children:(0,c.jsx)(nE,{value:u,onChange:x,tools:v,disabled:!1})}),(0,c.jsxs)("div",{className:"flex items-center justify-end space-x-3 pt-6 border-t border-gray-100",children:[(0,c.jsx)(b.Z,{variant:"secondary",onClick:E,children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",loading:o,children:o?"Creating...":"Add MCP Server"})]})]})})}):null},nV=t(64935),nK=t(11239),nG=t(54001),nH=t(96137),nJ=t(96362),nY=t(80221),nW=t(29202);let{Title:n$,Text:nQ}=en.default,{Panel:nX}=t_.default,n0=e=>{let{icon:s,title:t,description:l,children:a,serverName:r,accessGroups:i=["dev"]}=e,[n,o]=(0,d.useState)(!1),m=()=>{let e={"x-litellm-api-key":"Bearer YOUR_LITELLM_API_KEY"};if(n&&r){let s=[r.replace(/\s+/g,"_"),...i].join(",");e["x-mcp-servers"]=[s]}return e};return(0,c.jsxs)(tN.Z,{className:"border border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)("span",{className:"p-2 rounded-lg bg-gray-50",children:s}),(0,c.jsxs)("div",{children:[(0,c.jsx)(n$,{level:5,className:"mb-0",children:t}),(0,c.jsx)(nQ,{className:"text-gray-600",children:l})]})]}),r&&("Implementation Example"===t||"Configuration"===t)&&(0,c.jsxs)(A.Z.Item,{className:"mb-4",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(tj.Z,{size:"small",checked:n,onChange:o}),(0,c.jsxs)(nQ,{className:"text-sm",children:["Limit tools to specific MCP servers or MCP groups by passing the ",(0,c.jsx)("code",{children:"x-mcp-servers"})," header"]})]}),n&&(0,c.jsx)(ls.Z,{className:"mt-2",type:"info",showIcon:!0,message:"Two Options",description:(0,c.jsxs)("div",{children:[(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Option 1:"})," Get a specific server: ",(0,c.jsxs)("code",{children:['["',r.replace(/\s+/g,"_"),'"]']})]}),(0,c.jsxs)("p",{children:[(0,c.jsx)("strong",{children:"Option 2:"})," Get a group of MCPs: ",(0,c.jsx)("code",{children:'["dev-group"]'})]}),(0,c.jsxs)("p",{className:"mt-2 text-sm text-gray-600",children:["You can also mix both: ",(0,c.jsx)("code",{children:'["Server1,dev-group"]'})]})]})})]}),d.Children.map(a,e=>{if(d.isValidElement(e)&&e.props.hasOwnProperty("code")&&e.props.hasOwnProperty("copyKey")){let s=e.props.code;if(s&&s.includes('"headers":'))return d.cloneElement(e,{code:s.replace(/"headers":\s*{[^}]*}/,'"headers": '.concat(JSON.stringify(m(),null,8)))})}return e})]})};var n1=e=>{let{currentServerAccessGroups:s=[]}=e,t=(0,j.getProxyBaseUrl)(),[l,a]=(0,d.useState)({}),[r,i]=(0,d.useState)({openai:[],litellm:[],cursor:[],http:[]}),[n]=(0,d.useState)("Zapier_MCP"),o=async(e,s)=>{await eM(e)&&(a(e=>({...e,[s]:!0})),setTimeout(()=>{a(e=>({...e,[s]:!1}))},2e3))},m=e=>{let{code:s,copyKey:t,title:a,className:r=""}=e;return(0,c.jsxs)("div",{className:"relative group",children:[a&&(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(nV.Z,{size:16,className:"text-blue-600"}),(0,c.jsx)(nQ,{strong:!0,className:"text-gray-700",children:a})]}),(0,c.jsxs)(tN.Z,{className:"bg-gray-50 border border-gray-200 relative ".concat(r),children:[(0,c.jsx)(P.ZP,{type:"text",size:"small",icon:l[t]?(0,c.jsx)(sm.Z,{size:12}):(0,c.jsx)(su.Z,{size:12}),onClick:()=>o(s,t),className:"absolute top-2 right-2 z-10 transition-all duration-200 ".concat(l[t]?"text-green-600 bg-green-50 border-green-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100")}),(0,c.jsx)("pre",{className:"text-sm overflow-x-auto pr-10 text-gray-800 font-mono leading-relaxed",children:s})]})]})},u=e=>{let{step:s,title:t,children:l}=e;return(0,c.jsxs)("div",{className:"flex gap-4",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("div",{className:"w-8 h-8 bg-blue-600 text-white rounded-full flex items-center justify-center text-sm font-semibold",children:s})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsx)(nQ,{strong:!0,className:"text-gray-800 block mb-2",children:t}),l]})]})};return(0,c.jsx)("div",{children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(S.Z,{className:"text-3xl font-bold text-gray-900 mb-3",children:"Connect to your MCP client"}),(0,c.jsx)(k.Z,{className:"text-lg text-gray-600",children:"Use tools directly from any MCP client with LiteLLM MCP. Enable your AI assistant to perform real-world tasks through a simple, secure connection."})]}),(0,c.jsxs)(e1.Z,{className:"w-full",children:[(0,c.jsx)(e2.Z,{className:"flex justify-start mt-8 mb-6",children:(0,c.jsxs)("div",{className:"flex bg-gray-100 p-1 rounded-lg",children:[(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nV.Z,{size:18}),"OpenAI API"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nK.Z,{size:18}),"LiteLLM Proxy"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nY.Z,{size:18}),"Cursor"]})}),(0,c.jsx)(e0.Z,{className:"px-6 py-3 rounded-md transition-all duration-200",children:(0,c.jsxs)("span",{className:"flex items-center gap-2 font-medium",children:[(0,c.jsx)(nW.Z,{size:18}),"Streamable HTTP"]})})]})}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 p-6 rounded-lg border border-blue-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nV.Z,{className:"text-blue-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-blue-900",children:"OpenAI Responses API Integration"})]}),(0,c.jsx)(nQ,{className:"text-blue-700",children:"Connect OpenAI Responses API to your LiteLLM MCP server for seamless tool integration"})]}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(n0,{icon:(0,c.jsx)(nG.Z,{className:"text-blue-600",size:16}),title:"API Key Setup",description:"Configure your OpenAI API key for authentication",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsxs)(nQ,{children:["Get your API key from the"," ",(0,c.jsxs)("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-700 inline-flex items-center gap-1",children:["OpenAI platform ",(0,c.jsx)(nJ.Z,{size:12})]})]})}),(0,c.jsx)(m,{title:"Environment Variable",code:'export OPENAI_API_KEY="sk-..."',copyKey:"openai-env"})]})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nH.Z,{className:"text-blue-600",size:16}),title:"MCP Server Information",description:"Connection details for your LiteLLM MCP server",children:(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"openai-server-url"})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-blue-600",size:16}),title:"Implementation Example",description:"Complete cURL example for using the Responses API",serverName:"Zapier Gmail",accessGroups:["dev"],children:(0,c.jsx)(m,{code:'curl --location \'https://api.openai.com/v1/responses\' \\\n--header \'Content-Type: application/json\' \\\n--header "Authorization: Bearer $OPENAI_API_KEY" \\\n--data \'{\n "model": "gpt-4.1",\n "tools": [\n {\n "type": "mcp",\n "server_label": "litellm",\n "server_url": "'.concat(t,'/mcp",\n "require_approval": "never",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n ],\n "input": "Run available tools",\n "tool_choice": "required"\n}\''),copyKey:"openai-curl",className:"text-xs"})})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-emerald-50 to-green-50 p-6 rounded-lg border border-emerald-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nK.Z,{className:"text-emerald-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-emerald-900",children:"LiteLLM Proxy API Integration"})]}),(0,c.jsx)(nQ,{className:"text-emerald-700",children:"Connect to LiteLLM Proxy Responses API for seamless tool integration with multiple model providers"})]}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(n0,{icon:(0,c.jsx)(nG.Z,{className:"text-emerald-600",size:16}),title:"API Key Setup",description:"Configure your LiteLLM Proxy API key for authentication",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsx)(nQ,{children:"Get your API key from your LiteLLM Proxy dashboard or contact your administrator"})}),(0,c.jsx)(m,{title:"Environment Variable",code:'export LITELLM_API_KEY="sk-..."',copyKey:"litellm-env"})]})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nH.Z,{className:"text-emerald-600",size:16}),title:"MCP Server Information",description:"Connection details for your LiteLLM MCP server",children:(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"litellm-server-url"})}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-emerald-600",size:16}),title:"Implementation Example",description:"Complete cURL example for using the LiteLLM Proxy Responses API",serverName:n,accessGroups:["dev"],children:(0,c.jsx)(m,{code:"curl --location '".concat(t,'/v1/responses\' \\\n--header \'Content-Type: application/json\' \\\n--header "Authorization: Bearer $LITELLM_API_KEY" \\\n--data \'{\n "model": "gpt-4",\n "tools": [\n {\n "type": "mcp",\n "server_label": "litellm",\n "server_url": "').concat(t,'/mcp",\n "require_approval": "never",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n ],\n "input": "Run available tools",\n "tool_choice": "required"\n}\''),copyKey:"litellm-curl",className:"text-xs"})})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-purple-50 to-blue-50 p-6 rounded-lg border border-purple-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nY.Z,{className:"text-purple-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-purple-900",children:"Cursor IDE Integration"})]}),(0,c.jsx)(nQ,{className:"text-purple-700",children:"Use tools directly from Cursor IDE with LiteLLM MCP. Enable your AI assistant to perform real-world tasks without leaving your coding environment."})]}),(0,c.jsxs)(tN.Z,{className:"border border-gray-200",children:[(0,c.jsx)(n$,{level:5,className:"mb-4 text-gray-800",children:"Setup Instructions"}),(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsx)(u,{step:1,title:"Open Cursor Settings",children:(0,c.jsxs)(nQ,{className:"text-gray-600",children:["Use the keyboard shortcut ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"⇧+⌘+J"})," (Mac) or ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Ctrl+Shift+J"})," (Windows/Linux)"]})}),(0,c.jsx)(u,{step:2,title:"Navigate to MCP Tools",children:(0,c.jsx)(nQ,{className:"text-gray-600",children:'Go to the "MCP Tools" tab and click "New MCP Server"'})}),(0,c.jsxs)(u,{step:3,title:"Add Configuration",children:[(0,c.jsxs)(nQ,{className:"text-gray-600 mb-3",children:["Copy the JSON configuration below and paste it into Cursor, then save with ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Cmd+S"})," or ",(0,c.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded",children:"Ctrl+S"})]}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nV.Z,{className:"text-purple-600",size:16}),title:"Configuration",description:"Cursor MCP configuration",serverName:"Zapier Gmail",accessGroups:["dev"],children:(0,c.jsx)(m,{code:'{\n "mcpServers": {\n "Zapier_MCP": {\n "server_url": "'.concat(t,'/mcp",\n "headers": {\n "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY",\n "x-mcp-servers": ["Zapier_MCP,dev"]\n }\n }\n }\n}'),copyKey:"cursor-config",className:"text-xs"})})]})]})]})]}),{})}),(0,c.jsx)(e4.Z,{className:"mt-6",children:(0,c.jsx)(()=>(0,c.jsxs)(tX.Z,{direction:"vertical",size:"large",className:"w-full",children:[(0,c.jsxs)("div",{className:"bg-gradient-to-r from-green-50 to-teal-50 p-6 rounded-lg border border-green-100",children:[(0,c.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,c.jsx)(nW.Z,{className:"text-green-600",size:24}),(0,c.jsx)(n$,{level:4,className:"mb-0 text-green-900",children:"Streamable HTTP Transport"})]}),(0,c.jsx)(nQ,{className:"text-green-700",children:"Connect to LiteLLM MCP using HTTP transport. Compatible with any MCP client that supports HTTP streaming."})]}),(0,c.jsx)(n0,{icon:(0,c.jsx)(nW.Z,{className:"text-green-600",size:16}),title:"Universal MCP Connection",description:"Use this URL with any MCP client that supports HTTP transport",children:(0,c.jsxs)(tX.Z,{direction:"vertical",size:"middle",className:"w-full",children:[(0,c.jsx)("div",{children:(0,c.jsx)(nQ,{children:"Each MCP client supports different transports. Refer to your client documentation to determine the appropriate transport method."})}),(0,c.jsx)(m,{title:"Server URL",code:"".concat(t,"/mcp"),copyKey:"http-server-url"}),(0,c.jsx)(m,{title:"Headers Configuration",code:JSON.stringify({"x-litellm-api-key":"Bearer YOUR_LITELLM_API_KEY"},null,2),copyKey:"http-headers"}),(0,c.jsx)("div",{className:"mt-4",children:(0,c.jsx)(P.ZP,{type:"link",className:"p-0 h-auto text-blue-600 hover:text-blue-700",href:"https://modelcontextprotocol.io/docs/concepts/transports",icon:(0,c.jsx)(nJ.Z,{size:14}),children:"Learn more about MCP transports"})})]})})]}),{})})]})]})]})})};let{Option:n2}=I.default,n4=e=>{let{isModalOpen:s,title:t,confirmDelete:l,cancelDelete:a}=e;return s?(0,c.jsx)(L.Z,{open:s,onOk:l,okType:"danger",onCancel:a,children:(0,c.jsxs)(y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,c.jsx)(S.Z,{children:t}),(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)("p",{children:"Are you sure you want to delete this MCP Server?"})})]})}):null};var n5=e=>{let{accessToken:s,userRole:t,userID:l}=e,{data:a,isLoading:r,refetch:i,dataUpdatedAt:n}=(0,sj.a)({queryKey:["mcpServers"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,j.fetchMCPServers)(s)},enabled:!!s}),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(null),[g,f]=(0,d.useState)(!1),[v,y]=(0,d.useState)("all"),[_,N]=(0,d.useState)("all"),[Z,w]=(0,d.useState)([]),[C,A]=(0,d.useState)(!1),L="Internal User"===t,T=d.useMemo(()=>{if(!a)return[];let e=new Set,s=[];return a.forEach(t=>{t.teams&&t.teams.forEach(t=>{let l=t.team_id;e.has(l)||(e.add(l),s.push(t))})}),s},[a]),P=d.useMemo(()=>a?Array.from(new Set(a.flatMap(e=>e.mcp_access_groups).filter(e=>null!=e))):[],[a]),E=e=>{y(e),O(e,_)},M=e=>{N(e),O(v,e)},O=(e,s)=>{if(!a)return w([]);let t=a;if("personal"===e){w([]);return}"all"!==e&&(t=t.filter(s=>{var t;return null===(t=s.teams)||void 0===t?void 0:t.some(s=>s.team_id===e)})),"all"!==s&&(t=t.filter(e=>{var t;return null===(t=e.mcp_access_groups)||void 0===t?void 0:t.some(e=>"string"==typeof e?e===s:e&&e.name===s)})),w(t)};(0,d.useEffect)(()=>{O(v,_)},[n]);let D=d.useMemo(()=>nw(null!=t?t:"",e=>{p(e),f(!1)},e=>{p(e),f(!0)},F),[t]);function F(e){m(e),x(!0)}let R=async()=>{if(null!=o&&null!=s){try{await (0,j.deleteMCPServer)(s,o),eo.Z.success("Deleted MCP Server successfully"),i()}catch(e){console.error("Error deleting the mcp server:",e)}x(!1),m(null)}};return s&&t&&l?(0,c.jsxs)("div",{className:"w-full h-full p-6",children:[(0,c.jsx)(n4,{isModalOpen:u,title:"Delete MCP Server",confirmDelete:R,cancelDelete:()=>{x(!1),m(null)}}),(0,c.jsx)(nB,{userRole:t,accessToken:s,onCreateSuccess:e=>{w(s=>[...s,e]),A(!1)},isModalVisible:C,setModalVisible:A,availableAccessGroups:P}),(0,c.jsx)(S.Z,{children:"MCP Servers"}),(0,c.jsx)(k.Z,{className:"text-tremor-content mt-2",children:"Configure and manage your MCP servers"}),(0,eI.tY)(t)&&(0,c.jsx)(b.Z,{className:"mt-4 mb-4",onClick:()=>A(!0),children:"+ Add New MCP Server"}),(0,c.jsxs)(e1.Z,{className:"w-full h-full",children:[(0,c.jsx)(e2.Z,{className:"flex justify-between mt-2 w-full items-center",children:(0,c.jsxs)("div",{className:"flex",children:[(0,c.jsx)(e0.Z,{children:"All Servers"}),(0,c.jsx)(e0.Z,{children:"Connect"})]})}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:(0,c.jsx)(()=>h?(0,c.jsx)(nD,{mcpServer:Z.find(e=>e.server_id===h)||{server_id:"",server_name:"",alias:"",url:"",transport:"",auth_type:"",created_at:"",created_by:"",updated_at:"",updated_by:""},onBack:()=>{f(!1),p(null),i()},isProxyAdmin:(0,eI.tY)(t),isEditing:g,accessToken:s,userID:l,userRole:t,availableAccessGroups:P}):(0,c.jsxs)("div",{className:"w-full h-full",children:[(0,c.jsx)("div",{className:"w-full px-6",children:(0,c.jsx)("div",{className:"flex flex-col space-y-4",children:(0,c.jsx)("div",{className:"flex items-center justify-between bg-gray-50 rounded-lg p-4 border-2 border-gray-200",children:(0,c.jsxs)("div",{className:"flex items-center gap-4",children:[(0,c.jsx)(k.Z,{className:"text-lg font-semibold text-gray-900",children:"Current Team:"}),(0,c.jsxs)(I.default,{value:v,onChange:E,style:{width:300},children:[(0,c.jsx)(n2,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:L?"All Available Servers":"All Servers"})]})}),(0,c.jsx)(n2,{value:"personal",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"Personal"})]})}),T.map(e=>(0,c.jsx)(n2,{value:e.team_id,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e.team_alias||e.team_id})]})},e.team_id))]}),(0,c.jsxs)(k.Z,{className:"text-lg font-semibold text-gray-900 ml-6",children:["Access Group:",(0,c.jsx)(V.Z,{title:"An MCP Access Group is a set of users or teams that have permission to access specific MCP servers. Use access groups to control and organize who can connect to which servers.",children:(0,c.jsx)(tL.Z,{style:{marginLeft:4,color:"#888"}})})]}),(0,c.jsxs)(I.default,{value:_,onChange:M,style:{width:300},children:[(0,c.jsx)(n2,{value:"all",children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:"All Access Groups"})]})}),P.map(e=>(0,c.jsx)(n2,{value:e,children:(0,c.jsxs)("div",{className:"flex items-center gap-2",children:[(0,c.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,c.jsx)("span",{className:"font-medium",children:e})]})},e))]})]})})})}),(0,c.jsx)("div",{className:"w-full px-6 mt-6",children:(0,c.jsx)(lx,{data:Z,columns:D,renderSubComponent:()=>(0,c.jsx)("div",{}),getRowCanExpand:()=>!1,isLoading:r,noDataMessage:"No MCP servers configured"})})]}),{})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(n1,{})})]})]})]}):(console.log("Missing required authentication parameters",{accessToken:s,userRole:t,userID:l}),(0,c.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."}))},n6=t(21770);function n3(e){let{tool:s,needsAuth:t,authValue:l,onSubmit:a,isLoading:r,result:i,error:n,onClose:o}=e,[m]=A.Z.useForm(),[u,x]=d.useState("formatted"),[h,p]=d.useState(null),[g,j]=d.useState(null),f=d.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),v=d.useMemo(()=>f.properties&&f.properties.params&&"object"===f.properties.params.type&&f.properties.params.properties?{type:"object",properties:f.properties.params.properties,required:f.properties.params.required||[]}:f,[f]);d.useEffect(()=>{h&&(i||n)&&j(Date.now()-h)},[i,n,h]);let y=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0;{let s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.focus(),s.select();let t=document.execCommand("copy");if(document.body.removeChild(s),!t)throw Error("execCommand failed");return!0}}catch(e){return console.error("Copy failed:",e),!1}},N=async()=>{await y(JSON.stringify(i,null,2))?eo.Z.success("Result copied to clipboard"):eo.Z.fromBackend("Failed to copy result")},Z=async()=>{await y(s.name)?eo.Z.success("Tool name copied to clipboard"):eo.Z.fromBackend("Failed to copy tool name")};return(0,c.jsxs)("div",{className:"space-y-4 h-full",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between pb-3 border-b border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-3",children:[s.mcp_info.logo_url&&(0,c.jsx)("img",{src:s.mcp_info.logo_url,alt:"".concat(s.mcp_info.server_name," logo"),className:"w-6 h-6 object-contain"}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-1",children:[(0,c.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Test Tool:"}),(0,c.jsxs)("div",{className:"group inline-flex items-center space-x-1 bg-slate-50 hover:bg-slate-100 px-3 py-1 rounded-md cursor-pointer transition-colors border border-slate-200",onClick:Z,title:"Click to copy tool name",children:[(0,c.jsx)("span",{className:"font-mono text-slate-700 font-medium text-sm",children:s.name}),(0,c.jsx)("svg",{className:"w-3 h-3 text-slate-400 group-hover:text-slate-600 transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]})]}),(0,c.jsx)("p",{className:"text-xs text-gray-600",children:s.description}),(0,c.jsxs)("p",{className:"text-xs text-gray-500",children:["Provider: ",s.mcp_info.server_name]})]})]}),(0,c.jsx)(b.Z,{onClick:o,variant:"light",size:"sm",className:"text-gray-500 hover:text-gray-700",children:(0,c.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,c.jsxs)("div",{className:"grid grid-cols-2 gap-4 h-full",children:[(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"border-b border-gray-100 px-4 py-2",children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Input Parameters"}),(0,c.jsx)(V.Z,{title:"Configure the input parameters for this tool call",children:(0,c.jsx)(B.Z,{className:"text-gray-400 hover:text-gray-600"})})]})}),(0,c.jsx)("div",{className:"p-4",children:(0,c.jsxs)(A.Z,{form:m,onFinish:e=>{p(Date.now()),j(null);let s={};Object.entries(e).forEach(e=>{var t;let[l,a]=e,r=null===(t=v.properties)||void 0===t?void 0:t[l];if(r&&null!=a&&""!==a)switch(r.type){case"boolean":s[l]="true"===a||!0===a;break;case"number":s[l]=Number(a);break;case"string":s[l]=String(a);break;default:s[l]=a}else null!=a&&""!==a&&(s[l]=a)}),a(f.properties&&f.properties.params&&"object"===f.properties.params.type&&f.properties.params.properties?{params:s}:s)},layout:"vertical",className:"space-y-3",children:["string"==typeof s.inputSchema?(0,c.jsx)("div",{className:"space-y-3",children:(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700",children:["Input ",(0,c.jsx)("span",{className:"text-red-500",children:"*"})]}),name:"input",rules:[{required:!0,message:"Please enter input for this tool"}],className:"mb-3",children:(0,c.jsx)(_.Z,{placeholder:"Enter input for this tool",className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"})})}):void 0===v.properties?(0,c.jsx)("div",{className:"text-center py-6 bg-gray-50 rounded-lg border border-gray-200",children:(0,c.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,c.jsx)("h4",{className:"text-sm font-medium text-gray-900 mb-1",children:"No Parameters Required"}),(0,c.jsx)("p",{className:"text-xs text-gray-500",children:"This tool can be called without any input parameters."})]})}):(0,c.jsx)("div",{className:"space-y-3",children:Object.entries(v.properties).map(e=>{var s,t,l,a,r;let[i,n]=e;return(0,c.jsxs)(A.Z.Item,{label:(0,c.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center",children:[i," ",(null===(s=v.required)||void 0===s?void 0:s.includes(i))&&(0,c.jsx)("span",{className:"text-red-500",children:"*"}),n.description&&(0,c.jsx)(V.Z,{title:n.description,children:(0,c.jsx)(B.Z,{className:"ml-2 text-gray-400 hover:text-gray-600"})})]}),name:i,rules:[{required:null===(t=v.required)||void 0===t?void 0:t.includes(i),message:"Please enter ".concat(i)}],className:"mb-3",children:["string"===n.type&&n.enum&&(0,c.jsxs)("select",{className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors",defaultValue:n.default,children:[!(null===(l=v.required)||void 0===l?void 0:l.includes(i))&&(0,c.jsxs)("option",{value:"",children:["Select ",i]}),n.enum.map(e=>(0,c.jsx)("option",{value:e,children:e},e))]}),"string"===n.type&&!n.enum&&(0,c.jsx)(_.Z,{placeholder:n.description||"Enter ".concat(i),className:"rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"}),"number"===n.type&&(0,c.jsx)("input",{type:"number",placeholder:n.description||"Enter ".concat(i),className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors"}),"boolean"===n.type&&(0,c.jsxs)("select",{className:"w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors",defaultValue:(null===(a=n.default)||void 0===a?void 0:a.toString())||"",children:[!(null===(r=v.required)||void 0===r?void 0:r.includes(i))&&(0,c.jsxs)("option",{value:"",children:["Select ",i]}),(0,c.jsx)("option",{value:"true",children:"True"}),(0,c.jsx)("option",{value:"false",children:"False"})]})]},i)})}),(0,c.jsx)("div",{className:"pt-3 border-t border-gray-100",children:(0,c.jsx)(b.Z,{onClick:()=>m.submit(),disabled:r,variant:"primary",className:"w-full",loading:r,children:r?"Calling Tool...":i||n?"Call Again":"Call Tool"})})]})})]}),(0,c.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"border-b border-gray-100 px-4 py-2",children:(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Tool Result"})}),(0,c.jsx)("div",{className:"p-4",children:i||n||r?(0,c.jsxs)("div",{className:"space-y-3",children:[i&&!r&&!n&&(0,c.jsx)("div",{className:"p-2 bg-green-50 border border-green-200 rounded-lg",children:(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("svg",{className:"h-4 w-4 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,c.jsx)("h4",{className:"text-xs font-medium text-green-900",children:"Tool executed successfully"}),null!==g&&(0,c.jsxs)("span",{className:"text-xs text-green-600 ml-1",children:["• ",(g/1e3).toFixed(2),"s"]})]}),(0,c.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,c.jsxs)("div",{className:"flex bg-white rounded border border-green-300 p-0.5",children:[(0,c.jsx)("button",{onClick:()=>x("formatted"),className:"px-2 py-1 text-xs font-medium rounded transition-colors ".concat("formatted"===u?"bg-green-100 text-green-800":"text-green-600 hover:text-green-800"),children:"Formatted"}),(0,c.jsx)("button",{onClick:()=>x("json"),className:"px-2 py-1 text-xs font-medium rounded transition-colors ".concat("json"===u?"bg-green-100 text-green-800":"text-green-600 hover:text-green-800"),children:"JSON"})]}),(0,c.jsx)("button",{onClick:N,className:"p-1 hover:bg-green-100 rounded text-green-700",title:"Copy response",children:(0,c.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,c.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,c.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]})}),(0,c.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[r&&(0,c.jsxs)("div",{className:"flex flex-col justify-center items-center h-48 text-gray-500",children:[(0,c.jsxs)("div",{className:"relative",children:[(0,c.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-gray-200"}),(0,c.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-blue-600 border-t-transparent absolute top-0"})]}),(0,c.jsx)("p",{className:"text-sm font-medium mt-3",children:"Calling tool..."}),(0,c.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Please wait while we process your request"})]}),n&&(0,c.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,c.jsxs)("div",{className:"flex items-start space-x-2",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("svg",{className:"h-4 w-4 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsxs)("div",{className:"flex items-center space-x-2 mb-1",children:[(0,c.jsx)("h4",{className:"text-xs font-medium text-red-900",children:"Tool Call Failed"}),null!==g&&(0,c.jsxs)("span",{className:"text-xs text-red-600",children:["• ",(g/1e3).toFixed(2),"s"]})]}),(0,c.jsx)("div",{className:"bg-white border border-red-200 rounded p-2 max-h-48 overflow-y-auto",children:(0,c.jsx)("pre",{className:"text-xs whitespace-pre-wrap text-red-700 font-mono",children:n.message})})]})]})}),i&&!r&&!n&&(0,c.jsx)("div",{className:"space-y-3",children:"formatted"===u?i.map((e,s)=>(0,c.jsxs)("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:["text"===e.type&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Text Response"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsx)("div",{className:"bg-white rounded border border-gray-200 max-h-64 overflow-y-auto",children:(0,c.jsx)("div",{className:"p-3 space-y-2",children:e.text.split("\n\n").map((e,s)=>{if(""===e.trim())return null;if(e.startsWith("##")){let t=e.replace(/^#+\s/,"");return(0,c.jsx)("div",{className:"border-b border-gray-200 pb-1 mb-2",children:(0,c.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:t})},s)}let t=/(https?:\/\/[^\s\)]+)/g;if(t.test(e)){let l=e.split(t);return(0,c.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded p-2",children:(0,c.jsx)("div",{className:"text-xs text-gray-700 leading-relaxed whitespace-pre-wrap",children:l.map((e,s)=>t.test(e)?(0,c.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline break-all",children:e},s):e)})},s)}return e.includes("Score:")?(0,c.jsx)("div",{className:"bg-green-50 border-l-4 border-green-400 p-2 rounded-r",children:(0,c.jsx)("p",{className:"text-xs text-green-800 font-medium whitespace-pre-wrap",children:e})},s):(0,c.jsx)("div",{className:"bg-gray-50 rounded p-2 border border-gray-200",children:(0,c.jsx)("div",{className:"text-xs text-gray-700 leading-relaxed whitespace-pre-wrap font-mono",children:e})},s)}).filter(Boolean)})})})]}),"image"===e.type&&e.url&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Image Response"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsx)("div",{className:"bg-gray-50 rounded p-3 border border-gray-200",children:(0,c.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded shadow-sm"})})})]}),"embedded_resource"===e.type&&(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"bg-gray-50 px-3 py-1 border-b border-gray-200",children:(0,c.jsx)("span",{className:"text-xs font-medium text-gray-700 uppercase tracking-wide",children:"Embedded Resource"})}),(0,c.jsx)("div",{className:"p-3",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2 p-3 bg-blue-50 border border-blue-200 rounded",children:[(0,c.jsx)("div",{className:"flex-shrink-0",children:(0,c.jsx)("svg",{className:"h-5 w-5 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,c.jsxs)("div",{className:"flex-1",children:[(0,c.jsxs)("p",{className:"text-xs font-medium text-blue-900",children:["Resource Type: ",e.resource_type]}),e.url&&(0,c.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-xs text-blue-600 hover:text-blue-800 hover:underline mt-1 transition-colors",children:["View Resource",(0,c.jsxs)("svg",{className:"ml-1 h-3 w-3",fill:"currentColor",viewBox:"0 0 20 20",children:[(0,c.jsx)("path",{d:"M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"}),(0,c.jsx)("path",{d:"M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"})]})]})]})]})})]})]},s)):(0,c.jsx)("div",{className:"bg-white rounded border border-gray-200",children:(0,c.jsx)("div",{className:"p-3 overflow-auto max-h-80 bg-gray-50",children:(0,c.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all text-gray-800",children:JSON.stringify(i,null,2)})})})})]})]}):(0,c.jsx)("div",{className:"flex flex-col justify-center items-center h-48 text-gray-500",children:(0,c.jsxs)("div",{className:"text-center max-w-sm",children:[(0,c.jsx)("div",{className:"mb-3",children:(0,c.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-300",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),(0,c.jsx)("h4",{className:"text-sm font-medium text-gray-900 mb-1",children:"Ready to Call Tool"}),(0,c.jsx)("p",{className:"text-xs text-gray-500 leading-relaxed",children:'Configure the input parameters and click "Call Tool" to see the results here.'})]})})})]})]})]})}var n8=t(29488),n7=t(36724);let n9=e=>{let s,{visible:t,onOk:l,onCancel:a,authType:r}=e,[i]=A.Z.useForm();if(r===nC.API_KEY||r===nC.BEARER_TOKEN){let e=r===nC.API_KEY?"API Key":"Bearer Token";s=(0,c.jsx)(A.Z.Item,{name:"authValue",label:e,rules:[{required:!0,message:"Please input your ".concat(e)}],children:(0,c.jsx)(E.default.Password,{})})}else r===nC.BASIC&&(s=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(A.Z.Item,{name:"username",label:"Username",rules:[{required:!0,message:"Please input your username"}],children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{name:"password",label:"Password",rules:[{required:!0,message:"Please input your password"}],children:(0,c.jsx)(E.default.Password,{})})]}));return(0,c.jsx)(L.Z,{open:t,title:"Authentication",onOk:()=>{i.validateFields().then(e=>{r===nC.BASIC?l("".concat(e.username.trim(),":").concat(e.password.trim())):l(e.authValue.trim())})},onCancel:a,destroyOnClose:!0,children:(0,c.jsx)(A.Z,{form:i,layout:"vertical",children:s})})},oe=e=>{let{authType:s,onAuthSubmit:t,onClearAuth:l,hasAuth:a}=e,[r,i]=(0,d.useState)(!1);return(0,c.jsxs)("div",{className:"space-y-3",children:[(0,c.jsxs)("div",{className:"flex items-center justify-between",children:[(0,c.jsxs)(n7.xv,{className:"text-sm font-medium text-gray-700",children:["Authentication ",a?"✓":""]}),(0,c.jsxs)("div",{className:"flex gap-2",children:[a&&(0,c.jsx)(n7.zx,{onClick:()=>{l()},size:"sm",variant:"secondary",className:"text-xs text-red-600 hover:text-red-700",children:"Clear"}),(0,c.jsx)(n7.zx,{onClick:()=>i(!0),size:"sm",variant:"secondary",className:"text-xs",children:a?"Update":"Add Auth"})]})]}),(0,c.jsx)(n7.xv,{className:"text-xs text-gray-500",children:a?"Authentication configured and saved locally":"Some tools may require authentication"}),(0,c.jsx)(n9,{visible:r,onOk:e=>{t(e),i(!1)},onCancel:()=>i(!1),authType:s})]})};var os=e=>{let{serverId:s,accessToken:t,auth_type:l,userRole:a,userID:r,serverAlias:i}=e,[n,o]=(0,d.useState)(""),[m,u]=(0,d.useState)(null),[x,h]=(0,d.useState)(null),[p,g]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(nT(l)){let e=(0,n8.Ui)(s,i||void 0);e&&o(e)}},[s,i,l]);let f=e=>{o(e),e&&nT(l)&&((0,n8.Hc)(s,e,l||"none",i||void 0),eo.Z.success("Authentication token saved locally"))},v=()=>{o(""),(0,n8.e4)(s),eo.Z.info("Authentication token cleared")},{data:y,isLoading:b,error:_}=(0,sj.a)({queryKey:["mcpTools",s,n,i],queryFn:()=>{if(!t)throw Error("Access Token required");return(0,j.listMCPTools)(t,s,n,i||void 0)},enabled:!!t,staleTime:3e4}),{mutate:N,isPending:Z}=(0,n6.D)({mutationFn:async e=>{if(!t)throw Error("Access Token required");try{return await (0,j.callMCPTool)(t,e.tool.name,e.arguments,e.authValue,i||void 0)}catch(e){throw e}},onSuccess:e=>{h(e),g(null)},onError:e=>{g(e),h(null)}}),w=(null==y?void 0:y.tools)||[],k=""!==n;return(0,c.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,c.jsx)(n7.Zb,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,c.jsxs)("div",{className:"flex h-auto w-full gap-4",children:[(0,c.jsxs)("div",{className:"w-1/4 p-4 bg-gray-50 flex flex-col",children:[(0,c.jsx)(n7.Dx,{className:"text-xl font-semibold mb-6 mt-2",children:"MCP Tools"}),(0,c.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,c.jsxs)("div",{className:"flex flex-col flex-1 min-h-0",children:[(0,c.jsxs)(n7.xv,{className:"font-medium block mb-3 text-gray-700 flex items-center",children:[(0,c.jsx)(rC.Z,{className:"mr-2"})," Available Tools",w.length>0&&(0,c.jsx)("span",{className:"ml-2 bg-blue-100 text-blue-800 text-xs font-medium px-2 py-0.5 rounded-full",children:w.length})]}),b&&(0,c.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 bg-white border border-gray-200 rounded-lg",children:[(0,c.jsxs)("div",{className:"relative mb-3",children:[(0,c.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-gray-200"}),(0,c.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-600 border-t-transparent absolute top-0"})]}),(0,c.jsx)("p",{className:"text-xs font-medium text-gray-700",children:"Loading tools..."})]}),(null==y?void 0:y.error)&&!b&&!w.length&&(0,c.jsx)("div",{className:"p-3 text-xs text-red-800 rounded-lg bg-red-50 border border-red-200",children:(0,c.jsxs)("p",{className:"font-medium",children:["Error: ",y.message]})}),!b&&!(null==y?void 0:y.error)&&(!w||0===w.length)&&(0,c.jsxs)("div",{className:"p-4 text-center bg-white border border-gray-200 rounded-lg",children:[(0,c.jsx)("div",{className:"mx-auto w-8 h-8 bg-gray-200 rounded-full flex items-center justify-center mb-2",children:(0,c.jsx)("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 8.172V5L8 4z"})})}),(0,c.jsx)("p",{className:"text-xs font-medium text-gray-700 mb-1",children:"No tools available"}),(0,c.jsx)("p",{className:"text-xs text-gray-500",children:"No tools found for this server"})]}),!b&&!(null==y?void 0:y.error)&&w.length>0&&(0,c.jsx)("div",{className:"space-y-2 flex-1 overflow-y-auto min-h-0 mcp-tools-scrollable",style:{maxHeight:"400px",scrollbarWidth:"auto",scrollbarColor:"#cbd5e0 #f7fafc"},children:w.map(e=>(0,c.jsxs)("div",{className:"border rounded-lg p-3 cursor-pointer transition-all hover:shadow-sm ".concat((null==m?void 0:m.name)===e.name?"border-blue-500 bg-blue-50 ring-1 ring-blue-200":"border-gray-200 bg-white hover:border-gray-300"),onClick:()=>{u(e),h(null),g(null)},children:[(0,c.jsxs)("div",{className:"flex items-start space-x-2",children:[e.mcp_info.logo_url&&(0,c.jsx)("img",{src:e.mcp_info.logo_url,alt:"".concat(e.mcp_info.server_name," logo"),className:"w-4 h-4 object-contain flex-shrink-0 mt-0.5"}),(0,c.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,c.jsx)("h4",{className:"font-mono text-xs font-medium text-gray-900 truncate",children:e.name}),(0,c.jsx)("p",{className:"text-xs text-gray-500 truncate",children:e.mcp_info.server_name}),(0,c.jsx)("p",{className:"text-xs text-gray-600 mt-1 line-clamp-2 leading-relaxed",children:e.description})]})]}),(null==m?void 0:m.name)===e.name&&(0,c.jsx)("div",{className:"mt-2 pt-2 border-t border-blue-200",children:(0,c.jsxs)("div",{className:"flex items-center text-xs font-medium text-blue-700",children:[(0,c.jsx)("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,c.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),"Selected"]})})]},e.name))})]}),nT(l)&&(0,c.jsx)("div",{className:"pt-4 border-t border-gray-200 flex-shrink-0 mt-6",children:k?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(n7.xv,{className:"font-medium block mb-3 text-gray-700 flex items-center",children:[(0,c.jsx)(rX.Z,{className:"mr-2"})," Authentication"]}),(0,c.jsx)(oe,{authType:l,onAuthSubmit:f,onClearAuth:v,hasAuth:k})]}):(0,c.jsxs)("div",{className:"p-4 bg-gradient-to-r from-orange-50 to-red-50 border border-orange-200 rounded-lg",children:[(0,c.jsxs)("div",{className:"flex items-center mb-3",children:[(0,c.jsx)(rX.Z,{className:"mr-2 text-orange-600 text-lg"}),(0,c.jsx)(n7.xv,{className:"font-semibold text-orange-800",children:"Authentication Required"})]}),(0,c.jsx)(n7.xv,{className:"text-sm text-orange-700 mb-4",children:"This MCP server requires authentication. You must add your credentials below to access the tools."}),(0,c.jsx)(oe,{authType:l,onAuthSubmit:f,onClearAuth:v,hasAuth:k})]})})]})]}),(0,c.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,c.jsx)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:(0,c.jsx)(n7.Dx,{className:"text-xl font-semibold mb-0",children:"Tool Testing Playground"})}),(0,c.jsx)("div",{className:"flex-1 overflow-auto p-4",children:m?(0,c.jsx)("div",{className:"h-full",children:(0,c.jsx)(n3,{tool:m,needsAuth:nT(l),authValue:n,onSubmit:e=>{N({tool:m,arguments:e,authValue:n})},result:x,error:p,isLoading:Z,onClose:()=>u(null)})}):(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(ez.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(n7.xv,{className:"text-lg font-medium text-gray-600 mb-2",children:"Select a Tool to Test"}),(0,c.jsx)(n7.xv,{className:"text-center text-gray-500 max-w-md",children:"Choose a tool from the left sidebar to start testing its functionality with custom inputs."})]})})]})]})})})},ot=t(57018),ol=e=>{let{tagId:s,onClose:t,accessToken:l,is_admin:a,editTag:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(r),[x,h]=(0,d.useState)([]),p=async()=>{if(l)try{let e=(await (0,j.tagInfoCall)(l,[s]))[s];e&&(o(e),r&&i.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),eo.Z.fromBackend("Error fetching tag details: "+e)}};(0,d.useEffect)(()=>{p()},[s,l]),(0,d.useEffect)(()=>{l&&eH("dummy-user","Admin",l,h)},[l]);let g=async e=>{if(l)try{await (0,j.tagUpdateCall)(l,{name:e.name,description:e.description,models:e.models}),eo.Z.success("Tag updated successfully"),u(!1),p()}catch(e){console.error("Error updating tag:",e),eo.Z.fromBackend("Error updating tag: "+e)}};return n?(0,c.jsxs)("div",{className:"p-4",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.zx,{onClick:t,className:"mb-4",children:"← Back to Tags"}),(0,c.jsxs)(ot.Dx,{children:["Tag Name: ",n.name]}),(0,c.jsx)(ot.xv,{className:"text-gray-500",children:n.description||"No description"})]}),a&&!m&&(0,c.jsx)(ot.zx,{onClick:()=>u(!0),children:"Edit Tag"})]}),m?(0,c.jsx)(ot.Zb,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:g,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed LLMs"," ",(0,c.jsx)(V.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select LLMs",children:x.map(e=>(0,c.jsx)(I.default.Option,{value:e,children:F(e)},e))})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(ot.zx,{onClick:()=>u(!1),children:"Cancel"}),(0,c.jsx)(ot.zx,{type:"submit",children:"Save Changes"})]})]})}):(0,c.jsx)("div",{className:"space-y-6",children:(0,c.jsxs)(ot.Zb,{children:[(0,c.jsx)(ot.Dx,{children:"Tag Details"}),(0,c.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Name"}),(0,c.jsx)(ot.xv,{children:n.name})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Description"}),(0,c.jsx)(ot.xv,{children:n.description||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Allowed LLMs"}),(0,c.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===n.models.length?(0,c.jsx)(ot.Ct,{color:"red",children:"All Models"}):n.models.map(e=>{var s;return(0,c.jsx)(ot.Ct,{color:"blue",children:(0,c.jsx)(V.Z,{title:"ID: ".concat(e),children:(null===(s=n.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Created"}),(0,c.jsx)(ot.xv,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(ot.xv,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(ot.xv,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,c.jsx)("div",{children:"Loading..."})},oa=e=>{let{data:s,onEdit:t,onDelete:l,onSelectTag:a}=e,[r,i]=d.useState([{id:"created_at",desc:!0}]),n=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("div",{className:"overflow-hidden",children:(0,c.jsx)(V.Z,{title:t.name,children:(0,c.jsx)(b.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",onClick:()=>a(t.name),children:t.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.description,children:(0,c.jsx)("span",{className:"text-xs",children:t.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,t;let{row:l}=e,a=l.original;return(0,c.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(t=a.models)||void 0===t?void 0:t.map(e=>{var s;return(0,c.jsx)(eX.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,c.jsx)(V.Z,{title:"ID: ".concat(e),children:(0,c.jsx)(k.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>t(a),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>l(a.name),className:"cursor-pointer"})]})}}],o=(0,s_.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No tags found"})})})})})]})})})},or=e=>{let{accessToken:s,userID:t,userRole:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(null),[u,x]=(0,d.useState)(!1),[h,p]=(0,d.useState)(!1),[g,f]=(0,d.useState)(null),[N,Z]=(0,d.useState)(""),[w]=A.Z.useForm(),[S,C]=(0,d.useState)([]),T=async()=>{if(s)try{let e=await (0,j.tagListCall)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),eo.Z.fromBackend("Error fetching tags: "+e)}},P=async e=>{if(s)try{await (0,j.tagCreateCall)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),eo.Z.success("Tag created successfully"),n(!1),w.resetFields(),T()}catch(e){console.error("Error creating tag:",e),eo.Z.fromBackend("Error creating tag: "+e)}},M=async e=>{f(e),p(!0)},O=async()=>{if(s&&g){try{await (0,j.tagDeleteCall)(s,g),eo.Z.success("Tag deleted successfully"),T()}catch(e){console.error("Error deleting tag:",e),eo.Z.fromBackend("Error deleting tag: "+e)}p(!1),f(null)}};return(0,d.useEffect)(()=>{t&&l&&s&&(async()=>{try{let e=await (0,j.modelInfoCall)(s,t,l);e&&e.data&&C(e.data)}catch(e){console.error("Error fetching models:",e),eo.Z.fromBackend("Error fetching models: "+e)}})()},[s,t,l]),(0,d.useEffect)(()=>{T()},[s]),(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,c.jsx)(ol,{tagId:o,onClose:()=>{m(null),x(!1)},accessToken:s,is_admin:"Admin"===l,editTag:u}):(0,c.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,c.jsx)("h1",{children:"Tag Management"}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[N&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",N]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{T(),Z(new Date().toLocaleString())}})]})]}),(0,c.jsxs)(k.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,c.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,c.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,c.jsx)(b.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create New Tag"}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(oa,{data:a,onEdit:e=>{m(e.name),x(!0)},onDelete:M,onSelectTag:m})})}),(0,c.jsx)(L.Z,{title:"Create New Tag",visible:i,width:800,footer:null,onCancel:()=>{n(!1),w.resetFields()},children:(0,c.jsxs)(A.Z,{form:w,onFinish:P,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Allowed Models"," ",(0,c.jsx)(V.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,c.jsx)(I.default,{mode:"multiple",placeholder:"Select LLMs",children:S.map(e=>(0,c.jsx)(I.default.Option,{value:e.model_info.id,children:(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{children:e.model_name}),(0,c.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,c.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,c.jsx)(b.Z,{type:"submit",children:"Create Tag"})})]})}),h&&(0,c.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,c.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,c.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,c.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,c.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,c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,c.jsx)("div",{className:"sm:flex sm:items-start",children:(0,c.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,c.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:O,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:()=>{p(!1),f(null)},children:"Cancel"})]})]})]})})]})})},oi=e=>{let{data:s,onView:t,onEdit:l,onDelete:a}=e,[r,i]=d.useState([{id:"created_at",desc:!0}]),n=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,c.jsx)("button",{onClick:()=>t(l.vector_store_id),className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",children:l.vector_store_id.length>15?"".concat(l.vector_store_id.slice(0,15),"..."):l.vector_store_id})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.vector_store_name,children:(0,c.jsx)("span",{className:"text-xs",children:t.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)(V.Z,{title:t.vector_store_description,children:(0,c.jsx)("span",{className:"text-xs",children:t.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,t=s.original,{displayName:l,logo:a}=(0,sU.dr)(t.custom_llm_provider);return(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[a&&(0,c.jsx)("img",{src:a,alt:l,className:"h-4 w-4"}),(0,c.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.created_at).toLocaleDateString()})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsx)("span",{className:"text-xs",children:new Date(t.updated_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,c.jsxs)("div",{className:"flex space-x-2",children:[(0,c.jsx)(sZ.Z,{icon:sV.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"}),(0,c.jsx)(sZ.Z,{icon:W.Z,size:"sm",onClick:()=>a(t.vector_store_id),className:"cursor-pointer"})]})}}],o=(0,s_.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,sN.sC)(),getSortedRowModel:(0,sN.tj)(),enableSorting:!0});return(0,c.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsxs)(sw.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,c.jsx)(sC.Z,{children:o.getHeaderGroups().map(e=>(0,c.jsx)(sA.Z,{children:e.headers.map(e=>(0,c.jsx)(sI.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,c.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,c.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,s_.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,c.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,c.jsx)(sP.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,c.jsx)(sL.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,c.jsx)(sE.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,c.jsx)(sk.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,c.jsx)(sA.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,c.jsx)(sS.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,s_.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,c.jsx)(sA.Z,{children:(0,c.jsx)(sS.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,c.jsx)("div",{className:"text-center text-gray-500",children:(0,c.jsx)("p",{children:"No vector stores found"})})})})})]})})})};(r=o||(o={})).Bedrock="Amazon Bedrock",r.PgVector="PostgreSQL pgvector (LiteLLM Connector)",r.VertexRagEngine="Vertex AI RAG Engine",r.OpenAI="OpenAI",r.Azure="Azure OpenAI";let on={Bedrock:"bedrock",PgVector:"pg_vector",VertexRagEngine:"vertex_ai",OpenAI:"openai",Azure:"azure"},oo="/ui/assets/logos/",oc={"Amazon Bedrock":"".concat(oo,"bedrock.svg"),"PostgreSQL pgvector (LiteLLM Connector)":"".concat(oo,"postgresql.svg"),"Vertex AI RAG Engine":"".concat(oo,"google.svg"),OpenAI:"".concat(oo,"openai_small.svg"),"Azure OpenAI":"".concat(oo,"microsoft_azure.svg")},od={bedrock:[],pg_vector:[{name:"api_base",label:"API Base",tooltip:"Enter the base URL of your deployed litellm-pgvector server (e.g., http://your-server:8000)",placeholder:"http://your-deployed-server:8000",required:!0,type:"text"},{name:"api_key",label:"API Key",tooltip:"Enter the API key from your deployed litellm-pgvector server",placeholder:"your-deployed-api-key",required:!0,type:"password"}],vertex_rag_engine:[],openai:[{name:"api_key",label:"API Key",tooltip:"Enter your OpenAI API key",placeholder:"sk-...",required:!0,type:"password"}],azure:[{name:"api_key",label:"API Key",tooltip:"Enter your Azure OpenAI API key",placeholder:"your-azure-api-key",required:!0,type:"password"},{name:"api_base",label:"API Base",tooltip:"Enter your Azure OpenAI endpoint (e.g., https://your-resource.openai.azure.com/)",placeholder:"https://your-resource.openai.azure.com/",required:!0,type:"text"}]},om=e=>od[e]||[];var ou=e=>{let{isVisible:s,onCancel:t,onSuccess:l,accessToken:a,credentials:r}=e,[i]=A.Z.useForm(),[n,m]=(0,d.useState)("{}"),[u,x]=(0,d.useState)("bedrock"),h=async e=>{if(a)try{let s={};try{s=n.trim()?JSON.parse(n):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t={vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name},r=om(e.custom_llm_provider).reduce((s,t)=>(s[t.name]=e[t.name],s),{});t.litellm_params=r,await (0,j.vectorStoreCreateCall)(a,t),eo.Z.success("Vector store created successfully"),i.resetFields(),m("{}"),l()}catch(e){console.error("Error creating vector store:",e),eo.Z.fromBackend("Error creating vector store: "+e)}},p=()=>{i.resetFields(),m("{}"),x("bedrock"),t()};return(0,c.jsx)(L.Z,{title:"Add New Vector Store",visible:s,width:1e3,footer:null,onCancel:p,children:(0,c.jsxs)(A.Z,{form:i,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Provider"," ",(0,c.jsx)(V.Z,{title:"Select the provider for this vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,c.jsx)(I.default,{onChange:e=>x(e),children:Object.entries(o).map(e=>{let[s,t]=e;return(0,c.jsx)(I.default.Option,{value:on[s],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:oc[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s)})})}),"pg_vector"===u&&(0,c.jsx)(ls.Z,{message:"PG Vector Setup Required",description:(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"LiteLLM provides a server to connect to PG Vector. To use this provider:"}),(0,c.jsxs)("ol",{style:{marginLeft:"16px",marginTop:"8px"},children:[(0,c.jsxs)("li",{children:["Deploy the litellm-pgvector server from: ",(0,c.jsx)("a",{href:"https://github.com/BerriAI/litellm-pgvector",target:"_blank",rel:"noopener noreferrer",children:"https://github.com/BerriAI/litellm-pgvector"})]}),(0,c.jsx)("li",{children:"Configure your PostgreSQL database with pgvector extension"}),(0,c.jsx)("li",{children:"Start the server and note the API base URL and API key"}),(0,c.jsx)("li",{children:"Enter those details in the fields below"})]})]}),type:"info",showIcon:!0,style:{marginBottom:"16px"}}),"vertex_rag_engine"===u&&(0,c.jsx)(ls.Z,{message:"Vertex AI RAG Engine Setup",description:(0,c.jsxs)("div",{children:[(0,c.jsx)("p",{children:"To use Vertex AI RAG Engine:"}),(0,c.jsxs)("ol",{style:{marginLeft:"16px",marginTop:"8px"},children:[(0,c.jsxs)("li",{children:["Set up your Vertex AI RAG Engine corpus following the guide: ",(0,c.jsx)("a",{href:"https://cloud.google.com/vertex-ai/generative-ai/docs/rag-engine/rag-overview",target:"_blank",rel:"noopener noreferrer",children:"Vertex AI RAG Engine Overview"})]}),(0,c.jsx)("li",{children:"Create a corpus in your Google Cloud project"}),(0,c.jsx)("li",{children:"Note the corpus ID from the Vertex AI console"}),(0,c.jsx)("li",{children:"Enter the corpus ID in the Vector Store ID field below"})]})]}),type:"info",showIcon:!0,style:{marginBottom:"16px"}}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Vector Store ID"," ",(0,c.jsx)(V.Z,{title:"Enter the vector store ID from your api provider",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,c.jsx)(_.Z,{placeholder:"vertex_rag_engine"===u?"6917529027641081856 (Get corpus ID from Vertex AI console)":"Enter vector store ID from your provider"})}),om(u).map(e=>(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:[e.label," ",(0,c.jsx)(V.Z,{title:e.tooltip,children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:e.name,rules:e.required?[{required:!0,message:"Please input the ".concat(e.label.toLowerCase())}]:[],children:(0,c.jsx)(_.Z,{type:e.type||"text",placeholder:e.placeholder})},e.name)),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Vector Store Name"," ",(0,c.jsx)(V.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,c.jsx)(_.Z,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"vector_store_description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Existing Credentials"," ",(0,c.jsx)(V.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON metadata for the vector store (optional)",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),children:(0,c.jsx)(E.default.TextArea,{rows:4,value:n,onChange:e=>m(e.target.value),placeholder:'{"key": "value"}'})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,c.jsx)(b.Z,{onClick:p,variant:"secondary",children:"Cancel"}),(0,c.jsx)(b.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},ox=e=>{let{isVisible:s,onCancel:t,onConfirm:l}=e;return(0,c.jsxs)(L.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:t,children:[(0,c.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,c.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,c.jsx)(b.Z,{onClick:l,color:"red",className:"ml-2",children:"Delete"}),(0,c.jsx)(b.Z,{onClick:t,variant:"primary",children:"Cancel"})]})]})},oh=t(23907);let{TextArea:op}=E.default,{Text:og,Title:oj}=en.default;var of=e=>{let{vectorStoreId:s,accessToken:t,className:l=""}=e,[a,r]=(0,d.useState)(""),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)([]),[u,x]=(0,d.useState)({}),h=async()=>{if(!a.trim()){tc.ZP.warning("Please enter a search query");return}n(!0);try{let e=await (0,j.vectorStoreSearchCall)(t,s,a),l={query:a,response:e,timestamp:Date.now()};m(e=>[l,...e]),r("")}catch(e){console.error("Error searching vector store:",e),eo.Z.fromBackend("Failed to search vector store")}finally{n(!1)}},p=e=>new Date(e).toLocaleString(),g=(e,s)=>{let t="".concat(e,"-").concat(s);x(e=>({...e,[t]:!e[t]}))};return(0,c.jsx)(tN.Z,{className:"w-full rounded-xl shadow-md",children:(0,c.jsxs)("div",{className:"flex flex-col h-[600px]",children:[(0,c.jsxs)("div",{className:"p-4 border-b border-gray-200 flex justify-between items-center",children:[(0,c.jsxs)("div",{className:"flex items-center",children:[(0,c.jsx)(rQ.Z,{className:"mr-2 text-blue-500"}),(0,c.jsx)(oj,{level:4,className:"mb-0",children:"Test Vector Store"})]}),o.length>0&&(0,c.jsx)(P.ZP,{onClick:()=>{m([]),x({}),eo.Z.success("Search history cleared")},size:"small",children:"Clear History"})]}),(0,c.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===o.length?(0,c.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,c.jsx)(rQ.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,c.jsx)(og,{children:"Test your vector store by entering a search query below"})]}):(0,c.jsx)("div",{className:"space-y-4",children:o.map((e,s)=>{var t;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("div",{className:"text-right",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3 bg-blue-50 border border-blue-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,c.jsx)("strong",{className:"text-sm",children:"Query"}),(0,c.jsx)("span",{className:"text-xs text-gray-500",children:p(e.timestamp)})]}),(0,c.jsx)("div",{className:"text-left",children:e.query})]})}),(0,c.jsx)("div",{className:"text-left",children:(0,c.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3 bg-white border border-gray-200",children:[(0,c.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,c.jsx)(rQ.Z,{className:"text-green-500"}),(0,c.jsx)("strong",{className:"text-sm",children:"Vector Store Results"}),e.response&&(0,c.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600",children:[(null===(t=e.response.data)||void 0===t?void 0:t.length)||0," results"]})]}),e.response&&e.response.data&&e.response.data.length>0?(0,c.jsx)("div",{className:"space-y-3",children:e.response.data.map((e,t)=>{let l=u["".concat(s,"-").concat(t)]||!1;return(0,c.jsxs)("div",{className:"border rounded-lg overflow-hidden bg-gray-50",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center p-3 cursor-pointer hover:bg-gray-100 transition-colors",onClick:()=>g(s,t),children:[(0,c.jsxs)("div",{className:"flex items-center",children:[l?(0,c.jsx)(tZ.Z,{className:"text-gray-500 mr-2"}):(0,c.jsx)(la.Z,{className:"text-gray-500 mr-2"}),(0,c.jsxs)("span",{className:"font-medium text-sm",children:["Result ",t+1]}),!l&&e.content&&e.content[0]&&(0,c.jsxs)("span",{className:"ml-2 text-xs text-gray-500 truncate max-w-md",children:["- ",e.content[0].text.substring(0,100),"..."]})]}),(0,c.jsxs)("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded",children:["Score: ",e.score.toFixed(4)]})]}),l&&(0,c.jsxs)("div",{className:"border-t bg-white p-3",children:[e.content&&e.content.map((e,s)=>(0,c.jsxs)("div",{className:"mb-3",children:[(0,c.jsxs)("div",{className:"text-xs text-gray-500 mb-1",children:["Content (",e.type,")"]}),(0,c.jsx)("div",{className:"text-sm bg-gray-50 p-3 rounded border text-gray-800 max-h-40 overflow-y-auto",children:e.text})]},s)),(e.file_id||e.filename||e.attributes)&&(0,c.jsxs)("div",{className:"mt-3 pt-3 border-t border-gray-200",children:[(0,c.jsx)("div",{className:"text-xs text-gray-500 mb-2 font-medium",children:"Metadata"}),(0,c.jsxs)("div",{className:"space-y-2 text-xs",children:[e.file_id&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium",children:"File ID:"})," ",e.file_id]}),e.filename&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium",children:"Filename:"})," ",e.filename]}),e.attributes&&Object.keys(e.attributes).length>0&&(0,c.jsxs)("div",{className:"bg-gray-50 p-2 rounded",children:[(0,c.jsx)("span",{className:"font-medium block mb-1",children:"Attributes:"}),(0,c.jsx)("pre",{className:"text-xs bg-white p-2 rounded border overflow-x-auto",children:JSON.stringify(e.attributes,null,2)})]})]})]})]})]},t)})}):(0,c.jsx)("div",{className:"text-gray-500 text-sm",children:"No results found"})]})}),sr(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),h())},placeholder:"Enter your search query... (Shift+Enter for new line)",disabled:i,autoSize:{minRows:1,maxRows:4},style:{resize:"none"}})}),(0,c.jsx)(P.ZP,{type:"primary",onClick:h,disabled:i||!a.trim(),icon:(0,c.jsx)(oh.Z,{}),loading:i,children:"Search"})]})})]})})},ov=e=>{let{vectorStoreId:s,onClose:t,accessToken:l,is_admin:a,editVectorStore:r}=e,[i]=A.Z.useForm(),[n,o]=(0,d.useState)(null),[m,u]=(0,d.useState)(r),[x,h]=(0,d.useState)("{}"),[p,g]=(0,d.useState)([]),[f,v]=(0,d.useState)("details"),y=async()=>{if(l)try{let e=await (0,j.vectorStoreInfoCall)(l,s);if(e&&e.vector_store){if(o(e.vector_store),e.vector_store.vector_store_metadata){let s="string"==typeof e.vector_store.vector_store_metadata?JSON.parse(e.vector_store.vector_store_metadata):e.vector_store.vector_store_metadata;h(JSON.stringify(s,null,2))}r&&i.setFieldsValue({vector_store_id:e.vector_store.vector_store_id,custom_llm_provider:e.vector_store.custom_llm_provider,vector_store_name:e.vector_store.vector_store_name,vector_store_description:e.vector_store.vector_store_description})}}catch(e){console.error("Error fetching vector store details:",e),eo.Z.fromBackend("Error fetching vector store details: "+e)}},_=async()=>{if(l)try{let e=await (0,j.credentialListCall)(l);console.log("List credentials response:",e),g(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e)}};(0,d.useEffect)(()=>{y(),_()},[s,l]);let N=async e=>{if(l)try{let s={};try{s=x?JSON.parse(x):{}}catch(e){eo.Z.fromBackend("Invalid JSON in metadata field");return}let t={vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s};await (0,j.vectorStoreUpdateCall)(l,t),eo.Z.success("Vector store updated successfully"),u(!1),y()}catch(e){console.error("Error updating vector store:",e),eo.Z.fromBackend("Error updating vector store: "+e)}};return n?(0,c.jsxs)("div",{className:"p-4 max-w-full",children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(b.Z,{icon:e6.Z,variant:"light",className:"mb-4",onClick:t,children:"Back to Vector Stores"}),(0,c.jsxs)(S.Z,{children:["Vector Store ID: ",n.vector_store_id]}),(0,c.jsx)(k.Z,{className:"text-gray-500",children:n.vector_store_description||"No description"})]}),a&&!m&&(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Vector Store"})]}),(0,c.jsxs)(e1.Z,{children:[(0,c.jsxs)(e2.Z,{className:"mb-6",children:[(0,c.jsx)(e0.Z,{children:"Details"}),(0,c.jsx)(e0.Z,{children:"Test Vector Store"})]}),(0,c.jsxs)(e5.Z,{children:[(0,c.jsx)(e4.Z,{children:m?(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,c.jsx)(S.Z,{children:"Edit Vector Store"})}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)(A.Z,{form:i,onFinish:N,layout:"vertical",initialValues:n,children:[(0,c.jsx)(A.Z.Item,{label:"Vector Store ID",name:"vector_store_id",rules:[{required:!0,message:"Please input a vector store ID"}],children:(0,c.jsx)(E.default,{disabled:!0})}),(0,c.jsx)(A.Z.Item,{label:"Vector Store Name",name:"vector_store_name",children:(0,c.jsx)(E.default,{})}),(0,c.jsx)(A.Z.Item,{label:"Description",name:"vector_store_description",children:(0,c.jsx)(E.default.TextArea,{rows:4})}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Provider"," ",(0,c.jsx)(V.Z,{title:"Select the provider for this vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,c.jsx)(I.default,{children:Object.entries(sU.Cl).map(e=>{let[s,t]=e;return"Bedrock"===s?(0,c.jsx)(I.default.Option,{value:sU.fK[s],children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("img",{src:sU.cd[t],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,l=s.parentElement;if(l){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=t.charAt(0),l.replaceChild(e,s)}}}),(0,c.jsx)("span",{children:t})]})},s):null})})}),(0,c.jsx)("div",{className:"mb-4",children:(0,c.jsx)(k.Z,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter provider credentials below"})}),(0,c.jsx)(A.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,c.jsx)(I.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var t;return(null!==(t=null==s?void 0:s.label)&&void 0!==t?t:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,c.jsxs)("div",{className:"flex items-center my-4",children:[(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,c.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,c.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,c.jsx)(A.Z.Item,{label:(0,c.jsxs)("span",{children:["Metadata"," ",(0,c.jsx)(V.Z,{title:"JSON metadata for the vector store",children:(0,c.jsx)(B.Z,{style:{marginLeft:"4px"}})})]}),children:(0,c.jsx)(E.default.TextArea,{rows:4,value:x,onChange:e=>h(e.target.value),placeholder:'{"key": "value"}'})}),(0,c.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,c.jsx)(P.ZP,{onClick:()=>u(!1),children:"Cancel"}),(0,c.jsx)(P.ZP,{type:"primary",htmlType:"submit",children:"Save Changes"})]})]})})]}):(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,c.jsx)(S.Z,{children:"Vector Store Details"}),a&&(0,c.jsx)(b.Z,{onClick:()=>u(!0),children:"Edit Vector Store"})]}),(0,c.jsx)(G.Z,{children:(0,c.jsxs)("div",{className:"space-y-4",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"ID"}),(0,c.jsx)(k.Z,{children:n.vector_store_id})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Name"}),(0,c.jsx)(k.Z,{children:n.vector_store_name||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Description"}),(0,c.jsx)(k.Z,{children:n.vector_store_description||"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Provider"}),(0,c.jsx)("div",{className:"flex items-center space-x-2 mt-1",children:(()=>{let e=n.custom_llm_provider||"bedrock",{displayName:s,logo:t}=(()=>{let s=Object.keys(sU.fK).find(s=>sU.fK[s].toLowerCase()===e.toLowerCase());if(!s)return{displayName:e,logo:""};let t=sU.Cl[s],l=sU.cd[t];return{displayName:t,logo:l}})();return(0,c.jsxs)(c.Fragment,{children:[t&&(0,c.jsx)("img",{src:t,alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let t=e.target,l=t.parentElement;if(l){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),l.replaceChild(e,t)}}}),(0,c.jsx)(eX.Z,{color:"blue",children:s})]})})()})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Metadata"}),(0,c.jsx)("div",{className:"bg-gray-50 p-3 rounded mt-2 font-mono text-xs overflow-auto max-h-48",children:(0,c.jsx)("pre",{children:x})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Created"}),(0,c.jsx)(k.Z,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"font-medium",children:"Last Updated"}),(0,c.jsx)(k.Z,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})})]})}),(0,c.jsx)(e4.Z,{children:(0,c.jsx)(of,{vectorStoreId:n.vector_store_id,accessToken:l||""})})]})]})]}):(0,c.jsx)("div",{children:"Loading..."})},oy=e=>{let{accessToken:s,userID:t,userRole:l}=e,[a,r]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[o,m]=(0,d.useState)(!1),[u,x]=(0,d.useState)(null),[h,p]=(0,d.useState)(""),[g,f]=(0,d.useState)([]),[_,N]=(0,d.useState)(null),[Z,w]=(0,d.useState)(!1),S=async()=>{if(s)try{let e=await (0,j.vectorStoreListCall)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),eo.Z.fromBackend("Error fetching vector stores: "+e)}},C=async()=>{if(s)try{let e=await (0,j.credentialListCall)(s);console.log("List credentials response:",e),f(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),eo.Z.fromBackend("Error fetching credentials: "+e)}},I=async e=>{x(e),m(!0)},A=async()=>{if(s&&u){try{await (0,j.vectorStoreDeleteCall)(s,u),eo.Z.success("Vector store deleted successfully"),S()}catch(e){console.error("Error deleting vector store:",e),eo.Z.fromBackend("Error deleting vector store: "+e)}m(!1),x(null)}};return(0,d.useEffect)(()=>{S(),C()},[s]),_?(0,c.jsx)("div",{className:"w-full h-full",children:(0,c.jsx)(ov,{vectorStoreId:_,onClose:()=>{N(null),w(!1),S()},accessToken:s,is_admin:(0,eI.tY)(l||""),editVectorStore:Z})}):(0,c.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,c.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,c.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,c.jsx)("h1",{children:"Vector Store Management"}),(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[h&&(0,c.jsxs)(k.Z,{children:["Last Refreshed: ",h]}),(0,c.jsx)(sZ.Z,{icon:e3.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{S(),C(),p(new Date().toLocaleString())}})]})]}),(0,c.jsx)(k.Z,{className:"mb-4",children:(0,c.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings.."})}),(0,c.jsx)(b.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Add Vector Store"}),(0,c.jsx)(y.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,c.jsx)(v.Z,{numColSpan:1,children:(0,c.jsx)(oi,{data:a,onView:e=>{N(e),w(!1)},onEdit:e=>{N(e),w(!0)},onDelete:I})})}),(0,c.jsx)(ou,{isVisible:i,onCancel:()=>n(!1),onSuccess:()=>{n(!1),S()},accessToken:s,credentials:g}),(0,c.jsx)(ox,{isVisible:o,onCancel:()=>m(!1),onConfirm:A})]})})},ob=e=>{let{userID:s,userRole:t,accessToken:l}=e,{logoUrl:a,setLogoUrl:r}=(0,g.F)(),[i,n]=(0,d.useState)(""),[o,m]=(0,d.useState)(!1);(0,d.useEffect)(()=>{l&&u()},[l]);let u=async()=>{try{let s=(0,j.getProxyBaseUrl)(),t=await fetch(s?"".concat(s,"/get/ui_theme_settings"):"/get/ui_theme_settings",{method:"GET",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(t.ok){var e;let s=await t.json(),l=(null===(e=s.values)||void 0===e?void 0:e.logo_url)||"";n(l),r(l||null)}}catch(e){console.error("Error fetching theme settings:",e)}},x=async()=>{m(!0);try{let e=(0,j.getProxyBaseUrl)();if((await fetch(e?"".concat(e,"/update/ui_theme_settings"):"/update/ui_theme_settings",{method:"PATCH",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({logo_url:i||null})})).ok)eo.Z.success("Logo settings updated successfully!"),r(i||null);else throw Error("Failed to update settings")}catch(e){console.error("Error updating logo settings:",e),eo.Z.fromBackend("Failed to update logo settings")}finally{m(!1)}},h=async()=>{n(""),r(null),m(!0);try{let e=(0,j.getProxyBaseUrl)();if((await fetch(e?"".concat(e,"/update/ui_theme_settings"):"/update/ui_theme_settings",{method:"PATCH",headers:{Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({logo_url:null})})).ok)eo.Z.success("Logo reset to default!");else throw Error("Failed to reset logo")}catch(e){console.error("Error resetting logo:",e),eo.Z.fromBackend("Failed to reset logo")}finally{m(!1)}};return l?(0,c.jsxs)("div",{className:"w-full mx-auto max-w-4xl px-6 py-8",children:[(0,c.jsxs)("div",{className:"mb-8",children:[(0,c.jsx)(S.Z,{className:"text-2xl font-bold mb-2",children:"Logo Customization"}),(0,c.jsx)(k.Z,{className:"text-gray-600",children:"Customize your LiteLLM admin dashboard with a custom logo."})]}),(0,c.jsx)(G.Z,{className:"shadow-sm p-6",children:(0,c.jsxs)("div",{className:"space-y-6",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium text-gray-700 mb-2 block",children:"Custom Logo URL"}),(0,c.jsx)(_.Z,{placeholder:"https://example.com/logo.png",value:i,onValueChange:e=>{n(e),r(e||null)},className:"w-full"}),(0,c.jsx)(k.Z,{className:"text-xs text-gray-500 mt-1",children:"Enter a URL for your custom logo or leave empty to use the default LiteLLM logo"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(k.Z,{className:"text-sm font-medium text-gray-700 mb-2 block",children:"Current Logo"}),(0,c.jsx)("div",{className:"bg-gray-50 rounded-lg p-6 flex items-center justify-center min-h-[120px]",children:i?(0,c.jsx)("img",{src:i,alt:"Custom logo",className:"max-w-full max-h-24 object-contain",onError:e=>{var s;let t=e.target;t.style.display="none";let l=document.createElement("div");l.className="text-gray-500 text-sm",l.textContent="Failed to load image",null===(s=t.parentElement)||void 0===s||s.appendChild(l)}}):(0,c.jsx)(k.Z,{className:"text-gray-500 text-sm",children:"Default LiteLLM logo will be used"})})]}),(0,c.jsxs)("div",{className:"flex gap-3 pt-4",children:[(0,c.jsx)(b.Z,{onClick:x,loading:o,disabled:o,color:"indigo",children:"Save Changes"}),(0,c.jsx)(b.Z,{onClick:h,loading:o,disabled:o,variant:"secondary",color:"gray",children:"Reset to Default"})]})]})})]}):null};let o_=new x.S;function oN(){return(0,c.jsxs)("div",{className:re("h-screen","flex items-center justify-center gap-4"),children:[(0,c.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,c.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,c.jsx)(rt,{className:"size-4"}),(0,c.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function oZ(){let[e,s]=(0,d.useState)(""),[t,l]=(0,d.useState)(!1),[a,r]=(0,d.useState)(!1),[i,n]=(0,d.useState)(null),[o,x]=(0,d.useState)(null),[v,y]=(0,d.useState)([]),[b,_]=(0,d.useState)([]),[N,Z]=(0,d.useState)([]),[w,k]=(0,d.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[S,C]=(0,d.useState)(!0),I=(0,m.useSearchParams)(),[A,L]=(0,d.useState)({data:[]}),[T,P]=(0,d.useState)(null),[E,M]=(0,d.useState)(!1),[O,D]=(0,d.useState)(!0),[F,R]=(0,d.useState)(null),z=I.get("invitation_id"),[U,q]=(0,d.useState)(()=>I.get("page")||"api-keys"),[B,V]=(0,d.useState)(null),[K,G]=(0,d.useState)(!1),H=e=>{y(s=>s?[...s,e]:[e]),M(()=>!E)},J=!1===O&&null===T&&null===z;return((0,d.useEffect)(()=>{let e=function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token");(0,j.getUiConfig)().then(s=>{P(e),D(!1)})},[]),(0,d.useEffect)(()=>{J&&(window.location.href=(j.proxyBaseUrl||"")+"/sso/key/generate")},[J]),(0,d.useEffect)(()=>{if(!T)return;let e=(0,u.o)(T);if(e){if(V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let t=function(e){if(!e)return"Undefined Role";switch(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_user_viewer":case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);s(t),"Admin Viewer"==t&&q("usage")}e.user_email&&n(e.user_email),e.login_method&&C("username_password"==e.login_method),e.premium_user&&l(e.premium_user),e.auth_header_name&&(0,j.setGlobalLitellmHeaderName)(e.auth_header_name),e.user_id&&R(e.user_id)}},[T]),(0,d.useEffect)(()=>{B&&F&&e&&eH(F,e,B,Z),B&&F&&e&&f(B,F,e,null,x),B&&lU(B,_)},[B,F,e]),O||J)?(0,c.jsx)(oN,{}):(0,c.jsx)(d.Suspense,{fallback:(0,c.jsx)(oN,{}),children:(0,c.jsx)(h.aH,{client:o_,children:(0,c.jsx)(g.f,{accessToken:B,children:z?(0,c.jsx)(sR,{userID:F,userRole:e,premiumUser:t,teams:o,keys:v,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:x,setKeys:y,organizations:b,addKey:H,createClicked:E}):(0,c.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,c.jsx)(p.Z,{userID:F,userRole:e,premiumUser:t,userEmail:i,setProxySettings:k,proxySettings:w,accessToken:B,isPublicPage:!1,sidebarCollapsed:K,onToggleSidebar:()=>{G(!K)}}),(0,c.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,c.jsx)("div",{className:"mt-2",children:(0,c.jsx)(ib,{accessToken:B,setPage:e=>{let s=new URLSearchParams(I);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),q(e)},userRole:e,defaultSelectedKey:U,collapsed:K})}),"api-keys"==U?(0,c.jsx)(sR,{userID:F,userRole:e,premiumUser:t,teams:o,keys:v,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:x,setKeys:y,organizations:b,addKey:H,createClicked:E}):"models"==U?(0,c.jsx)(lf,{userID:F,userRole:e,token:T,keys:v,accessToken:B,modelData:A,setModelData:L,premiumUser:t,teams:o}):"llm-playground"==U?(0,c.jsx)(r8,{userID:F,userRole:e,token:T,accessToken:B,disabledPersonalKeyCreation:a}):"users"==U?(0,c.jsx)(lP,{userID:F,userRole:e,token:T,keys:v,teams:o,accessToken:B,setKeys:y}):"teams"==U?(0,c.jsx)(lR,{teams:o,setTeams:x,searchParams:I,accessToken:B,userID:F,userRole:e,organizations:b,premiumUser:t}):"organizations"==U?(0,c.jsx)(lq,{organizations:b,setOrganizations:_,userModels:N,accessToken:B,userRole:e,premiumUser:t}):"admin-panel"==U?(0,c.jsx)(l0,{setTeams:x,searchParams:I,accessToken:B,userID:F,showSSOBanner:S,premiumUser:t,proxySettings:w}):"api_ref"==U?(0,c.jsx)(ro,{proxySettings:w}):"settings"==U?(0,c.jsx)(ae,{userID:F,userRole:e,accessToken:B,premiumUser:t}):"budgets"==U?(0,c.jsx)(au,{accessToken:B}):"guardrails"==U?(0,c.jsx)(nx,{accessToken:B,userRole:e}):"prompts"==U?(0,c.jsx)(nf,{accessToken:B,userRole:e}):"transform-request"==U?(0,c.jsx)(nv,{accessToken:B}):"general-settings"==U?(0,c.jsx)(ao,{userID:F,userRole:e,accessToken:B,modelData:A}):"ui-theme"==U?(0,c.jsx)(ob,{userID:F,userRole:e,accessToken:B}):"model-hub-table"==U?(0,c.jsx)(aB.Z,{accessToken:B,publicPage:!1,premiumUser:t,userRole:e}):"caching"==U?(0,c.jsx)(iM,{userID:F,userRole:e,token:T,accessToken:B,premiumUser:t}):"pass-through-settings"==U?(0,c.jsx)(lp,{userID:F,userRole:e,accessToken:B,modelData:A}):"logs"==U?(0,c.jsx)(aU,{userID:F,userRole:e,token:T,accessToken:B,allTeams:null!=o?o:[],premiumUser:t}):"mcp-servers"==U?(0,c.jsx)(n5,{accessToken:B,userRole:e,userID:F}):"tag-management"==U?(0,c.jsx)(or,{accessToken:B,userRole:e,userID:F}):"vector-stores"==U?(0,c.jsx)(oy,{accessToken:B,userRole:e,userID:F}):"new_usage"==U?(0,c.jsx)(rn,{userID:F,userRole:e,accessToken:B,teams:null!=o?o:[],premiumUser:t}):(0,c.jsx)(ik,{userID:F,userRole:e,token:T,accessToken:B,keys:v,premiumUser:t})]})]})})})})}}},function(e){e.O(0,[665,990,50,521,866,220,154,162,172,971,117,744],function(){return e(e.s=36362)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/main-app-4f7318ae681a6d94.js b/litellm/proxy/_experimental/out/_next/static/chunks/main-app-bb35cb240fbb9dca.js similarity index 54% rename from litellm/proxy/_experimental/out/_next/static/chunks/main-app-4f7318ae681a6d94.js rename to litellm/proxy/_experimental/out/_next/static/chunks/main-app-bb35cb240fbb9dca.js index 04cf9b1105..959563da94 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/main-app-4f7318ae681a6d94.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/main-app-bb35cb240fbb9dca.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[744],{10264:function(e,n,t){Promise.resolve().then(t.t.bind(t,12846,23)),Promise.resolve().then(t.t.bind(t,19107,23)),Promise.resolve().then(t.t.bind(t,61060,23)),Promise.resolve().then(t.t.bind(t,4707,23)),Promise.resolve().then(t.t.bind(t,80,23)),Promise.resolve().then(t.t.bind(t,36423,23))}},function(e){var n=function(n){return e(e.s=n)};e.O(0,[971,117],function(){return n(54278),n(10264)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[744],{78483:function(e,n,t){Promise.resolve().then(t.t.bind(t,12846,23)),Promise.resolve().then(t.t.bind(t,19107,23)),Promise.resolve().then(t.t.bind(t,61060,23)),Promise.resolve().then(t.t.bind(t,4707,23)),Promise.resolve().then(t.t.bind(t,80,23)),Promise.resolve().then(t.t.bind(t,36423,23))}},function(e){var n=function(n){return e(e.s=n)};e.O(0,[971,117],function(){return n(54278),n(78483)}),_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 38989f27ab..3e9814096f 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 376baa7575..3bfe8d70ec 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[85617,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","866","static/chunks/866-9e1803a09e9ae8da.js","220","static/chunks/220-89d73a525e307735.js","154","static/chunks/154-a64e60332235c8d7.js","162","static/chunks/162-4e7640b4d68e1ae4.js","172","static/chunks/172-0f7049c565983c4d.js","931","static/chunks/app/page-bb7f38c1ba8189cf.js"],"default",1] +3:I[85617,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","866","static/chunks/866-9e1803a09e9ae8da.js","220","static/chunks/220-89d73a525e307735.js","154","static/chunks/154-b1f2a106d0e0d77b.js","162","static/chunks/162-4e7640b4d68e1ae4.js","172","static/chunks/172-0f7049c565983c4d.js","931","static/chunks/app/page-73b19c9fbf8cc64f.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["y_NiU8YZI67ST5KsTLGlv",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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:["0oPk2eYtSaTLaPyVixqA8",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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":"/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","link","5",{"rel":"icon","href":"./favicon.ico"}],["$","meta","6",{"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 e92ca24330..86538bc863 100644 --- a/litellm/proxy/_experimental/out/model_hub.txt +++ b/litellm/proxy/_experimental/out/model_hub.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[52829,["50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","154","static/chunks/154-a64e60332235c8d7.js","162","static/chunks/162-4e7640b4d68e1ae4.js","418","static/chunks/app/model_hub/page-0dbadf20167b786c.js"],"default",1] +3:I[52829,["50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","154","static/chunks/154-b1f2a106d0e0d77b.js","162","static/chunks/162-4e7640b4d68e1ae4.js","418","static/chunks/app/model_hub/page-13b00ef4a072d920.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["y_NiU8YZI67ST5KsTLGlv",[[["",{"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":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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:["0oPk2eYtSaTLaPyVixqA8",[[["",{"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":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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":"/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","link","5",{"rel":"icon","href":"./favicon.ico"}],["$","meta","6",{"name":"next-size-adjust"}]] 1:null diff --git a/litellm/proxy/_experimental/out/model_hub_table/index.html b/litellm/proxy/_experimental/out/model_hub_table.html similarity index 95% rename from litellm/proxy/_experimental/out/model_hub_table/index.html rename to litellm/proxy/_experimental/out/model_hub_table.html index b8456d3506..65e0de2a8c 100644 --- a/litellm/proxy/_experimental/out/model_hub_table/index.html +++ b/litellm/proxy/_experimental/out/model_hub_table.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/model_hub_table.txt b/litellm/proxy/_experimental/out/model_hub_table.txt index e7f80d5c08..bda9c4d9c0 100644 --- a/litellm/proxy/_experimental/out/model_hub_table.txt +++ b/litellm/proxy/_experimental/out/model_hub_table.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[22775,["50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","866","static/chunks/866-9e1803a09e9ae8da.js","154","static/chunks/154-a64e60332235c8d7.js","162","static/chunks/162-4e7640b4d68e1ae4.js","172","static/chunks/172-0f7049c565983c4d.js","25","static/chunks/app/model_hub_table/page-f469bae327299fbb.js"],"default",1] +3:I[22775,["50","static/chunks/50-d0da2dd7acce2eb9.js","521","static/chunks/521-d97d355792d44830.js","866","static/chunks/866-9e1803a09e9ae8da.js","154","static/chunks/154-b1f2a106d0e0d77b.js","162","static/chunks/162-4e7640b4d68e1ae4.js","172","static/chunks/172-0f7049c565983c4d.js","25","static/chunks/app/model_hub_table/page-304b7041a3fa39f7.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["y_NiU8YZI67ST5KsTLGlv",[[["",{"children":["model_hub_table",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub_table",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub_table","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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:["0oPk2eYtSaTLaPyVixqA8",[[["",{"children":["model_hub_table",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub_table",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub_table","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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":"/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","link","5",{"rel":"icon","href":"./favicon.ico"}],["$","meta","6",{"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..1dc5fdb1f8 --- /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 89432d3b84..711291e1c8 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-b7b79b78e27792f3.js","50","static/chunks/50-d0da2dd7acce2eb9.js","154","static/chunks/154-a64e60332235c8d7.js","461","static/chunks/app/onboarding/page-7828c2c64e97362a.js"],"default",1] +3:I[12011,["665","static/chunks/3014691f-b7b79b78e27792f3.js","50","static/chunks/50-d0da2dd7acce2eb9.js","154","static/chunks/154-b1f2a106d0e0d77b.js","461","static/chunks/app/onboarding/page-d0d85032bb87ba51.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["y_NiU8YZI67ST5KsTLGlv",[[["",{"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":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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:["0oPk2eYtSaTLaPyVixqA8",[[["",{"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":"/litellm-asset-prefix/_next/static/css/349654da14372cd9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/litellm-asset-prefix/_next/static/css/4103fa525703177b.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_1c856b","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":"/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","link","5",{"rel":"icon","href":"./favicon.ico"}],["$","meta","6",{"name":"next-size-adjust"}]] 1:null