1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9291],{91497:function(e,t,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/usage",function(){return s(82882)}])},82882:function(e,t,s){"use strict";s.r(t),s.d(t,{__N_SSG:function(){return ed},default:function(){return ei}});var a=s(39696),r=s(90170),l=s(5270),n=s.n(l),d=s(6924),i=s(63992),o=s(35351),c=s(4220);c.kL.register(...c.zX);let u=e=>{let{data:t,labels:s,type:l="spend"}=e,n=(0,r.useRef)(null),d=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!n.current)return;d.current&&d.current.destroy();let e=n.current.getContext("2d");if(!e)return;let a={type:"bar",data:{labels:s.map(e=>new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})),datasets:[{data:t,backgroundColor:"#3b82f6",borderColor:"#7c3aed",borderWidth:0,borderRadius:{topLeft:4,topRight:4,bottomLeft:0,bottomRight:0},borderSkipped:!1}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{backgroundColor:"rgba(0, 0, 0, 0.8)",titleColor:"white",bodyColor:"white",borderColor:"rgba(255, 255, 255, 0.1)",borderWidth:1,cornerRadius:8,displayColors:!1,callbacks:{title:e=>new Date(s[e[0].dataIndex]).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}),label:e=>"spend"===l?"$".concat(e.parsed.y):"".concat(e.parsed.y," credits")}}},scales:{x:{grid:{display:!1},border:{display:!0,color:"#666",width:1},ticks:{color:"#6b7280",font:{size:12}}},y:{beginAtZero:!0,grid:{display:!1},border:{display:!0,color:"#666",width:1},ticks:{color:"#6b7280",font:{size:12},callback:function(e){return"spend"===l?"$"+e:e.toString()}}}},interaction:{intersect:!1,mode:"index"},hover:{mode:"nearest",intersect:!1},layout:{padding:{top:20,bottom:20}}}};return d.current=new c.kL(e,a),()=>{d.current&&d.current.destroy()}},[t,s]),(0,a.jsx)("div",{className:"relative w-full",style:{height:"300px"},children:(0,a.jsx)("canvas",{ref:n})})};var m=s(64842),x=s(56156);let f=e=>{let{dailyRecords:t,type:s,showToggle:r,onToggle:l}=e,n="requests"===s?t.map(e=>e.creditsConsumed):t.map(e=>e.spend),d=t.map(e=>e.date);return(0,a.jsxs)("div",{children:[r&&l&&(0,a.jsx)("div",{className:"mb-3 flex justify-end",children:(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1 dark:bg-default-700",children:[(0,a.jsx)("button",{onClick:()=>l("spend"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("spend"===s?"bg-white text-default-900 shadow-sm dark:bg-default-600 dark:text-white":"text-default-600 hover:text-default-900 dark:text-default-300 dark:hover:text-white"),children:"Total Spend"}),(0,a.jsx)("button",{onClick:()=>l("requests"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("requests"===s?"bg-white text-default-900 shadow-sm dark:bg-default-600 dark:text-white":"text-default-600 hover:text-default-900 dark:text-default-300 dark:hover:text-white"),children:"Total Credits"})]})}),(0,a.jsx)("div",{className:"h-auto",children:(0,a.jsx)(u,{data:n,labels:d,type:s||"spend"})})]})},h=e=>{let{services:t,dateRange:s}=e,[l,n]=(0,r.useState)("spend"),{t:d}=(0,x.Z)("usage"),{start:i,end:o}=(()=>{if("object"==typeof s&&s.start&&s.end){let e=new Date(s.start),t=new Date(s.end);return{start:e.toLocaleDateString("en-US",{month:"short",day:"numeric"}),end:t.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}let e=new Date,t=new Date;return t.setDate(e.getDate()-13),{start:t.toLocaleDateString("en-US",{month:"short",day:"numeric"}),end:e.toLocaleDateString("en-US",{month:"short",day:"numeric"})}})();return(0,a.jsxs)(m.w,{className:"w-full border border-transparent pb-6 dark:border-default-50",children:[(0,a.jsxs)("div",{className:"mb-6 w-full",children:[(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-1",children:[(0,a.jsx)("div",{className:"font-semibold text-default-900",children:"API Endpoints"}),(0,a.jsx)("p",{className:"text-sm text-default-500",children:d("date.apiEndpoints")})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)("button",{onClick:()=>n("spend"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("spend"===l?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Spend"}),(0,a.jsx)("button",{onClick:()=>n("requests"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("requests"===l?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Credits"})]})]}),(0,a.jsx)("div",{className:"mb-1 flex items-start justify-between",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-lg font-semibold text-default-900"}),(0,a.jsx)("p",{className:"text-default-5000 text-sm"})]})}),(0,a.jsx)("div",{className:"flex border-b border-default-200",children:(0,a.jsx)("button",{className:"border-b-2 border-blue-500 px-4 py-2 text-sm font-medium text-blue-500",children:"Usage Overview"})})]}),(0,a.jsx)("div",{className:"grid w-full grid-cols-1 gap-6 px-4 md:grid-cols-2 lg:px-6",children:t.map((e,t)=>(0,a.jsxs)("div",{className:"rounded-xl border border-default-100 p-6 shadow-sm",children:[(0,a.jsx)("div",{className:"mb-4 flex items-center justify-between",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-medium text-default-900",children:e.model}),(0,a.jsx)("div",{className:"mt-1 text-sm text-default-600",children:"spend"===l?"$".concat(e.totalSpend," total spend"):"".concat(e.totalCredits," total credits")})]})}),(0,a.jsx)("div",{className:"mb-4",children:(0,a.jsx)(f,{dailyRecords:e.dailyRecords,type:l})}),(0,a.jsxs)("div",{className:"flex justify-between text-sm text-default-500",children:[(0,a.jsx)("span",{children:i}),(0,a.jsx)("span",{children:o})]})]},t))}),0===t.length&&(0,a.jsx)("div",{className:"w-full p-12 text-center text-default-500",children:(0,a.jsx)("p",{children:d("date.noApiEndpoints")})})]})};var p=s(80096),g=s(94721),j=s(42370),b=s(4648),w=s(91411),N=s(32324),v=s(95796),y=s(97796),S=s(56257),
1C=s(18492),D=s(65213);let k=e=>e.toString(),P=e=>{let[,t,s]=e.split("-").map(Number);return new Date(2e3,t-1,s).toLocaleDateString("en-US",{month:"short",day:"numeric"})},T=e=>{let{value:t,onChange:s,maxDays:l=90,timeZone:n}=e,d=n||(0,D.iT)(),[i,o]=(0,r.useState)(!1),[c,u]=(0,r.useState)(!1),[m,f]=(0,r.useState)({start:null,end:null}),[h,T]=(0,r.useState)(!1),{t:L}=(0,x.Z)("usage");(0,r.useEffect)(()=>{let e=()=>{T(window.innerWidth<768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let E=[{value:"week",label:"Week to date",days:7},{value:"month",label:"Month to date",days:30},{value:"7d",label:"Last 7 days",days:7},{value:"14d",label:"Last 14 days",days:14},{value:"30d",label:"Last 30 days",days:30},{value:"custom",label:"Custom Range",isCustom:!0}],A=e=>{let t=(0,D.Lg)(d),s=t;switch(e){case"week":s=(0,D.zJ)(t,"en-US");break;case"month":s=(0,D.Nm)(t);break;case"7d":s=t.subtract({days:6});break;case"14d":default:s=t.subtract({days:13});break;case"30d":s=t.subtract({days:29})}return{start:k(s),end:k(t)}},R=()=>{if("object"==typeof t&&t.start&&t.end){let e=P(t.start),s=P(t.end);return"".concat(e," - ").concat(s)}let e=E.find(e=>e.value===t);return e?e.label:"Month to date"},Z=e=>{if(!e||!e.start||!e.end)return{isValid:!1,error:"Please select both start and end dates"};let t=new Date(e.start.year,e.start.month-1,e.start.day),s=new Date(e.end.year,e.end.month-1,e.end.day);return t>s?{isValid:!1,error:"Start date must be before end date"}:Math.ceil(Math.abs(s-t)/864e5)+1>l?{isValid:!1,error:"Date range cannot exceed ".concat(l," days")}:{isValid:!0,error:null}},X=()=>{if(!m.start||!m.end)return 0;let e=new Date(m.start.year,m.start.month-1,m.start.day);return Math.ceil(Math.abs(new Date(m.end.year,m.end.month-1,m.end.day)-e)/864e5)+1},U=e=>{if("custom"===e){u(!0);return}u(!1),f({start:null,end:null}),s(A(e)),o(!1)};return(0,a.jsxs)(b.j,{isOpen:i,onOpenChange:o,placement:"bottom-start",children:[(0,a.jsx)(w.b,{children:(0,a.jsxs)(N.A,{variant:"bordered",className:"min-w-[140px] justify-start border-default-300 bg-default-100 text-default-700 hover:bg-default-50",startContent:(0,a.jsx)(p.Z,{className:"h-4 w-4"}),endContent:(0,a.jsx)(g.Z,{className:"h-4 w-4"}),children:[(0,a.jsx)("span",{className:"hidden sm:inline",children:R()}),(0,a.jsx)("span",{className:"sm:hidden",children:R()})]})}),(0,a.jsx)(v.g,{className:"w-full p-0 md:w-[520px]",children:(0,a.jsxs)("div",{className:"flex max-h-[400px] w-full flex-col items-start overflow-hidden md:flex-row",children:[(0,a.jsx)("div",{className:"w-full rounded-md border-b border-default-200 bg-default-50 p-4 md:w-[30%]",children:(0,a.jsxs)("div",{className:"w-full space-y-1",children:[(0,a.jsx)("div",{className:"mb-3 text-sm font-medium text-default-900",children:L("date.quickSelect")}),(0,a.jsx)("div",{className:"flex w-full flex-wrap gap-2 md:flex-col",children:E.map(e=>(0,a.jsx)(N.A,{variant:t===e.value?"solid":"light",color:t===e.value?"primary":"default",size:"sm",className:"flex w-auto items-center justify-between bg-gray-200 px-1 md:w-full md:min-w-full md:bg-transparent md:px-2",onPress:()=>U(e.value),startContent:e.isCustom?(0,a.jsx)(j.Z,{className:"h-4 w-4"}):null,children:(0,a.jsx)("div",{className:"flex-1 truncate text-left text-xs",children:e.label})},e.value))}),(0,a.jsx)(y.j,{className:"my-3"}),(0,a.jsxs)("div",{className:"text-xs text-default-500",children:[(0,a.jsx)("div",{children:L("date.maxRange",{maxDays:l})}),c&&m.start&&m.end&&(0,a.jsx)("div",{className:"mt-1",children:L("date.selectedDays",{days:X()})})]})]})}),(0,a.jsx)("div",{className:"w-full flex-1 p-4",children:c?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("div",{className:"text-sm font-medium text-default-900",children:"Custom Date Range"}),(0,a.jsx)(N.A,{size:"sm",variant:"light",onPress:()=>u(!1),children:"Cancel"})]}),(0,a.jsx)("div",{className:"text-xs text-default-600",children:m.start?m.end?(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{children:L("date.selectedDays",{days:X()})}),X()>l&&(0,a.jsx)("span",{className:"text-red-500",children:L("date.exceedsLimit",{maxDays:l})})]}):(0,a.jsx)("span",{children:L("date.selectEndDate")}):(0,a.jsx)("span",{children:L("date.selectStartDate")})}),(0,a.jsx)("div",{className:"rounded-md border border-default-200",children:(0,a.jsx)(S.o,{value:m,onChange:e=>{e&&e.start&&e.end?f(e):f({start:null,end:null})},format:"yyyy/MM/dd",visibleMonths:h?1:2,pageBehavior:"visible",className:"w-full",maxValue:(0,D.Lg)(d),calendarProps:{classNames:{base:"w-full",gridWrapper:"w-full",grid:"w-full shadow-none",content:"w-full bg-transparent"}}})}),(0,a.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,a.jsx)(N.A,{size:"sm",variant:"light",onPress:()=>{f({start:null,end:null})},children:L("date.clearSelection")}),(0,a.jsx)(N.A,{size:"sm",color:"primary",onPress:()=>{let e=Z(m);if(!e.isValid){C.ZP.error(e.error);return}let t=e=>e.toString().padStart(2,"0");s({start:"".concat(m.start.year,"-").concat(t(m.start.month),"-").concat(t(m.start.day)),end:"".concat(m.end.year,"-").concat(t(m.end.month),"-").concat(t(m.end.day))}),o(!1)},isDisabled:!m.start||!m.end||X()>l,children:L("date.applyRange")})]})]}):(0,a.jsxs)("div",{className:"py-8 text-center text-default-500",children:[(0,a.jsx)(p.Z,{className:"mx-auto mb-4 h-12 w-12 opacity-50"}),(0,a.jsx)("p",{children:L("date.customRange")})]})})]})})]})},L=e=>{let{apiKeys:t,dateRange:s}=e,[l,n]=(0,r.useState)("spend"),{t:d}=(0,x.Z)("usage"),{start:i,end:o}=(()=>{let e=new Date,t=new Date;switch(s){case"week":t.setDate(e.getDate()-e.getDay());break;case"month":t.setDate(1);break;case"7d":t.setDate(e.getDate()-6);break;case"14d":default:t.setDate(e.getDate()-13);break;case"30d":t.setDate(e.getDate()-29)}return{start:t.toLocaleDateString("en-US",{month:"short",day:"numeric"}),end:e.toLocaleDateString("en-US",{month:"short",day:"numeric"})}})(),c=e=>
1new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),u=e=>{let t=e.substring(0,4),s=e.substring(e.length-4);return"".concat(t,"****").concat(s)};return(0,a.jsxs)(m.w,{className:"w-full border border-transparent dark:border-default-50",children:[(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-1",children:[(0,a.jsx)("div",{className:"font-semibold text-default-900",children:"API Keys"}),(0,a.jsx)("p",{className:"text-sm text-default-500",children:d("date.apiKeys")})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)("button",{onClick:()=>n("spend"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("spend"===l?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Spend"}),(0,a.jsx)("button",{onClick:()=>n("requests"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("requests"===l?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Credits"})]})]}),(0,a.jsx)("div",{className:"p-6",children:(0,a.jsx)("div",{className:"space-y-4",children:t.length>0?(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsx)("div",{className:"flex items-center justify-between rounded-lg border border-default-100 p-4 transition-colors hover:border-default-200",children:(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"mb-2",children:[(0,a.jsx)("div",{className:"font-medium text-default-900",children:e.apiKeyName?e.apiKeyName+" API Key":"Default API Key"}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-4 text-sm text-default-600",children:[(0,a.jsx)("span",{className:"rounded bg-default-100 px-2 py-1 font-mono text-xs text-default-900",children:u(e.apiKey)}),(0,a.jsxs)("span",{children:["Created ",c(e.created)]}),(0,a.jsxs)("span",{children:["Last used ",c(e.lastUsed)]})]})]}),(0,a.jsxs)("div",{className:"mb-3",children:[(0,a.jsx)("div",{className:"mb-2 text-sm text-default-600",children:(0,a.jsxs)("span",{className:"flex items-center gap-1",children:[(0,a.jsx)("div",{className:"h-3 w-3 rounded-full bg-blue-500"}),"spend"===l?"$".concat(e.totalSpend," total spend"):"".concat(e.totalCredits.toLocaleString()," total credits")]})}),(0,a.jsx)(f,{dailyRecords:e.dailyRecords,type:l,showToggle:!1})]}),(0,a.jsxs)("div",{className:"flex justify-between text-xs text-default-500",children:[(0,a.jsx)("span",{children:i}),(0,a.jsx)("span",{children:o})]})]})},t))}):(0,a.jsx)("div",{className:"w-full p-12 text-center text-default-500",children:(0,a.jsx)("p",{children:d("date.noApiKeys")})})})})]})},E=e=>{let{data:t}=e;return(0,a.jsx)("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-4"})};var A=s(2649),R=s(95866),Z=s(1993),X=s(38489),U=s(26972),_=s(29911),I=s(25411),M=s(79399),F=s(44421),K=s(2855),O=s(19609),V=s(27220),z=s(82135),q=s(72114);let W=["=","+","@"," ","\r"],B=e=>""!==e&&Number.isFinite(Number(e));function Y(e){if(null==e)return"";let t=String(e);return(W.some(e=>t.startsWith(e))?t="'".concat(t):t.startsWith("-")&&!B(t)&&(t="'".concat(t)),/[",\r\n]/.test(t))?'"'.concat(t.replace(/"/g,'""'),'"'):t}function $(e){return e&&0!==e.length?e.map(e=>e.map(Y).join(",")).join("\r\n")+"\r\n":""}let H=["API Key","Model","Credits Consumed","Create Time","Task ID"],J=(e,t)=>[e.apiKey||"",e.modelName||"",String((e.creditsConsumed||0)/100),(0,q.wi)(e.createTime,t),e.taskId||""],G=e=>{let t="xlsx",s=0,a=[],r=[],l=()=>{t="csv",r.push("\uFEFF",$([H])),r.push($(a.map(t=>J(t,e)))),a=[]};return{push(n){if(n&&0!==n.length){if(s+=n.length,"csv"===t){r.push($(n.map(t=>J(t,e))));return}for(let e=0;e<n.length;e+=1)a.push(n[e]);s>5e4&&l()}},getRowCount:()=>s,getFormat:()=>t,finish:()=>({format:t,rowCount:s,records:a,chunks:r})}},Q=e=>{let t=(0,D.Lg)(e);return{start:t.subtract({days:30}),end:t}},ee=(0,z.Pi)(e=>{let{isOpen:t,onClose:s}=e,{t:l}=(0,x.Z)("usage"),{userStore:n}=(0,V.o)(),d=(0,q.uY)(n.user),[i,o]=(0,r.useState)(d),[c,u]=(0,r.useState)(()=>Q(d).start),[m,f]=(0,r.useState)(()=>Q(d).end),[h,p]=(0,r.useState)({}),[g,j]=(0,r.useState)(!1),[b,w]=(0,r.useState)(0),[v,y]=(0,r.useState)(0),[S,k]=(0,r.useState)(0),[P,T]=(0,r.useState)("xlsx"),L=(0,r.useRef)(!1),E=(0,r.useRef)(null),z=(0,r.useRef)(d),W=(0,r.useMemo)(()=>
1Array.from(new Set([i,d,(0,q.ei)(),...(0,q.hA)()])).filter(Boolean).sort((e,t)=>e.localeCompare(t)),[i,d]);(0,r.useEffect)(()=>{if(t){L.current=!0,o(d);let e=Q(d);u(e.start),f(e.end),E.current=e.end,z.current=d,p({}),g||0!==b||0!==v||(w(0),y(0))}else L.current=!1},[t,d]),(0,r.useEffect)(()=>{if(!t||!i||!c||!m||z.current===i)return;let e=(0,D.Lg)(i),s=E.current,a=c,r=m;s&&0===r.compare(s)&&(r=e),r.compare(e)>0&&(r=e),a.compare(r)>0&&(a=r),Math.ceil((r.toDate(i).getTime()-a.toDate(i).getTime())/864e5)+1>31&&(a=r.subtract({days:30})),0!==a.compare(c)&&u(a),0!==r.compare(m)&&f(r),E.current=e,z.current=i},[t,i,c,m]);let B=(0,r.useMemo)(()=>{let e={};return c&&m&&(0>=m.compare(c)&&(e.endDate="End date must be after start date"),Math.ceil((m.toDate(i).getTime()-c.toDate(i).getTime())/864e5)+1>31&&(e.dateRange="The time range cannot exceed 31 days")),p(e),0===Object.keys(e).length},[c,m,i]),Y=async(e,t,s,a,r)=>{try{let l={startTime:e,endTime:t,timeZone:r,pageNum:s};null!=a&&(l.lastId=a);let n=await O.Z.post("/client/v1/credits/exportUsageInfo",l);if(200===n.code)return{records:n.data.records||[],lastId:n.data.lastId||0,hasMore:n.data.hasMore||!1,pages:n.data.pages||0};return C.ZP.error(n.msg||"Failed to fetch export data. Please try again."),null}catch(e){return console.error("Error fetching export data:",e),C.ZP.error("Failed to fetch export data. Please try again."),null}},$=async(e,t,s,a)=>{try{let r=null,l=1,n=!0;for(;n;){if(l>2e3)return C.ZP.error("Too much data to export. Please narrow the time range."),!1;let d=await Y(e,t,l,r,s);if(!d)return C.ZP.error("Export failed. Please try again."),!1;let{records:i,lastId:o,hasMore:c,pages:u}=d;if(1===l&&u>0&&w(u),y(l),a.push(i),k(a.getRowCount()),T(a.getFormat()),c&&o===r)return C.ZP.error("Export failed. Please try again."),!1;r=o,(n=c)&&l++}return!0}catch(e){return console.error("Error fetching all export data:",e),C.ZP.error("Failed to fetch export data. Please try again."),!1}},ee=(e,t,s)=>{let a=[H,...e.map(e=>J(e,t))],r=K.P6.aoa_to_sheet(a);r["!cols"]=[{wch:50},{wch:50},{wch:18},{wch:30},{wch:50}];let l=K.P6.book_new();K.P6.book_append_sheet(l,r,"Usage Data"),K.NC(l,"".concat(s,".xlsx"))},et=async()=>{if(B)try{j(!0),k(0),T("xlsx"),C.ZP.success("Exporting data, please wait...");let e=c.toString(),t=m.toString(),a=G(i);if(!await $(e,t,i,a))return;let{format:r,rowCount:l,records:n,chunks:d}=a.finish();if(0===l){C.ZP.error("No data to export");return}let o=c.toString(),u=m.toString(),x="usage_data_".concat(o,"_to_").concat(u);"csv"===r?(function(e,t){let s=new Blob(e,{type:"text/csv;charset=utf-8;"}),a=URL.createObjectURL(s),r=document.createElement("a");r.href=a,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(a),1e3)}(d,"".concat(x,".csv")),C.ZP.success("Export successful. ".concat(l.toLocaleString()," rows exported as CSV because the data is too large for XLSX."))):(ee(n,i,x),C.ZP.success("Export successful")),s()}catch(e){console.error("Error exporting file:",e),C.ZP.error("Failed to export data. Please try again.")}finally{j(!1),w(0),y(0),k(0)}};return(0,a.jsx)(A.R,{isOpen:t,onOpenChange:s,placement:"center",size:"md",children:(0,a.jsx)(R.A,{children:e=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(Z.k,{className:"flex flex-col gap-1",children:[(0,a.jsx)("div",{className:"text-xl font-semibold",children:"Export"}),(0,a.jsx)("p",{className:"text-sm text-default-500",children:"Export Usage Data"})]}),(0,a.jsx)(X.I,{children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(U.J,{label:"Start time",value:c,onChange:u,maxValue:(0,D.Lg)(i),isInvalid:!!h.endDate,className:"w-full"}),(0,a.jsx)(U.J,{label:"End time",value:m,onChange:f,maxValue:(0,D.Lg)(i),minValue:c,isInvalid:!!h.endDate||!!h.dateRange,className:"w-full"}),(0,a.jsx)(_.d,{label:l("export.timeZone"),selectedKey:i,onSelectionChange:e=>{e&&o(String(e))},defaultFilter:(e,t)=>{if(!t)return!0;let s=t.toLowerCase();return e.toLowerCase().includes(s)},isClearable:!1,menuTrigger:"focus",isVirtualized:!0,itemHeight:36,maxListboxHeight:320,className:"w-full",classNames:{listboxWrapper:"max-h-80",popoverContent:"max-h-80"},children:W.map(e=>(0,a.jsx)(I.R,{textValue:(0,q._8)(e),children:(0,a.jsx)("span",{className:"block max-w-full truncate whitespace-nowrap",children:(0,q._8)(e)})},e))}),(h.dateRange||h.endDate)&&(0,a.jsxs)("div",{className:"rounded-lg bg-danger-50 p-3 text-sm text-danger-600",children:[h.dateRange&&(0,a.jsxs)("div",{children:["⢠",h.dateRange]}),h.endDate&&(0,a.jsxs)("div",{children:["⢠",h.endDate]})]}),c&&m&&B&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rounded-lg bg-success-50 p-3 text-sm text-success-600",children:["â Selected"," ",Math.
1ceil((m.toDate(i).getTime()-c.toDate(i).getTime())/864e5)+1," ","days data"]}),g&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 text-sm text-default-600",children:[(0,a.jsx)("span",{children:"Exporting progress..."}),(0,a.jsxs)("span",{className:"tabular-nums text-default-500",children:[S.toLocaleString()," rows",b>0?" \xb7 ".concat(v,"/").concat(b):""]})]}),(0,a.jsx)(M.W,{"aria-label":"Export progress",value:b>0?Math.min(v/b*100,100):0,isIndeterminate:0===b,className:"w-full",color:"primary"}),"csv"===P&&(0,a.jsx)("div",{className:"rounded-lg bg-warning-50 p-3 text-sm text-warning-700",children:"This export exceeds the XLSX limit, so it will be saved as a CSV file. You can still open it in Excel."})]})]})]})}),(0,a.jsxs)(F.R,{children:[(0,a.jsx)(N.A,{variant:"light",onPress:e,children:"Cancel"}),(0,a.jsx)(N.A,{color:"primary",onPress:et,isDisabled:!B||!c||!m||g,isLoading:g,children:"Export"})]})]})})})});var et=s(46402),es=s(84140);function ea(e){let{dailyRecords:t,totalSpend:s,totalCredits:l}=e,{t:n}=(0,x.Z)("dashboard"),[d,i]=(0,r.useState)("spend");return(0,a.jsxs)(m.w,{className:"h-auto w-full border border-transparent dark:border-default-50",children:["requests"===d&&(0,a.jsx)("div",{className:"w-full px-6 pt-6",children:(0,a.jsxs)("div",{className:"flex w-full items-start justify-between gap-2 rounded-lg bg-orange-600/5 px-4 py-3",children:[(0,a.jsx)(es.JO,{icon:"typcn:info",className:"shrink-0 text-orange-500",width:16,height:16}),(0,a.jsx)("p",{className:"min-w-0 flex-1 text-xs text-orange-500",children:n("billing.totalCreditsUsageHint")})]})}),(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("div",{className:"text-lg font-semibold text-default-900",children:"spend"===d?"Total Spend":"Total Credits"}),(0,a.jsx)("p",{className:"text-3xl font-bold text-default-900",children:"spend"===d?"$".concat(s):l.toLocaleString()})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)("button",{onClick:()=>i("spend"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("spend"===d?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Spend"}),(0,a.jsx)("button",{onClick:()=>i("requests"),className:"rounded-md px-3 py-1 text-sm font-medium transition-colors ".concat("requests"===d?"bg-default-500/10 text-default-foreground":"text-default-500 hover:text-default-foreground"),children:"Total Credits"})]})]}),(0,a.jsx)("div",{className:"p-6",children:(0,a.jsx)(u,{data:"spend"===d?t.map(e=>e.spend):t.map(e=>e.creditsConsumed),labels:t.map(e=>e.date),type:d})})]})}let er=e=>{let t=(0,D.Lg)(e);return{start:t.subtract({days:13}).toString(),end:t.toString()}},el=(0,z.Pi)(()=>{let{userStore:e}=(0,V.o)(),t=(0,q.uY)(e.user),[s,l]=(0,r.useState)(()=>er(t)),[n,d]=(0,r.useState)(null),[i,c]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1);(0,r.useEffect)(()=>
1{l(er(t))},[t]);let f=async()=>{if(!u){x(!0);try{let e=await O.Z.post("/client/v1/credits/usagePage",{startTime:s.start,endTime:s.end,timeZone:t});200===e.code?d(e.data):C.ZP.error(e.msg)}catch(e){console.error("Error fetching usage data:",e)}finally{x(!1)}}};return(0,r.useEffect)(()=>{e.user&&f()},[s,e.user,t]),(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3 lg:absolute lg:right-6 lg:top-5",children:[(0,a.jsx)(T,{value:s,onChange:l,maxDays:31,timeZone:t}),(0,a.jsxs)(N.A,{color:"primary",variant:"solid",onPress:()=>c(!0),className:"inline-flex items-center gap-2",children:[(0,a.jsx)(o.Z,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"Export"})]})]}),u?(0,a.jsxs)("div",{className:"mx-auto w-full",children:[(0,a.jsx)("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-4"}),(0,a.jsxs)("div",{className:"mt-8 w-full space-y-8",children:[(0,a.jsxs)(m.w,{className:"h-auto w-full border border-transparent dark:border-default-50",children:[(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)(et.X,{className:"h-6 w-32 rounded-lg"}),(0,a.jsx)(et.X,{className:"mt-2 h-10 w-24 rounded-lg"})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)(et.X,{className:"h-8 w-20 rounded-md"}),(0,a.jsx)(et.X,{className:"ml-1 h-8 w-20 rounded-md"})]})]}),(0,a.jsx)("div",{className:"p-6",children:(0,a.jsx)(et.X,{className:"h-[300px] w-full rounded-lg"})})]}),(0,a.jsxs)(m.w,{className:"w-full border border-transparent pb-6 dark:border-default-50",children:[(0,a.jsxs)("div",{className:"mb-6 w-full",children:[(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-1",children:[(0,a.jsx)(et.X,{className:"h-5 w-32 rounded-lg"}),(0,a.jsx)(et.X,{className:"h-4 w-48 rounded-lg"})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)(et.X,{className:"h-8 w-20 rounded-md"}),(0,a.jsx)(et.X,{className:"ml-1 h-8 w-20 rounded-md"})]})]}),(0,a.jsx)("div",{className:"flex border-b border-default-200",children:(0,a.jsx)(et.X,{className:"h-10 w-32 rounded-none"})})]}),(0,a.jsx)("div",{className:"grid w-full grid-cols-1 gap-6 px-4 md:grid-cols-2 lg:px-6",children:Array.from({length:4}).map((e,t)=>(0,a.jsxs)("div",{className:"rounded-xl border border-default-100 p-6 shadow-sm",children:[(0,a.jsx)("div",{className:"mb-4 flex items-center justify-between",children:(0,a.jsxs)("div",{children:[(0,a.jsx)(et.X,{className:"h-5 w-24 rounded-lg"}),(0,a.jsx)(et.X,{className:"mt-1 h-4 w-32 rounded-lg"})]})}),(0,a.jsx)("div",{className:"mb-4",children:(0,a.jsx)(et.X,{className:"h-[200px] w-full rounded-lg"})}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)(et.X,{className:"h-4 w-12 rounded-lg"}),(0,a.jsx)(et.X,{className:"h-4 w-12 rounded-lg"})]})]},t))})]}),(0,a.jsxs)(m.w,{className:"w-full border border-transparent dark:border-default-50",children:[(0,a.jsxs)("div",{className:"flex w-full flex-col items-start justify-between gap-2 border-b border-default-500/10 p-6 md:flex-row md:items-center",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-1",children:[(0,a.jsx)(et.X,{className:"h-5 w-24 rounded-lg"}),(0,a.jsx)(et.X,{className:"h-4 w-40 rounded-lg"})]}),(0,a.jsxs)("div",{className:"flex rounded-lg bg-default-100 p-1",children:[(0,a.jsx)(et.X,{className:"h-8 w-20 rounded-md"}),(0,a.jsx)(et.X,{className:"ml-1 h-8 w-20 rounded-md"})]})]}),(0,a.jsx)("div",{className:"p-6",children:(0,a.jsx)("div",{className:"space-y-4",children:Array.from({length:3}).map((e,t)=>(0,a.jsx)("div",{className:"flex items-center justify-between rounded-lg border border-default-100 p-4",children:(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"mb-2",children:[(0,a.jsx)(et.X,{className:"h-5 w-40 rounded-lg"}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-4",children:[(0,a.jsx)(et.X,{className:"h-6 w-24 rounded"}),(0,a.jsx)(et.X,{className:"h-4 w-32 rounded-lg"}),(0,a.jsx)(et.X,{className:"h-4 w-28 rounded-lg"})]})]}),(0,a.jsxs)("div",{className:"mb-3",children:[(0,a.jsx)("div",{className:"mb-2",children:(0,a.jsx)(et.X,{className:"h-4 w-36 rounded-lg"})}),(0,a.jsx)(et.X,{className:"h-[120px] w-full rounded-lg"})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)(et.X,{className:"h-3 w-12 rounded-lg"}),(0,a.jsx)(et.X,{className:"h-3 w-12 rounded-lg"})]})]})},t))})})]})]})]}):n?(0,a.jsxs)("div",{className:"mx-auto w-full",children:[(0,a.jsx)(E,{data:n}),(0,a.jsxs)("div",{className:"mt-8 w-full space-y-8",children:[(0,a.jsx)(ea,{dailyRecords:n.overview.dailyRecords,totalSpend:n.overview.totalSpend,totalCredits:n.overview.totalCredits}),(0,a.jsx)(h,{services:n.apiEndpoints.modelRecords,dateRange:s}),(0,a.jsx)(L,{apiKeys:n.apiKeys.apiKeyRecords,dateRange:s})]})]}):(0,a.jsx)(m.w,{className:"mx-auto flex min-h-[400px] w-full items-center justify-center",children:(0,a.jsx)("div",{className:"text-lg text-gray-600",children:"No data"})}),(0,a.jsx)(ee,{isOpen:i,onClose:()=>c(!1)})]})})});var en=s(68237),ed=!0,ei=function(){let e=(0,en.useRouter)(),{t}=(0,x.Z)("common");return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(n(),{children:[(0,a.jsx)("title",{children:t("head.title")}),(0,a.jsx)("meta",{name:"description",content:t("head.description")}),(0,a.jsx)("meta",{name:"robots",content:"noindex"}),(0,d.t5)(e," /usage")]}),(0,a.jsx)("div",{className:"relative w-full",children:(0,a.jsx)("main",{children:(0,a.jsx)(i.Z,{selectedKey:"api-usage",children:(0,a.jsx)(el,{})})})})]})}},72114:function(e,t,s){"use strict";s.d(t,{_8:function(){return i},ei:function(){return r},hA:function(){return n},uY:function(){return l},wi:function(){return u}});let a=["UTC","America/Los_Angeles","America/Denver","America/Chicago","America/Ne
1w_York","America/Sao_Paulo","Europe/London","Europe/Paris","Europe/Berlin","Europe/Moscow","Asia/Dubai","Asia/Kolkata","Asia/Bangkok","Asia/Singapore","Asia/Shanghai","Asia/Hong_Kong","Asia/Tokyo","Asia/Seoul","Australia/Sydney","Pacific/Auckland"],r=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}},l=e=>(null==e?void 0:e.timezone)||(null==e?void 0:e.timeZone)||r()||"UTC",n=()=>Array.from(new Set(["UTC",..."function"==typeof Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):a])),d=e=>{try{var t;let s=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"shortOffset"}).formatToParts(new Date),a=null===(t=s.find(e=>"timeZoneName"===e.type))||void 0===t?void 0:t.value;return a?a.replace("GMT","UTC"):"UTC+0"}catch(e){return"UTC+0"}},i=e=>"(".concat(d(e),") ").concat(e),o=new Map,c=e=>{let t=e||"UTC",s=o.get(t);if(s)return s;let a=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"});return o.set(t,a),a},u=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(!e)return s;let a=new Date(e);if(Number.isNaN(a.getTime()))return s;try{let e=c(t).formatToParts(a),s=t=>{var s;return(null===(s=e.find(e=>e.type===t))||void 0===s?void 0:s.value)||""};return"".concat(s("year"),"-").concat(s("month"),"-").concat(s("day")," ").concat(s("hour"),":").concat(s("minute"),":").concat(s("second"))}catch(e){return s}}},24863:function(){},82963:function(){}},function(e){e.O(0,[5704,9536,2004,2324,5464,4285,6380,5143,1472,9591,7829,2015,4644,2045,1347,2278,6179,7410,2929,9648,7747,245,8163,9911,3894,7270,8351,2365,8375,2888,9774,179],function(){return e(e.s=91497)}),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.