+
${t.model} ${t.provider?`(${t.provider})`:""}
+
+
+
+
+
+ | Cost Type |
+ Per Request |
+ ${null!==t.daily_cost?"Daily | ":""}
+ ${null!==t.monthly_cost?"Monthly | ":""}
+
+
+ | Input Cost |
+ ${tv(t.input_cost_per_request)} |
+ ${null!==t.daily_cost?`${tv(t.daily_input_cost)} | `:""}
+ ${null!==t.monthly_cost?`${tv(t.monthly_input_cost)} | `:""}
+
+
+ | Output Cost |
+ ${tv(t.output_cost_per_request)} |
+ ${null!==t.daily_cost?`${tv(t.daily_output_cost)} | `:""}
+ ${null!==t.monthly_cost?`${tv(t.monthly_output_cost)} | `:""}
+
+
+ | Margin/Fee |
+ ${tv(t.margin_cost_per_request)} |
+ ${null!==t.daily_cost?`${tv(t.daily_margin_cost)} | `:""}
+ ${null!==t.monthly_cost?`${tv(t.monthly_margin_cost)} | `:""}
+
+
+ | Total |
+ ${tv(t.cost_per_request)} |
+ ${null!==t.daily_cost?`${tv(t.daily_cost)} | `:""}
+ ${null!==t.monthly_cost?`${tv(t.monthly_cost)} | `:""}
+
+
+
+ `}).join("")}
+
+
+
+
+ `;t.document.write(r),t.document.close(),t.onload=()=>{t.print()}})(e),a(!1)},children:[(0,t.jsx)(tf.FilePdfOutlined,{className:"mr-3 text-red-500"}),"Export as PDF"]}),(0,t.jsxs)("button",{className:"flex items-center w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 transition-colors",onClick:()=>{(e=>{let t=e.entries.filter(e=>null!==e.result),s=[["LLM Multi-Model Cost Estimate Report"],["Generated",new Date().toLocaleString()],[""]];for(let a of(s.push(["COMBINED TOTALS"],["Total Per Request",e.totals.cost_per_request.toString()],["Total Daily",e.totals.daily_cost?.toString()||"-"],["Total Monthly",e.totals.monthly_cost?.toString()||"-"],["Margin Per Request",e.totals.margin_per_request.toString()],["Daily Margin",e.totals.daily_margin?.toString()||"-"],["Monthly Margin",e.totals.monthly_margin?.toString()||"-"],[""]),s.push(["Model","Provider","Input Tokens","Output Tokens","Requests/Day","Requests/Month","Cost/Request","Daily Cost","Monthly Cost","Input Cost/Req","Output Cost/Req","Margin/Req"]),t)){let e=a.result;s.push([e.model,e.provider||"-",e.input_tokens.toString(),e.output_tokens.toString(),e.num_requests_per_day?.toString()||"-",e.num_requests_per_month?.toString()||"-",e.cost_per_request.toString(),e.daily_cost?.toString()||"-",e.monthly_cost?.toString()||"-",e.input_cost_per_request.toString(),e.output_cost_per_request.toString(),e.margin_cost_per_request.toString()])}let a=new Blob([s.map(e=>e.map(e=>`"${e}"`).join(",")).join("\n")],{type:"text/csv;charset=utf-8;"}),r=window.URL.createObjectURL(a),l=document.createElement("a");l.href=r,l.download=`cost_estimate_multi_model_${new Date().toISOString().split("T")[0]}.csv`,document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(r)})(e),a(!1)},children:[(0,t.jsx)(tb,{className:"mr-3 text-green-600"}),"Export as CSV"]})]})]}):null},tk=e=>null==e?"-":0===e?"$0":e<1e-4?`$${e.toExponential(2)}`:e<1?`$${e.toFixed(4)}`:`$${(0,th.formatNumberWithCommas)(e,2,!0)}`,tC=({result:e,loading:s,timePeriod:a})=>{let r="day"===a?"Daily":"Monthly",l="day"===a?e.daily_cost:e.monthly_cost,i="day"===a?e.daily_input_cost:e.monthly_input_cost,n="day"===a?e.daily_output_cost:e.monthly_output_cost,o="day"===a?e.daily_margin_cost:e.monthly_margin_cost,c="day"===a?e.num_requests_per_day:e.num_requests_per_month;return(0,t.jsxs)("div",{className:"space-y-3 bg-gray-50 p-4 rounded-lg",children:[s&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 text-sm",children:[(0,t.jsx)(ef.Spin,{indicator:(0,t.jsx)(tu.LoadingOutlined,{spin:!0}),size:"small"}),(0,t.jsx)("span",{children:"Updating..."})]}),(0,t.jsxs)("div",{className:"grid grid-cols-4 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"text-xs text-gray-500 block",children:"Total/Request"}),(0,t.jsx)(em.Text,{className:"text-base font-semibold text-blue-600",children:tk(e.cost_per_request)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"text-xs text-gray-500 block",children:"Input Cost"}),(0,t.jsx)(em.Text,{className:"text-sm",children:tk(e.input_cost_per_request)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"text-xs text-gray-500 block",children:"Output Cost"}),(0,t.jsx)(em.Text,{className:"text-sm",children:tk(e.output_cost_per_request)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"text-xs text-gray-500 block",children:"Margin Fee"}),(0,t.jsx)(em.Text,{className:`text-sm ${e.margin_cost_per_request>0?"text-amber-600":""}`,children:tk(e.margin_cost_per_request)})]})]}),null!==l&&(0,t.jsxs)("div",{className:"grid grid-cols-4 gap-4 pt-2 border-t border-gray-200",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)(em.Text,{className:"text-xs text-gray-500 block",children:[r," Total (",null==c?"-":(0,th.formatNumberWithCommas)(c,0,!0)," req)"]}),(0,t.jsx)(em.Text,{className:`text-base font-semibold ${"day"===a?"text-green-600":"text-purple-600"}`,children:tk(l)})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)(em.Text,{className:"text-xs text-gray-500 block",children:[r," Input"]}),(0,t.jsx)(em.Text,{className:"text-sm",children:tk(i)})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)(em.Text,{className:"text-xs text-gray-500 block",children:[r," Output"]}),(0,t.jsx)(em.Text,{className:"text-sm",children:tk(n)})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)(em.Text,{className:"text-xs text-gray-500 block",children:[r," Margin Fee"]}),(0,t.jsx)(em.Text,{className:`text-sm ${(o??0)>0?"text-amber-600":""}`,children:tk(o)})]})]}),(e.input_cost_per_token||e.output_cost_per_token)&&(0,t.jsxs)("div",{className:"text-xs text-gray-400 pt-2 border-t border-gray-200",children:["Token Pricing: "," ",e.input_cost_per_token&&(0,t.jsxs)("span",{children:["Input $",(0,th.formatNumberWithCommas)(1e6*e.input_cost_per_token,2),"/1M"]}),e.input_cost_per_token&&e.output_cost_per_token&&" | ",e.output_cost_per_token&&(0,t.jsxs)("span",{children:["Output $",(0,th.formatNumberWithCommas)(1e6*e.output_cost_per_token,2),"/1M"]})]})]})},tS=({multiResult:e,timePeriod:s})=>{let[a,r]=(0,i.useState)(new Set),l=e.entries.filter(e=>null!==e.result),n=e.entries.filter(e=>e.loading),o=e.entries.filter(e=>null!==e.error),c=l.length>0,d=n.length>0,u=o.length>0;if(!c&&!d&&!u)return(0,t.jsx)("div",{className:"py-6 text-center border border-dashed border-gray-300 rounded-lg bg-gray-50",children:(0,t.jsx)(em.Text,{className:"text-gray-500",children:"Select models above to see cost estimates"})});if(!c&&d&&!u)return(0,t.jsxs)("div",{className:"py-6 text-center",children:[(0,t.jsx)(ef.Spin,{indicator:(0,t.jsx)(tu.LoadingOutlined,{spin:!0})}),(0,t.jsx)(em.Text,{className:"text-gray-500 block mt-2",children:"Calculating costs..."})]});if(!c&&u)return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(td.Divider,{className:"my-4"}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(em.Text,{className:"text-base font-semibold text-gray-900",children:"Cost Estimates"}),d&&(0,t.jsx)(ef.Spin,{indicator:(0,t.jsx)(tu.LoadingOutlined,{spin:!0}),size:"small"})]}),o.map(e=>(0,t.jsxs)("div",{className:"text-sm text-red-600 bg-red-50 p-3 rounded-lg border border-red-200",children:[(0,t.jsxs)("span",{className:"font-medium",children:[e.entry.model||"Unknown model",": "]}),e.error]},e.entry.id))]});let p=e.totals.margin_per_request>0,x="day"===s?"Daily":"Monthly",h=[{title:"Model",dataIndex:"model",key:"model",render:(e,s)=>(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"font-medium text-sm",children:e}),s.provider&&(0,t.jsx)(tm.Tag,{color:"blue",className:"text-xs",children:s.provider}),s.loading&&(0,t.jsx)(ef.Spin,{indicator:(0,t.jsx)(tu.LoadingOutlined,{spin:!0}),size:"small"})]}),s.error&&(0,t.jsxs)("div",{className:"text-xs text-red-600 bg-red-50 px-2 py-1 rounded",children:["⚠️ ",s.error]}),s.hasZeroCost&&!s.error&&(0,t.jsx)("div",{className:"text-xs text-amber-600 bg-amber-50 px-2 py-1 rounded",children:"⚠️ No pricing data found for this model. Set base_model in config."})]})},{title:"Per Request",dataIndex:"cost_per_request",key:"cost_per_request",align:"right",render:(e,s)=>s.error?(0,t.jsx)("span",{className:"text-gray-400",children:"-"}):(0,t.jsx)("span",{className:"font-mono text-sm",children:tk(e)})},{title:"Margin Fee",dataIndex:"margin_cost_per_request",key:"margin_cost_per_request",align:"right",render:(e,s)=>s.error?(0,t.jsx)("span",{className:"text-gray-400",children:"-"}):(0,t.jsx)("span",{className:`font-mono text-sm ${(e??0)>0?"text-amber-600":"text-gray-400"}`,children:tk(e)})},{title:x,dataIndex:"day"===s?"daily_cost":"monthly_cost",key:"period_cost",align:"right",render:(e,s)=>s.error?(0,t.jsx)("span",{className:"text-gray-400",children:"-"}):(0,t.jsx)("span",{className:"font-mono text-sm",children:tk(e)})},{title:"",key:"expand",width:40,render:(e,s)=>s.error?null:(0,t.jsx)(m.Button,{size:"xs",variant:"light",onClick:()=>{var e;return e=s.id,void r(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},className:"text-gray-400 hover:text-gray-600",children:a.has(s.id)?(0,t.jsx)(tp.DownOutlined,{}):(0,t.jsx)(tx.RightOutlined,{})})}],g=e.entries.filter(e=>e.entry.model).map(e=>({key:e.entry.id,id:e.entry.id,model:e.result?.model||e.entry.model,provider:e.result?.provider,cost_per_request:e.result?.cost_per_request??null,margin_cost_per_request:e.result?.margin_cost_per_request??null,daily_cost:e.result?.daily_cost??null,monthly_cost:e.result?.monthly_cost??null,error:e.error,loading:e.loading,hasZeroCost:e.result&&0===e.result.cost_per_request}));return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(td.Divider,{className:"my-4"}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(em.Text,{className:"text-base font-semibold text-gray-900",children:"Cost Estimates"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[d&&(0,t.jsx)(ef.Spin,{indicator:(0,t.jsx)(tu.LoadingOutlined,{spin:!0}),size:"small"}),(0,t.jsx)(tw,{multiResult:e})]})]}),(0,t.jsxs)(eZ.Card,{size:"small",className:"bg-gradient-to-r from-slate-50 to-blue-50 border-slate-200",children:[(0,t.jsxs)(to.Row,{gutter:[16,8],children:[(0,t.jsx)(tc.Col,{xs:24,sm:12,children:(0,t.jsx)(ta,{title:(0,t.jsx)("span",{className:"text-xs",children:"Total Per Request"}),value:tk(e.totals.cost_per_request),valueStyle:{color:"#1890ff",fontSize:"18px",fontFamily:"monospace"}})}),(0,t.jsx)(tc.Col,{xs:24,sm:12,children:(0,t.jsx)(ta,{title:(0,t.jsxs)("span",{className:"text-xs",children:["Total ",x]}),value:tk("day"===s?e.totals.daily_cost:e.totals.monthly_cost),valueStyle:{color:"day"===s?"#52c41a":"#722ed1",fontSize:"18px",fontFamily:"monospace"}})})]}),p&&(0,t.jsxs)(to.Row,{gutter:[16,8],className:"mt-3 pt-3 border-t border-slate-200",children:[(0,t.jsxs)(tc.Col,{xs:24,sm:12,children:[(0,t.jsx)("div",{className:"text-xs text-gray-500",children:"Margin Fee/Request"}),(0,t.jsx)("div",{className:"text-sm font-mono text-amber-600",children:tk(e.totals.margin_per_request)})]}),(0,t.jsxs)(tc.Col,{xs:24,sm:12,children:[(0,t.jsxs)("div",{className:"text-xs text-gray-500",children:[x," Margin Fee"]}),(0,t.jsx)("div",{className:"text-sm font-mono text-amber-600",children:tk("day"===s?e.totals.daily_margin:e.totals.monthly_margin)})]})]})]}),g.length>0&&(0,t.jsx)(eJ.Table,{columns:h,dataSource:g,pagination:!1,size:"small",className:"border border-gray-200 rounded-lg",expandable:{expandedRowKeys:Array.from(a),expandedRowRender:e=>{let a=l.find(t=>t.entry.id===e.id);return a?.result?(0,t.jsx)("div",{className:"py-2",children:(0,t.jsx)(tC,{result:a.result,loading:a.loading,timePeriod:s})}):null},showExpandColumn:!1}})]})},tT=()=>({id:`entry-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,model:"",input_tokens:1e3,output_tokens:500,num_requests_per_day:void 0,num_requests_per_month:void 0}),tI=({accessToken:e,models:s})=>{let[a,l]=(0,i.useState)([tT()]),[n,o]=(0,i.useState)("month"),{debouncedFetchForEntry:c,removeEntry:d,getMultiModelResult:m}=function(e){let[t,s]=(0,i.useState)(new Map),a=(0,i.useRef)(new Map),l=(0,i.useCallback)(async t=>{if(!e||!t.model)return void s(e=>{let s=new Map(e);return s.set(t.id,{entry:t,result:null,loading:!1,error:null}),s});s(e=>{let s=new Map(e),a=s.get(t.id);return s.set(t.id,{entry:t,result:a?.result??null,loading:!0,error:null}),s});try{let a=(0,r.getProxyBaseUrl)(),l=a?`${a}/cost/estimate`:"/cost/estimate",i={model:t.model,input_tokens:t.input_tokens||0,output_tokens:t.output_tokens||0,num_requests_per_day:t.num_requests_per_day||null,num_requests_per_month:t.num_requests_per_month||null},n=await fetch(l,{method:"POST",headers:{[(0,r.getGlobalLitellmHeaderName)()]:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(n.ok){let e=await n.json();s(s=>{let a=new Map(s);return a.set(t.id,{entry:t,result:e,loading:!1,error:null}),a})}else{let e=await n.json(),a=e.detail?.error||e.detail||"Failed to estimate cost";s(e=>{let s=new Map(e);return s.set(t.id,{entry:t,result:null,loading:!1,error:a}),s})}}catch(e){console.error("Error estimating cost:",e),s(e=>{let s=new Map(e);return s.set(t.id,{entry:t,result:null,loading:!1,error:"Network error"}),s})}},[e]),n=(0,i.useCallback)(e=>{let t=a.current.get(e.id);t&&clearTimeout(t);let s=setTimeout(()=>{l(e)},500);a.current.set(e.id,s)},[l]),o=(0,i.useCallback)(e=>{let t=a.current.get(e);t&&(clearTimeout(t),a.current.delete(e)),s(t=>{let s=new Map(t);return s.delete(e),s})},[]);return(0,i.useEffect)(()=>{let e=a.current;return()=>{e.forEach(e=>clearTimeout(e)),e.clear()}},[]),{debouncedFetchForEntry:n,removeEntry:o,getMultiModelResult:(0,i.useCallback)(e=>{let s=e.map(e=>{let s=t.get(e.id);return{entry:e,result:s?.result??null,loading:s?.loading??!1,error:s?.error??null}}),a=0,r=null,l=null,i=0,n=null,o=null;for(let e of s)e.result&&(a+=e.result.cost_per_request,i+=e.result.margin_cost_per_request,null!==e.result.daily_cost&&(r=(r??0)+e.result.daily_cost),null!==e.result.daily_margin_cost&&(n=(n??0)+e.result.daily_margin_cost),null!==e.result.monthly_cost&&(l=(l??0)+e.result.monthly_cost),null!==e.result.monthly_margin_cost&&(o=(o??0)+e.result.monthly_margin_cost));return{entries:s,totals:{cost_per_request:a,daily_cost:r,monthly_cost:l,margin_per_request:i,daily_margin:n,monthly_margin:o}}},[t])}}(e),u=(0,i.useCallback)((e,t,s)=>{l(a=>{let r=a.map(a=>a.id===e?{...a,[t]:s}:a),l=r.find(t=>t.id===e);return l&&l.model&&c(l),r})},[c]),p=(0,i.useCallback)(e=>{o(e),l(t=>t.map(t=>({...t,num_requests_per_day:"day"===e?t.num_requests_per_day:void 0,num_requests_per_month:"month"===e?t.num_requests_per_month:void 0})))},[]),x=(0,i.useCallback)(()=>{l(e=>[...e,tT()])},[]),g=(0,i.useCallback)(e=>{l(t=>t.filter(t=>t.id!==e)),d(e)},[d]),f=m(a),y=[{title:"Model",dataIndex:"model",key:"model",width:"35%",render:(e,a)=>(0,t.jsx)(h.Select,{showSearch:!0,placeholder:"Select a model",value:a.model||void 0,onChange:e=>u(a.id,"model",e),optionFilterProp:"label",filterOption:(e,t)=>String(t?.label??"").toLowerCase().includes(e.toLowerCase()),options:s.map(e=>({value:e,label:e})),style:{width:"100%"},size:"small"})},{title:"Input Tokens",dataIndex:"input_tokens",key:"input_tokens",width:"18%",render:(e,s)=>(0,t.jsx)(eY.InputNumber,{min:0,value:s.input_tokens,onChange:e=>u(s.id,"input_tokens",e??0),style:{width:"100%"},size:"small",formatter:e=>`${e}`.replace(/\B(?=(\d{3})+(?!\d))/g,",")})},{title:"Output Tokens",dataIndex:"output_tokens",key:"output_tokens",width:"18%",render:(e,s)=>(0,t.jsx)(eY.InputNumber,{min:0,value:s.output_tokens,onChange:e=>u(s.id,"output_tokens",e??0),style:{width:"100%"},size:"small",formatter:e=>`${e}`.replace(/\B(?=(\d{3})+(?!\d))/g,",")})},{title:`Requests/${"day"===n?"Day":"Month"}`,dataIndex:"day"===n?"num_requests_per_day":"num_requests_per_month",key:"num_requests",width:"20%",render:(e,s)=>(0,t.jsx)(eY.InputNumber,{min:0,value:"day"===n?s.num_requests_per_day:s.num_requests_per_month,onChange:e=>u(s.id,"day"===n?"num_requests_per_day":"num_requests_per_month",e??void 0),style:{width:"100%"},size:"small",placeholder:"-",formatter:e=>e?`${e}`.replace(/\B(?=(\d{3})+(?!\d))/g,","):""})},{title:"",key:"actions",width:50,render:(e,s)=>(0,t.jsx)(j.Button,{type:"text",icon:(0,t.jsx)(eX.DeleteOutlined,{}),onClick:()=>g(s.id),disabled:1===a.length,danger:!0,size:"small"})}];return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"flex items-center justify-end mb-2",children:(0,t.jsxs)(eW.Radio.Group,{value:n,onChange:e=>p(e.target.value),size:"small",optionType:"button",buttonStyle:"solid",children:[(0,t.jsx)(eW.Radio.Button,{value:"day",children:"Per Day"}),(0,t.jsx)(eW.Radio.Button,{value:"month",children:"Per Month"})]})}),(0,t.jsx)(eJ.Table,{columns:y,dataSource:a,rowKey:"id",pagination:!1,size:"small",footer:()=>(0,t.jsx)(j.Button,{type:"dashed",onClick:x,icon:(0,t.jsx)(_.PlusOutlined,{}),className:"w-full",children:"Add Another Model"})}),(0,t.jsx)(tS,{multiResult:f,timePeriod:n})]})};var tA=e.i(270377),tP=e.i(778917),tF=e.i(664659);let tM=({items:e,children:s="Docs",className:a=""})=>{let[r,l]=(0,i.useState)(!1),n=(0,i.useRef)(null);return(0,i.useEffect)(()=>{let e=e=>{n.current&&!n.current.contains(e.target)&&l(!1)};return r&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]),(0,t.jsxs)("div",{className:`relative inline-block ${a}`,ref:n,children:[(0,t.jsxs)("button",{type:"button",onClick:()=>l(!r),className:"inline-flex items-center gap-1 text-gray-500 hover:text-gray-700 text-xs transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 rounded px-2 py-1","aria-expanded":r,"aria-haspopup":"true",children:[(0,t.jsx)("span",{children:s}),(0,t.jsx)(tF.ChevronDown,{className:`h-3 w-3 transition-transform ${r?"rotate-180":""}`,"aria-hidden":"true"})]}),r&&(0,t.jsx)("div",{className:"absolute right-0 mt-1 w-56 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50",children:e.map((e,s)=>(0,t.jsxs)("a",{href:e.href,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-between px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 transition-colors",onClick:()=>l(!1),children:[(0,t.jsx)("span",{children:e.label}),(0,t.jsx)(tP.ExternalLink,{className:"h-3.5 w-3.5 text-gray-400 flex-shrink-0 ml-2","aria-hidden":"true"})]},s))})]})};var tD=e.i(673709);let tE=()=>{let[e,s]=(0,i.useState)(""),[a,r]=(0,i.useState)(""),l=(0,i.useMemo)(()=>{let t=parseFloat(e),s=parseFloat(a);if(isNaN(t)||isNaN(s)||0===t||0===s)return null;let r=t+s,l=s/r*100;return{originalCost:r.toFixed(10),finalCost:t.toFixed(10),discountAmount:s.toFixed(10),discountPercentage:l.toFixed(2)}},[e,a]);return(0,t.jsxs)("div",{className:"space-y-4 pt-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"font-medium text-gray-900 text-sm mb-1",children:"Cost Calculation"}),(0,t.jsxs)(em.Text,{className:"text-xs text-gray-600",children:["Discounts are applied to provider costs: ",(0,t.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded text-xs",children:"final_cost = base_cost × (1 - discount%/100)"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"font-medium text-gray-900 text-sm mb-1",children:"Example"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600",children:"A 5% discount on a $10.00 request results in: $10.00 × (1 - 0.05) = $9.50"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(em.Text,{className:"font-medium text-gray-900 text-sm mb-1",children:"Valid Range"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600",children:"Discount percentages must be between 0% and 100%"})]}),(0,t.jsxs)("div",{className:"pt-4 border-t border-gray-200",children:[(0,t.jsx)(em.Text,{className:"font-medium text-gray-900 text-sm mb-2",children:"Validating Discounts"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600 mb-3",children:"Make a test request and check the response headers to verify discounts are applied:"}),(0,t.jsx)(tD.default,{language:"bash",code:`curl -X POST -i http://your-proxy:4000/chat/completions \\
+ -H "Content-Type: application/json" \\
+ -H "Authorization: Bearer sk-1234" \\
+ -d '{
+ "model": "gemini/gemini-2.5-pro",
+ "messages": [{"role": "user", "content": "Hello"}]
+ }'`}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600 mt-3 mb-2",children:"Look for these headers in the response:"}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded text-xs font-mono text-gray-800 whitespace-nowrap",children:"x-litellm-response-cost"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600",children:"Final cost after discount"})]}),(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded text-xs font-mono text-gray-800 whitespace-nowrap",children:"x-litellm-response-cost-original"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600",children:"Original cost before discount"})]}),(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("code",{className:"bg-gray-100 px-2 py-1 rounded text-xs font-mono text-gray-800 whitespace-nowrap",children:"x-litellm-response-cost-discount-amount"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600",children:"Amount discounted"})]})]})]}),(0,t.jsxs)("div",{className:"pt-4 border-t border-gray-200",children:[(0,t.jsx)(em.Text,{className:"font-medium text-gray-900 text-sm mb-3",children:"Discount Calculator"}),(0,t.jsx)(em.Text,{className:"text-xs text-gray-600 mb-3",children:"Enter values from your response headers to verify the discount:"}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Response Cost (x-litellm-response-cost)"}),(0,t.jsx)(eD.TextInput,{placeholder:"0.0171938125",value:e,onValueChange:s,className:"text-sm"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Discount Amount (x-litellm-response-cost-discount-amount)"}),(0,t.jsx)(eD.TextInput,{placeholder:"0.0009049375",value:a,onValueChange:r,className:"text-sm"})]})]}),l&&(0,t.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:[(0,t.jsx)(em.Text,{className:"text-sm font-medium text-blue-900 mb-2",children:"Calculated Results"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(em.Text,{className:"text-xs text-blue-800",children:"Original Cost:"}),(0,t.jsxs)("code",{className:"text-xs font-mono text-blue-900",children:["$",l.originalCost]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(em.Text,{className:"text-xs text-blue-800",children:"Final Cost:"}),(0,t.jsxs)("code",{className:"text-xs font-mono text-blue-900",children:["$",l.finalCost]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(em.Text,{className:"text-xs text-blue-800",children:"Discount Amount:"}),(0,t.jsxs)("code",{className:"text-xs font-mono text-blue-900",children:["$",l.discountAmount]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-blue-300",children:[(0,t.jsx)(em.Text,{className:"text-xs font-semibold text-blue-900",children:"Discount Applied:"}),(0,t.jsxs)(em.Text,{className:"text-sm font-bold text-blue-900",children:[l.discountPercentage,"%"]})]})]})]})]})]})};var tL=e.i(689020);let tz=[{label:"Custom pricing for models",href:"https://docs.litellm.ai/docs/proxy/custom_pricing"},{label:"Spend tracking",href:"https://docs.litellm.ai/docs/proxy/cost_tracking"}],tR=({userID:e,userRole:s,accessToken:a})=>{let[l,n]=(0,i.useState)(void 0),[o,c]=(0,i.useState)(""),[d,x]=(0,i.useState)(!0),[h,g]=(0,i.useState)(!1),[f,y]=(0,i.useState)(!1),[j,_]=(0,i.useState)(void 0),[b,v]=(0,i.useState)("percentage"),[N,w]=(0,i.useState)(""),[k,C]=(0,i.useState)(""),[S,T]=(0,i.useState)([]),[I]=p.Form.useForm(),[A]=p.Form.useForm(),[P,F]=u.Modal.useModal(),M="proxy_admin"===s||"Admin"===s,{discountConfig:D,fetchDiscountConfig:E,handleAddProvider:L,handleRemoveProvider:z,handleDiscountChange:R}=function({accessToken:e}){let[t,s]=(0,i.useState)({}),a=(0,i.useCallback)(async()=>{try{let t=(0,r.getProxyBaseUrl)(),a=t?`${t}/config/cost_discount_config`:"/config/cost_discount_config",l=await fetch(a,{method:"GET",headers:{[(0,r.getGlobalLitellmHeaderName)()]:`Bearer ${e}`,"Content-Type":"application/json"}});if(l.ok){let e=await l.json();s(e.values||{})}else console.error("Failed to fetch discount config")}catch(e){console.error("Error fetching discount config:",e),ew.default.fromBackend("Failed to fetch discount configuration")}},[e]),l=(0,i.useCallback)(async t=>{try{let s=(0,r.getProxyBaseUrl)(),l=s?`${s}/config/cost_discount_config`:"/config/cost_discount_config",i=await fetch(l,{method:"PATCH",headers:{[(0,r.getGlobalLitellmHeaderName)()]:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(i.ok)ew.default.success("Discount configuration updated successfully"),await a();else{let e=await i.json(),t=e.detail?.error||e.detail||"Failed to update settings";ew.default.fromBackend(t)}}catch(e){console.error("Error updating discount config:",e),ew.default.fromBackend("Failed to update discount configuration")}},[e,a]),n=(0,i.useCallback)(async(e,a)=>{if(!e||!a)return ew.default.fromBackend("Please select a provider and enter discount percentage"),!1;let r=parseFloat(a);if(isNaN(r)||r<0||r>100)return ew.default.fromBackend("Discount must be between 0% and 100%"),!1;let i=eB(e);if(!i)return ew.default.fromBackend("Invalid provider selected"),!1;if(t[i])return ew.default.fromBackend(`Discount for ${e$.Providers[e]} already exists. Edit it in the table above.`),!1;let n={...t,[i]:r/100};return s(n),await l(n),!0},[t,l]),o=(0,i.useCallback)(async e=>{let a={...t};delete a[e],s(a),await l(a)},[t,l]),c=(0,i.useCallback)(async(e,a)=>{let r=parseFloat(a);if(!isNaN(r)&&r>=0&&r<=1){let a={...t,[e]:r};s(a),await l(a)}},[t,l]);return{discountConfig:t,setDiscountConfig:s,fetchDiscountConfig:a,saveDiscountConfig:l,handleAddProvider:n,handleRemoveProvider:o,handleDiscountChange:c}}({accessToken:a}),{marginConfig:O,fetchMarginConfig:$,handleAddMargin:q,handleRemoveMargin:B,handleMarginChange:U}=function({accessToken:e}){let[t,s]=(0,i.useState)({}),a=(0,i.useCallback)(async()=>{try{let t=(0,r.getProxyBaseUrl)(),a=t?`${t}/config/cost_margin_config`:"/config/cost_margin_config",l=await fetch(a,{method:"GET",headers:{[(0,r.getGlobalLitellmHeaderName)()]:`Bearer ${e}`,"Content-Type":"application/json"}});if(l.ok){let e=await l.json();s(e.values||{})}else console.error("Failed to fetch margin config")}catch(e){console.error("Error fetching margin config:",e),ew.default.fromBackend("Failed to fetch margin configuration")}},[e]),l=(0,i.useCallback)(async t=>{try{let s=(0,r.getProxyBaseUrl)(),l=s?`${s}/config/cost_margin_config`:"/config/cost_margin_config",i=await fetch(l,{method:"PATCH",headers:{[(0,r.getGlobalLitellmHeaderName)()]:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(i.ok)ew.default.success("Margin configuration updated successfully"),await a();else{let e=await i.json(),t=e.detail?.error||e.detail||"Failed to update settings";ew.default.fromBackend(t)}}catch(e){console.error("Error updating margin config:",e),ew.default.fromBackend("Failed to update margin configuration")}},[e,a]),n=(0,i.useCallback)(async e=>{let a,r,{selectedProvider:i,marginType:n,percentageValue:o,fixedAmountValue:c}=e;if(!i)return ew.default.fromBackend("Please select a provider"),!1;if("global"===i)a="global";else{let e=eB(i);if(!e)return ew.default.fromBackend("Invalid provider selected"),!1;a=e}if(t[a]){let e="global"===a?"Global":e$.Providers[i];return ew.default.fromBackend(`Margin for ${e} already exists. Edit it in the table above.`),!1}if("percentage"===n){let e=parseFloat(o);if(isNaN(e)||e<0||e>1e3)return ew.default.fromBackend("Percentage must be between 0% and 1000%"),!1;r=e/100}else{let e=parseFloat(c);if(isNaN(e)||e<0)return ew.default.fromBackend("Fixed amount must be non-negative"),!1;r={fixed_amount:e}}let d={...t,[a]:r};return s(d),await l(d),!0},[t,l]),o=(0,i.useCallback)(async e=>{let a={...t};delete a[e],s(a),await l(a)},[t,l]),c=(0,i.useCallback)(async(e,a)=>{let r={...t,[e]:a};s(r),await l(r)},[t,l]);return{marginConfig:t,setMarginConfig:s,fetchMarginConfig:a,saveMarginConfig:l,handleAddMargin:n,handleRemoveMargin:o,handleMarginChange:c}}({accessToken:a});(0,i.useEffect)(()=>{a&&(Promise.all([E(),$()]).finally(()=>{x(!1)}),(async()=>{try{let e=await (0,tL.fetchAvailableModels)(a);T(e.map(e=>e.model_group))}catch(e){console.error("Error fetching models:",e)}})())},[a,E,$]);let V=async()=>{await L(l,o)&&(n(void 0),c(""),g(!1))},G=async(e,s)=>{P.confirm({title:"Remove Provider Discount",icon:(0,t.jsx)(tA.ExclamationCircleOutlined,{}),content:`Are you sure you want to remove the discount for ${s}?`,okText:"Remove",okType:"danger",cancelText:"Cancel",onOk:()=>z(e)})},H=async()=>{await q({selectedProvider:j,marginType:b,percentageValue:N,fixedAmountValue:k})&&(_(void 0),w(""),C(""),v("percentage"),y(!1))},K=async(e,s)=>{P.confirm({title:"Remove Provider Margin",icon:(0,t.jsx)(tA.ExclamationCircleOutlined,{}),content:`Are you sure you want to remove the margin for ${s}?`,okText:"Remove",okType:"danger",cancelText:"Cancel",onOk:()=>B(e)})};return a?(0,t.jsxs)("div",{className:"w-full p-8",children:[F,(0,t.jsx)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between mb-6",children:(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ed.Title,{children:"Cost Tracking Settings"}),(0,t.jsx)(tM,{items:tz})]}),(0,t.jsx)(em.Text,{className:"text-gray-500 mt-1",children:"Configure cost discounts and margins for different LLM providers. Changes are saved automatically."})]})}),(0,t.jsxs)("div",{className:"bg-white rounded-lg shadow w-full max-w-full space-y-4",children:[M&&(0,t.jsxs)(eP.Accordion,{children:[(0,t.jsx)(eF.AccordionHeader,{className:"px-6 py-4",children:(0,t.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,t.jsx)(em.Text,{className:"text-lg font-semibold text-gray-900",children:"Provider Discounts"}),(0,t.jsx)(em.Text,{className:"text-sm text-gray-500 mt-1",children:"Apply percentage-based discounts to reduce costs for specific providers"})]})}),(0,t.jsx)(eM.AccordionBody,{className:"px-0",children:(0,t.jsxs)(ep.TabGroup,{children:[(0,t.jsxs)(ex.TabList,{className:"px-6 pt-4",children:[(0,t.jsx)(eu.Tab,{children:"Discounts"}),(0,t.jsx)(eu.Tab,{children:"Test It"})]}),(0,t.jsxs)(eg.TabPanels,{children:[(0,t.jsx)(eh.TabPanel,{children:(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsx)("div",{className:"flex justify-end mb-4",children:(0,t.jsx)(m.Button,{onClick:()=>g(!0),children:"+ Add Provider Discount"})}),d?(0,t.jsx)("div",{className:"py-12 text-center",children:(0,t.jsx)(em.Text,{className:"text-gray-500",children:"Loading configuration..."})}):Object.keys(D).length>0?(0,t.jsx)(eV,{discountConfig:D,onDiscountChange:R,onRemoveProvider:G}):(0,t.jsxs)("div",{className:"py-16 px-6 text-center",children:[(0,t.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-400 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,t.jsx)(em.Text,{className:"text-gray-700 font-medium mb-2",children:"No provider discounts configured"}),(0,t.jsx)(em.Text,{className:"text-gray-500 text-sm",children:'Click "Add Provider Discount" to get started'})]})]})}),(0,t.jsx)(eh.TabPanel,{children:(0,t.jsx)("div",{className:"px-6 pb-4",children:(0,t.jsx)(tE,{})})})]})]})})]}),M&&(0,t.jsxs)(eP.Accordion,{children:[(0,t.jsx)(eF.AccordionHeader,{className:"px-6 py-4",children:(0,t.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,t.jsx)(em.Text,{className:"text-lg font-semibold text-gray-900",children:"Fee/Price Margin"}),(0,t.jsx)(em.Text,{className:"text-sm text-gray-500 mt-1",children:"Add fees or margins to LLM costs for internal billing and cost recovery"})]})}),(0,t.jsx)(eM.AccordionBody,{className:"px-0",children:(0,t.jsxs)("div",{className:"p-6",children:[(0,t.jsx)("div",{className:"flex justify-end mb-4",children:(0,t.jsx)(m.Button,{onClick:()=>y(!0),children:"+ Add Provider Margin"})}),d?(0,t.jsx)("div",{className:"py-12 text-center",children:(0,t.jsx)(em.Text,{className:"text-gray-500",children:"Loading configuration..."})}):Object.keys(O).length>0?(0,t.jsx)(eK,{marginConfig:O,onMarginChange:U,onRemoveProvider:K}):(0,t.jsxs)("div",{className:"py-16 px-6 text-center",children:[(0,t.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-400 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,t.jsx)(em.Text,{className:"text-gray-700 font-medium mb-2",children:"No provider margins configured"}),(0,t.jsx)(em.Text,{className:"text-gray-500 text-sm",children:'Click "Add Provider Margin" to get started'})]})]})})]}),(0,t.jsxs)(eP.Accordion,{defaultOpen:!0,children:[(0,t.jsx)(eF.AccordionHeader,{className:"px-6 py-4",children:(0,t.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,t.jsx)(em.Text,{className:"text-lg font-semibold text-gray-900",children:"Pricing Calculator"}),(0,t.jsx)(em.Text,{className:"text-sm text-gray-500 mt-1",children:"Estimate LLM costs based on expected token usage and request volume"})]})}),(0,t.jsx)(eM.AccordionBody,{className:"px-0",children:(0,t.jsx)("div",{className:"p-6",children:(0,t.jsx)(tI,{accessToken:a,models:S})})})]})]}),(0,t.jsx)(u.Modal,{title:(0,t.jsx)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:(0,t.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Provider Discount"})}),open:h,width:1e3,onCancel:()=>{g(!1),I.resetFields(),n(void 0),c("")},footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,t.jsxs)("div",{className:"mt-6",children:[(0,t.jsx)(em.Text,{className:"text-sm text-gray-600 mb-6",children:"Select a provider and set its discount percentage. Enter a value between 0% and 100% (e.g., 5 for a 5% discount)."}),(0,t.jsx)(p.Form,{form:I,onFinish:()=>{V()},layout:"vertical",className:"space-y-6",children:(0,t.jsx)(eH,{discountConfig:D,selectedProvider:l,newDiscount:o,onProviderChange:n,onDiscountChange:c,onAddProvider:V})})]})}),(0,t.jsx)(u.Modal,{title:(0,t.jsx)("div",{className:"flex items-center space-x-3 pb-4 border-b border-gray-100",children:(0,t.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"Add Provider Margin"})}),open:f,width:1e3,onCancel:()=>{y(!1),A.resetFields(),_(void 0),w(""),C(""),v("percentage")},footer:null,className:"top-8",styles:{body:{padding:"24px"},header:{padding:"24px 24px 0 24px",border:"none"}},children:(0,t.jsxs)("div",{className:"mt-6",children:[(0,t.jsx)(em.Text,{className:"text-sm text-gray-600 mb-6",children:'Select a provider (or "Global" for all providers) and configure the margin. You can use percentage-based or fixed amount.'}),(0,t.jsx)(p.Form,{form:A,layout:"vertical",className:"space-y-6",children:(0,t.jsx)(eQ,{marginConfig:O,selectedProvider:j,marginType:b,percentageValue:N,fixedAmountValue:k,onProviderChange:_,onMarginTypeChange:v,onPercentageChange:w,onFixedAmountChange:C,onAddProvider:H})})]})})]}):null};var tO=e.i(226898),t$=e.i(487304),tq=e.i(760221);e.i(111790);var tB=e.i(280881),tU=e.i(934879),tV=e.i(402874),tG=e.i(797305),tH=e.i(109799),tK=e.i(747871),tW=e.i(56567),tQ=e.i(468133),tJ=e.i(502547),tY=e.i(278587),tX=e.i(655913),tZ=e.i(38419),t0=e.i(78334),t1=e.i(555436),t2=e.i(284614),t6=e.i(389083),t4=e.i(309426),t5=e.i(350967),t3=e.i(206929),t8=e.i(35983),t9=e.i(898586),t7=e.i(9314),se=e.i(552130),st=e.i(533882),ss=e.i(651904),sa=e.i(460285),sr=e.i(355619),sl=e.i(75921),si=e.i(390605),sn=e.i(435451),so=e.i(916940),sc=e.i(127952),sd=e.i(902555),sm=e.i(162386);let su=(e,t,s)=>"Admin"===e||!!s&&!!t&&s.some(e=>e.members?.some(e=>e.user_id===t&&"org_admin"===e.user_role)),sp=(e,t,s)=>"Admin"===e?s||[]:s&&t?s.filter(e=>e.members?.some(e=>e.user_id===t&&"org_admin"===e.user_role)):[],sx=({teams:e,searchParams:s,accessToken:a,setTeams:l,userID:n,userRole:o,organizations:c,premiumUser:d=!1})=>{let x,y,_,b;console.log(`organizations: ${JSON.stringify(c)}`);let{data:v}=(0,tH.useOrganizations)(),[N,w]=(0,i.useState)(""),[k,C]=(0,i.useState)(null),[S,T]=(0,i.useState)(null),[I,A]=(0,i.useState)(!1),[P,F]=(0,i.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,i.useEffect)(()=>{console.log(`inside useeffect - ${N}`),a&&(0,eI.fetchTeams)(a,n,o,k,l),e6()},[N]);let[M]=p.Form.useForm(),[D]=p.Form.useForm(),{Title:E,Paragraph:L}=t9.Typography,[z,R]=(0,i.useState)(""),[O,$]=(0,i.useState)(!1),[q,B]=(0,i.useState)(null),[U,V]=(0,i.useState)(null),[G,H]=(0,i.useState)(!1),[Z,ee]=(0,i.useState)(!1),[es,er]=(0,i.useState)(!1),[el,ei]=(0,i.useState)(!1),[en,ed]=(0,i.useState)([]),[ef,ey]=(0,i.useState)(!1),[ej,e_]=(0,i.useState)(null),[eb,ev]=(0,i.useState)([]),[eN,ek]=(0,i.useState)({}),[eC,eS]=(0,i.useState)(!1),[eT,eA]=(0,i.useState)([]),[eL,ez]=(0,i.useState)([]),[eR,eO]=(0,i.useState)({}),[e$,eq]=(0,i.useState)([]),[eB,eU]=(0,i.useState)([]),[eV,eH]=(0,i.useState)(!1),[eK,eW]=(0,i.useState)({}),[eQ,eJ]=(0,i.useState)(null),[eY,eX]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e;console.log(`currentOrgForCreateTeam: ${S}`);let t=(e=[],S&&S.models.length>0?(console.log(`organization.models: ${S.models}`),e=S.models):e=en,(0,sr.unfurlWildcardModelsInList)(e,en));console.log(`models: ${t}`),ev(t),M.setFieldValue("models",[])},[S,en]),(0,i.useEffect)(()=>{if(Z){let e=sp(o,n,c);if(1===e.length){let t=e[0];M.setFieldValue("organization_id",t.organization_id),T(t)}else M.setFieldValue("organization_id",k?.organization_id||null),T(k)}},[Z,o,n,c,k]),(0,i.useEffect)(()=>{let e=async()=>{try{if(null==a)return;let e=(await (0,r.getPoliciesList)(a)).policies.map(e=>e.policy_name);ez(e)}catch(e){console.error("Failed to fetch policies:",e)}};(async()=>{try{if(null==a)return;let e=(await (0,r.getGuardrailsList)(a)).guardrails.map(e=>e.guardrail_name);eA(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})(),e()},[a]);let eZ=async()=>{try{if(null==a)return;let e=await (0,r.fetchMCPAccessGroups)(a);eU(e)}catch(e){console.error("Failed to fetch MCP access groups:",e)}};(0,i.useEffect)(()=>{eZ()},[a]),(0,i.useEffect)(()=>{e&&ek(e.reduce((e,t)=>(e[t.team_id]={keys:t.keys||[],team_info:{members_with_roles:t.members_with_roles||[]}},e),{}))},[e]);let e0=async e=>{e_(e),ey(!0)},e1=async()=>{if(null!=ej&&null!=e&&null!=a)try{eS(!0),await (0,r.teamDeleteCall)(a,ej.team_id),await (0,eI.fetchTeams)(a,n,o,k,l),ew.default.success("Team deleted successfully")}catch(e){ew.default.fromBackend("Error deleting the team: "+e)}finally{eS(!1),ey(!1),e_(null)}};(0,i.useEffect)(()=>{(async()=>{try{if(null===n||null===o||null===a)return;let e=await (0,sr.fetchAvailableModelsForTeamOrKey)(n,o,a);e&&ed(e)}catch(e){console.error("Error fetching user models:",e)}})()},[a,n,o,e]);let e2=async t=>{try{if(console.log(`formValues: ${JSON.stringify(t)}`),null!=a){let s=t?.team_alias,i=e?.map(e=>e.team_alias)??[],n=t?.organization_id||k?.organization_id;if(""===n||"string"!=typeof n?t.organization_id=null:t.organization_id=n.trim(),i.includes(s))throw Error(`Team alias ${s} already exists, please pick another alias`);if(ew.default.info("Creating Team"),e$.length>0){let e={};if(t.metadata)try{e=JSON.parse(t.metadata)}catch(e){console.warn("Invalid JSON in metadata field, starting with empty object")}e={...e,logging:e$.filter(e=>e.callback_name)},t.metadata=JSON.stringify(e)}if(t.secret_manager_settings&&"string"==typeof t.secret_manager_settings)if(""===t.secret_manager_settings.trim())delete t.secret_manager_settings;else try{t.secret_manager_settings=JSON.parse(t.secret_manager_settings)}catch(e){throw Error("Failed to parse secret manager settings: "+e)}if(t.allowed_vector_store_ids&&t.allowed_vector_store_ids.length>0||t.allowed_mcp_servers_and_groups&&(t.allowed_mcp_servers_and_groups.servers?.length>0||t.allowed_mcp_servers_and_groups.accessGroups?.length>0||t.allowed_mcp_servers_and_groups.toolPermissions)){if(t.object_permission={},t.allowed_vector_store_ids&&t.allowed_vector_store_ids.length>0&&(t.object_permission.vector_stores=t.allowed_vector_store_ids,delete t.allowed_vector_store_ids),t.allowed_mcp_servers_and_groups){let{servers:e,accessGroups:s}=t.allowed_mcp_servers_and_groups;e&&e.length>0&&(t.object_permission.mcp_servers=e),s&&s.length>0&&(t.object_permission.mcp_access_groups=s),delete t.allowed_mcp_servers_and_groups}t.mcp_tool_permissions&&Object.keys(t.mcp_tool_permissions).length>0&&(t.object_permission||(t.object_permission={}),t.object_permission.mcp_tool_permissions=t.mcp_tool_permissions,delete t.mcp_tool_permissions)}if(t.allowed_mcp_access_groups&&t.allowed_mcp_access_groups.length>0&&(t.object_permission||(t.object_permission={}),t.object_permission.mcp_access_groups=t.allowed_mcp_access_groups,delete t.allowed_mcp_access_groups),t.allowed_agents_and_groups){let{agents:e,accessGroups:s}=t.allowed_agents_and_groups;t.object_permission||(t.object_permission={}),e&&e.length>0&&(t.object_permission.agents=e),s&&s.length>0&&(t.object_permission.agent_access_groups=s),delete t.allowed_agents_and_groups}Object.keys(eK).length>0&&(t.model_aliases=eK),eQ?.router_settings&&Object.values(eQ.router_settings).some(e=>null!=e&&""!==e)&&(t.router_settings=eQ.router_settings);let o=await (0,r.teamCreateCall)(a,t);null!==e?l([...e,o]):l([o]),console.log(`response for team create call: ${o}`),ew.default.success("Team created"),M.resetFields(),eq([]),eW({}),eJ(null),eX(e=>e+1),ee(!1)}}catch(e){console.error("Error creating the team:",e),ew.default.fromBackend("Error creating the team: "+e)}},e6=()=>{w(new Date().toLocaleString())},e4=(e,t)=>{let s={...P,[e]:t};F(s),a&&(0,r.v2TeamListCall)(a,s.organization_id||null,null,s.team_id||null,s.team_alias||null).then(e=>{e&&e.teams&&l(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,t.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,t.jsx)(t5.Grid,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,t.jsxs)(t4.Col,{numColSpan:1,className:"flex flex-col gap-2",children:[su(o,n,c)&&(0,t.jsx)(m.Button,{className:"w-fit",onClick:()=>ee(!0),children:"+ Create New Team"}),U?(0,t.jsx)(tW.default,{teamId:U,onUpdate:e=>{l(t=>{if(null==t)return t;let s=t.map(t=>e.team_id===t.team_id?(0,th.updateExistingKeys)(t,e):t);return a&&(0,eI.fetchTeams)(a,n,o,k,l),s})},onClose:()=>{V(null),H(!1)},accessToken:a,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let t=0;t