tokmon 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZZ7DIK3O.js → chunk-STCMWCFW.js} +1 -4
- package/dist/{chunk-TLE24LIH.js → chunk-UAPL47GL.js} +56 -11
- package/dist/cli.js +4 -9
- package/dist/{server-UPX3ANBP.js → server-VMB5ZLZC.js} +2 -2
- package/dist/web/assets/breakdown-Z8sjyQBd.js +4 -0
- package/dist/web/assets/chart-GXfbPcfM.js +69 -0
- package/dist/web/assets/{index-B-HEpWCR.css → index-BIvuNQZ9.css} +1 -1
- package/dist/web/assets/index-Du2fmToJ.js +80 -0
- package/dist/web/assets/timeline-CtYOp-UM.js +2 -0
- package/dist/web/index.html +2 -2
- package/dist/{web-23FJCFDS.js → web-DYAEMCAE.js} +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-aha2Tekh.js +0 -113
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
cacheDir,
|
|
6
6
|
detectProviders,
|
|
7
7
|
resolveTimezone
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-UAPL47GL.js";
|
|
9
9
|
|
|
10
10
|
// src/web/server.ts
|
|
11
11
|
import { createServer } from "http";
|
|
@@ -52,9 +52,6 @@ async function resolveAccounts(config) {
|
|
|
52
52
|
const p = PROVIDERS[a.providerId];
|
|
53
53
|
return {
|
|
54
54
|
account: a,
|
|
55
|
-
// Web-only: a provider with a usage table (e.g. Cursor's local composer history)
|
|
56
|
-
// shows in the dashboard's leaderboard/calendar/explore even when its TUI flag is
|
|
57
|
-
// false. The TUI reads PROVIDERS[id].hasUsage directly, so it is unaffected.
|
|
58
55
|
hasUsage: p.hasUsage || !!p.fetchTable,
|
|
59
56
|
hasBilling: p.hasBilling,
|
|
60
57
|
color: colorHex(a.color, PROVIDERS[a.providerId].color)
|
|
@@ -1524,11 +1524,9 @@ async function cursorApiUsage(tz, homeDir) {
|
|
|
1524
1524
|
const endMs = Date.now();
|
|
1525
1525
|
const startMs = endMs - WINDOW_DAYS * 864e5;
|
|
1526
1526
|
const events = [];
|
|
1527
|
-
let
|
|
1528
|
-
for (let page = 1; page <= MAX_PAGES && events.length < total; page++) {
|
|
1527
|
+
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
1529
1528
|
const resp = await fetchPage(token, startMs, endMs, page);
|
|
1530
1529
|
if (!resp) return page === 1 ? null : finalizeTable(events, tz);
|
|
1531
|
-
total = resp.totalUsageEventsCount ?? 0;
|
|
1532
1530
|
const batch = resp.usageEventsDisplay ?? [];
|
|
1533
1531
|
events.push(...batch);
|
|
1534
1532
|
if (batch.length < PAGE_SIZE) break;
|
|
@@ -1566,10 +1564,11 @@ function finalizeTable(events, tz) {
|
|
|
1566
1564
|
const ts = Number(e.timestamp);
|
|
1567
1565
|
if (!Number.isFinite(ts) || ts <= 0) continue;
|
|
1568
1566
|
const tu = e.tokenUsage ?? {};
|
|
1569
|
-
const input =
|
|
1570
|
-
const output =
|
|
1571
|
-
const cacheRead =
|
|
1572
|
-
const
|
|
1567
|
+
const input = safeNum(tu.inputTokens);
|
|
1568
|
+
const output = safeNum(tu.outputTokens);
|
|
1569
|
+
const cacheRead = safeNum(tu.cacheReadTokens);
|
|
1570
|
+
const cents = Number(e.chargedCents);
|
|
1571
|
+
const usd = Number.isFinite(cents) && cents > 0 ? cents / 100 : 0;
|
|
1573
1572
|
if (usd <= 0 && input + output + cacheRead === 0) continue;
|
|
1574
1573
|
const model = String(e.model ?? "unknown");
|
|
1575
1574
|
put(buckets.daily, dayKey(ts, tz), model, usd, input, output, cacheRead);
|
|
@@ -1587,16 +1586,62 @@ function finalizeTable(events, tz) {
|
|
|
1587
1586
|
|
|
1588
1587
|
// src/providers/cursor/index.ts
|
|
1589
1588
|
var EMPTY = { daily: [], weekly: [], monthly: [] };
|
|
1589
|
+
var overlayDaily = (lo, hi) => {
|
|
1590
|
+
const m = new Map(lo.map((r) => [r.label, r]));
|
|
1591
|
+
for (const r of hi) m.set(r.label, r);
|
|
1592
|
+
return [...m.values()].sort((a, b) => a.label.localeCompare(b.label));
|
|
1593
|
+
};
|
|
1594
|
+
function reBucket(daily, tz, keyOf) {
|
|
1595
|
+
const out = /* @__PURE__ */ new Map();
|
|
1596
|
+
for (const day of daily) {
|
|
1597
|
+
const [y, mo, d] = day.label.split("-").map(Number);
|
|
1598
|
+
const label = keyOf(Date.UTC(y, mo - 1, d, 12), tz);
|
|
1599
|
+
let row = out.get(label);
|
|
1600
|
+
if (!row) {
|
|
1601
|
+
row = { label, models: [], input: 0, output: 0, cacheCreate: 0, cacheRead: 0, cacheSavings: 0, total: 0, cost: 0, count: 0, breakdown: [] };
|
|
1602
|
+
out.set(label, row);
|
|
1603
|
+
}
|
|
1604
|
+
row.input += day.input;
|
|
1605
|
+
row.output += day.output;
|
|
1606
|
+
row.cacheCreate += day.cacheCreate;
|
|
1607
|
+
row.cacheRead += day.cacheRead;
|
|
1608
|
+
row.cacheSavings += day.cacheSavings;
|
|
1609
|
+
row.total += day.total;
|
|
1610
|
+
row.cost += day.cost;
|
|
1611
|
+
row.count += day.count;
|
|
1612
|
+
for (const b of day.breakdown) {
|
|
1613
|
+
let md = row.breakdown.find((x) => x.name === b.name);
|
|
1614
|
+
if (!md) {
|
|
1615
|
+
md = { name: b.name, input: 0, output: 0, cacheCreate: 0, cacheRead: 0, cacheSavings: 0, cost: 0, count: 0 };
|
|
1616
|
+
row.breakdown.push(md);
|
|
1617
|
+
}
|
|
1618
|
+
md.input += b.input;
|
|
1619
|
+
md.output += b.output;
|
|
1620
|
+
md.cacheCreate += b.cacheCreate;
|
|
1621
|
+
md.cacheRead += b.cacheRead;
|
|
1622
|
+
md.cacheSavings += b.cacheSavings;
|
|
1623
|
+
md.cost += b.cost;
|
|
1624
|
+
md.count += b.count;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return [...out.values()].map((r) => {
|
|
1628
|
+
r.breakdown.sort((a, b) => b.cost - a.cost);
|
|
1629
|
+
r.models = r.breakdown.map((b) => b.name);
|
|
1630
|
+
return r;
|
|
1631
|
+
}).sort((a, b) => a.label.localeCompare(b.label));
|
|
1632
|
+
}
|
|
1590
1633
|
async function cursorTable(tz, homeDir) {
|
|
1591
|
-
|
|
1634
|
+
const [api, local] = await Promise.all([cursorApiUsage(tz, homeDir), cursorUsageTable(tz, homeDir)]);
|
|
1635
|
+
if (!api && !local) return EMPTY;
|
|
1636
|
+
const daily = overlayDaily(local?.daily ?? [], api?.daily ?? []);
|
|
1637
|
+
if (daily.length === 0) return EMPTY;
|
|
1638
|
+
return { daily, weekly: reBucket(daily, tz, weekKey), monthly: reBucket(daily, tz, monthKey) };
|
|
1592
1639
|
}
|
|
1593
1640
|
var cursorProvider = {
|
|
1594
1641
|
id: "cursor",
|
|
1595
1642
|
name: "Cursor",
|
|
1596
1643
|
color: "magenta",
|
|
1597
|
-
// hasUsage
|
|
1598
|
-
// The web surfaces the usage table via fetchTable (resolveAccounts promotes any
|
|
1599
|
-
// provider with a fetchTable to hasUsage for the dashboard only).
|
|
1644
|
+
// hasUsage: false — TUI keys its dedicated Cursor spend-table off this flag directly.
|
|
1600
1645
|
hasUsage: false,
|
|
1601
1646
|
hasBilling: true,
|
|
1602
1647
|
detect: (homeDir) => detectCursor(homeDir),
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
systemTimezone,
|
|
24
24
|
time,
|
|
25
25
|
tokens
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-UAPL47GL.js";
|
|
27
27
|
|
|
28
28
|
// src/cli.tsx
|
|
29
29
|
import { EventEmitter } from "events";
|
|
@@ -1606,11 +1606,7 @@ function App({ interval: cliInterval, initialConfig }) {
|
|
|
1606
1606
|
const hasStrip = slots.length > 1;
|
|
1607
1607
|
const stripChipW = (s) => 2 + 2 + truncateName(s.name, 16).length + 2;
|
|
1608
1608
|
const stripChars = slots.reduce((sum, s) => sum + stripChipW(s), 0);
|
|
1609
|
-
const stripLines = hasStrip ? Math.max(1, Math.ceil(stripChars / Math.max(
|
|
1610
|
-
1,
|
|
1611
|
-
cols - 4 - 7
|
|
1612
|
-
/*"focus "*/
|
|
1613
|
-
))) : 0;
|
|
1609
|
+
const stripLines = hasStrip ? Math.max(1, Math.ceil(stripChars / Math.max(1, cols - 4 - 7))) : 0;
|
|
1614
1610
|
const headerRows = cols < 70 ? 2 : 1;
|
|
1615
1611
|
const CHROME = 2 + headerRows + 3 + (hasStrip ? 1 + stripLines : 0) + 2 + 2;
|
|
1616
1612
|
const gridBudget = Math.max(1, rows - CHROME);
|
|
@@ -1856,7 +1852,6 @@ function App({ interval: cliInterval, initialConfig }) {
|
|
|
1856
1852
|
function toggleProvider(pid) {
|
|
1857
1853
|
updateConfig((c) => ({
|
|
1858
1854
|
...c,
|
|
1859
|
-
// Toggling in settings is also an explicit decision → mark it known.
|
|
1860
1855
|
knownProviders: c.knownProviders.includes(pid) ? c.knownProviders : [...c.knownProviders, pid],
|
|
1861
1856
|
disabledProviders: c.disabledProviders.includes(pid) ? c.disabledProviders.filter((p) => p !== pid) : [...c.disabledProviders, pid]
|
|
1862
1857
|
}));
|
|
@@ -1996,7 +1991,7 @@ function App({ interval: cliInterval, initialConfig }) {
|
|
|
1996
1991
|
setWebStatus("off");
|
|
1997
1992
|
} else {
|
|
1998
1993
|
setWebStatus("starting");
|
|
1999
|
-
const { startWebServer } = await import("./server-
|
|
1994
|
+
const { startWebServer } = await import("./server-VMB5ZLZC.js");
|
|
2000
1995
|
const ctrl = await startWebServer({ config: cfg, log: false });
|
|
2001
1996
|
webRef.current = ctrl;
|
|
2002
1997
|
setWebUrl(ctrl.url);
|
|
@@ -2674,7 +2669,7 @@ process.emitWarning = ((warning, ...rest) => {
|
|
|
2674
2669
|
var args = process.argv.slice(2);
|
|
2675
2670
|
var subcommand = args[0]?.toLowerCase();
|
|
2676
2671
|
if (subcommand === "serve" || subcommand === "web") {
|
|
2677
|
-
const { startWeb } = await import("./web-
|
|
2672
|
+
const { startWeb } = await import("./web-DYAEMCAE.js");
|
|
2678
2673
|
await startWeb(args.slice(1));
|
|
2679
2674
|
process.exit(typeof process.exitCode === "number" ? process.exitCode : 0);
|
|
2680
2675
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{R as m,g as Qe,r as ue,j as u,P as fe,E as pe,a as Ye,s as J,b as G,c as z,d as Je,T as re}from"./index-Du2fmToJ.js";import{c as N,a as A,y as et,z as xt,B as tt,F as At,i as C,H as Oe,I as S,L as _,J as rt,K as Pe,M as nt,D as kt,C as Ot,e as W,j as F,S as Pt,A as jt,N as _t,b as De,d as wt,l as M,g as je,u as Tt,G as St,O as ie,f as Et,P as _e,Q as Rt,U as ne,V as Be,o as it,W as we,X as Te,Y as Se,p as Nt,Z as It,q as Ee,_ as at,r as Re,R as Ne,s as ot,t as st,v as oe,T as ct,x as Ie}from"./chart-GXfbPcfM.js";var Lt=["points","className","baseLinePoints","connectNulls"];function V(){return V=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},V.apply(this,arguments)}function $t(r,e){if(r==null)return{};var n=Ct(r,e),t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(i=0;i<a.length;i++)t=a[i],!(e.indexOf(t)>=0)&&Object.prototype.propertyIsEnumerable.call(r,t)&&(n[t]=r[t])}return n}function Ct(r,e){if(r==null)return{};var n={};for(var t in r)if(Object.prototype.hasOwnProperty.call(r,t)){if(e.indexOf(t)>=0)continue;n[t]=r[t]}return n}function Ke(r){return Ft(r)||Kt(r)||Bt(r)||Dt()}function Dt(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Bt(r,e){if(r){if(typeof r=="string")return be(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);if(n==="Object"&&r.constructor&&(n=r.constructor.name),n==="Map"||n==="Set")return Array.from(r);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return be(r,e)}}function Kt(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function Ft(r){if(Array.isArray(r))return be(r)}function be(r,e){(e==null||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var Fe=function(e){return e&&e.x===+e.x&&e.y===+e.y},Mt=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],n=[[]];return e.forEach(function(t){Fe(t)?n[n.length-1].push(t):n[n.length-1].length>0&&n.push([])}),Fe(e[0])&&n[n.length-1].push(e[0]),n[n.length-1].length<=0&&(n=n.slice(0,-1)),n},Q=function(e,n){var t=Mt(e);n&&(t=[t.reduce(function(a,o){return[].concat(Ke(a),Ke(o))},[])]);var i=t.map(function(a){return a.reduce(function(o,l,c){return"".concat(o).concat(c===0?"M":"L").concat(l.x,",").concat(l.y)},"")}).join("");return t.length===1?"".concat(i,"Z"):i},Vt=function(e,n,t){var i=Q(e,t);return"".concat(i.slice(-1)==="Z"?i.slice(0,-1):i,"L").concat(Q(n.reverse(),t).slice(1))},qt=function(e){var n=e.points,t=e.className,i=e.baseLinePoints,a=e.connectNulls,o=$t(e,Lt);if(!n||!n.length)return null;var l=N("recharts-polygon",t);if(i&&i.length){var c=o.stroke&&o.stroke!=="none",s=Vt(n,i,a);return m.createElement("g",{className:l},m.createElement("path",V({},A(o,!0),{fill:s.slice(-1)==="Z"?o.fill:"none",stroke:"none",d:s})),c?m.createElement("path",V({},A(o,!0),{fill:"none",d:Q(n,a)})):null,c?m.createElement("path",V({},A(o,!0),{fill:"none",d:Q(i,a)})):null)}var f=Q(n,a);return m.createElement("path",V({},A(o,!0),{fill:f.slice(-1)==="Z"?o.fill:"none",className:l,d:f}))},ye,Me;function zt(){if(Me)return ye;Me=1;var r=et(),e=xt(),n=tt();function t(i,a){return i&&i.length?r(i,n(a,2),e):void 0}return ye=t,ye}var Wt=zt();const Gt=Qe(Wt);var ge,Ve;function Ht(){if(Ve)return ge;Ve=1;var r=et(),e=tt(),n=At();function t(i,a){return i&&i.length?r(i,e(a,2),n):void 0}return ge=t,ge}var Zt=Ht();const Ut=Qe(Zt);var Xt=["cx","cy","angle","ticks","axisLine"],Qt=["ticks","tick","angle","tickFormatter","stroke"];function H(r){"@babel/helpers - typeof";return H=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(r)}function Y(){return Y=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},Y.apply(this,arguments)}function qe(r,e){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(r);e&&(t=t.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),n.push.apply(n,t)}return n}function L(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?qe(Object(n),!0).forEach(function(t){de(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):qe(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function ze(r,e){if(r==null)return{};var n=Yt(r,e),t,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(i=0;i<a.length;i++)t=a[i],!(e.indexOf(t)>=0)&&Object.prototype.propertyIsEnumerable.call(r,t)&&(n[t]=r[t])}return n}function Yt(r,e){if(r==null)return{};var n={};for(var t in r)if(Object.prototype.hasOwnProperty.call(r,t)){if(e.indexOf(t)>=0)continue;n[t]=r[t]}return n}function Jt(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function We(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,ut(t.key),t)}}function er(r,e,n){return e&&We(r.prototype,e),n&&We(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function tr(r,e,n){return e=se(e),rr(r,lt()?Reflect.construct(e,n||[],se(r).constructor):e.apply(r,n))}function rr(r,e){if(e&&(H(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return nr(r)}function nr(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function lt(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(lt=function(){return!!r})()}function se(r){return se=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},se(r)}function ir(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&xe(r,e)}function xe(r,e){return xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},xe(r,e)}function de(r,e,n){return e=ut(e),e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function ut(r){var e=ar(r,"string");return H(e)=="symbol"?e:e+""}function ar(r,e){if(H(r)!="object"||!r)return r;var n=r[Symbol.toPrimitive];if(n!==void 0){var t=n.call(r,e);if(H(t)!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}var me=(function(r){function e(){return Jt(this,e),tr(this,e,arguments)}return ir(e,r),er(e,[{key:"getTickValueCoord",value:function(t){var i=t.coordinate,a=this.props,o=a.angle,l=a.cx,c=a.cy;return S(l,c,i,o)}},{key:"getTickTextAnchor",value:function(){var t=this.props.orientation,i;switch(t){case"left":i="end";break;case"right":i="start";break;default:i="middle";break}return i}},{key:"getViewBox",value:function(){var t=this.props,i=t.cx,a=t.cy,o=t.angle,l=t.ticks,c=Gt(l,function(f){return f.coordinate||0}),s=Ut(l,function(f){return f.coordinate||0});return{cx:i,cy:a,startAngle:o,endAngle:o,innerRadius:s.coordinate||0,outerRadius:c.coordinate||0}}},{key:"renderAxisLine",value:function(){var t=this.props,i=t.cx,a=t.cy,o=t.angle,l=t.ticks,c=t.axisLine,s=ze(t,Xt),f=l.reduce(function(v,p){return[Math.min(v[0],p.coordinate),Math.max(v[1],p.coordinate)]},[1/0,-1/0]),d=S(i,a,f[0],o),y=S(i,a,f[1],o),k=L(L(L({},A(s,!1)),{},{fill:"none"},A(c,!1)),{},{x1:d.x,y1:d.y,x2:y.x,y2:y.y});return m.createElement("line",Y({className:"recharts-polar-radius-axis-line"},k))}},{key:"renderTicks",value:function(){var t=this,i=this.props,a=i.ticks,o=i.tick,l=i.angle,c=i.tickFormatter,s=i.stroke,f=ze(i,Qt),d=this.getTickTextAnchor(),y=A(f,!1),k=A(o,!1),v=a.map(function(p,g){var b=t.getTickValueCoord(p),x=L(L(L(L({textAnchor:d,transform:"rotate(".concat(90-l,", ").concat(b.x,", ").concat(b.y,")")},y),{},{stroke:"none",fill:s},k),{},{index:g},b),{},{payload:p});return m.createElement(_,Y({className:N("recharts-polar-radius-axis-tick",rt(o)),key:"tick-".concat(p.coordinate)},Pe(t.props,p,g)),e.renderTickItem(o,x,c?c(p.value,g):p.value))});return m.createElement(_,{className:"recharts-polar-radius-axis-ticks"},v)}},{key:"render",value:function(){var t=this.props,i=t.ticks,a=t.axisLine,o=t.tick;return!i||!i.length?null:m.createElement(_,{className:N("recharts-polar-radius-axis",this.props.className)},a&&this.renderAxisLine(),o&&this.renderTicks(),nt.renderCallByParent(this.props,this.getViewBox()))}}],[{key:"renderTickItem",value:function(t,i,a){var o;return m.isValidElement(t)?o=m.cloneElement(t,i):C(t)?o=t(i):o=m.createElement(Oe,Y({},i,{className:"recharts-polar-radius-axis-tick-value"}),a),o}}])})(ue.PureComponent);de(me,"displayName","PolarRadiusAxis");de(me,"axisType","radiusAxis");de(me,"defaultProps",{type:"number",radiusAxisId:0,cx:0,cy:0,angle:0,orientation:"right",stroke:"#ccc",axisLine:!0,tick:!0,tickCount:5,allowDataOverflow:!1,scale:"auto",allowDuplicatedCategory:!0});function Z(r){"@babel/helpers - typeof";return Z=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Z(r)}function D(){return D=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},D.apply(this,arguments)}function Ge(r,e){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(r);e&&(t=t.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),n.push.apply(n,t)}return n}function $(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ge(Object(n),!0).forEach(function(t){ve(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Ge(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function or(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function He(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,pt(t.key),t)}}function sr(r,e,n){return e&&He(r.prototype,e),n&&He(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function cr(r,e,n){return e=ce(e),lr(r,ft()?Reflect.construct(e,n||[],ce(r).constructor):e.apply(r,n))}function lr(r,e){if(e&&(Z(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ur(r)}function ur(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function ft(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(ft=function(){return!!r})()}function ce(r){return ce=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},ce(r)}function fr(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&Ae(r,e)}function Ae(r,e){return Ae=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},Ae(r,e)}function ve(r,e,n){return e=pt(e),e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function pt(r){var e=pr(r,"string");return Z(e)=="symbol"?e:e+""}function pr(r,e){if(Z(r)!="object"||!r)return r;var n=r[Symbol.toPrimitive];if(n!==void 0){var t=n.call(r,e);if(Z(t)!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}var dr=Math.PI/180,Ze=1e-5,he=(function(r){function e(){return or(this,e),cr(this,e,arguments)}return fr(e,r),sr(e,[{key:"getTickLineCoord",value:function(t){var i=this.props,a=i.cx,o=i.cy,l=i.radius,c=i.orientation,s=i.tickSize,f=s||8,d=S(a,o,l,t.coordinate),y=S(a,o,l+(c==="inner"?-1:1)*f,t.coordinate);return{x1:d.x,y1:d.y,x2:y.x,y2:y.y}}},{key:"getTickTextAnchor",value:function(t){var i=this.props.orientation,a=Math.cos(-t.coordinate*dr),o;return a>Ze?o=i==="outer"?"start":"end":a<-Ze?o=i==="outer"?"end":"start":o="middle",o}},{key:"renderAxisLine",value:function(){var t=this.props,i=t.cx,a=t.cy,o=t.radius,l=t.axisLine,c=t.axisLineType,s=$($({},A(this.props,!1)),{},{fill:"none"},A(l,!1));if(c==="circle")return m.createElement(kt,D({className:"recharts-polar-angle-axis-line"},s,{cx:i,cy:a,r:o}));var f=this.props.ticks,d=f.map(function(y){return S(i,a,o,y.coordinate)});return m.createElement(qt,D({className:"recharts-polar-angle-axis-line"},s,{points:d}))}},{key:"renderTicks",value:function(){var t=this,i=this.props,a=i.ticks,o=i.tick,l=i.tickLine,c=i.tickFormatter,s=i.stroke,f=A(this.props,!1),d=A(o,!1),y=$($({},f),{},{fill:"none"},A(l,!1)),k=a.map(function(v,p){var g=t.getTickLineCoord(v),b=t.getTickTextAnchor(v),x=$($($({textAnchor:b},f),{},{stroke:"none",fill:s},d),{},{index:p,payload:v,x:g.x2,y:g.y2});return m.createElement(_,D({className:N("recharts-polar-angle-axis-tick",rt(o)),key:"tick-".concat(v.coordinate)},Pe(t.props,v,p)),l&&m.createElement("line",D({className:"recharts-polar-angle-axis-tick-line"},y,g)),o&&e.renderTickItem(o,x,c?c(v.value,p):v.value))});return m.createElement(_,{className:"recharts-polar-angle-axis-ticks"},k)}},{key:"render",value:function(){var t=this.props,i=t.ticks,a=t.radius,o=t.axisLine;return a<=0||!i||!i.length?null:m.createElement(_,{className:N("recharts-polar-angle-axis",this.props.className)},o&&this.renderAxisLine(),this.renderTicks())}}],[{key:"renderTickItem",value:function(t,i,a){var o;return m.isValidElement(t)?o=m.cloneElement(t,i):C(t)?o=t(i):o=m.createElement(Oe,D({},i,{className:"recharts-polar-angle-axis-tick-value"}),a),o}}])})(ue.PureComponent);ve(he,"displayName","PolarAngleAxis");ve(he,"axisType","angleAxis");ve(he,"defaultProps",{type:"category",angleAxisId:0,scale:"auto",cx:0,cy:0,orientation:"outer",axisLine:!0,tickLine:!0,tickSize:8,tick:!0,hide:!1,allowDuplicatedCategory:!0});var ae;function U(r){"@babel/helpers - typeof";return U=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},U(r)}function q(){return q=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},q.apply(this,arguments)}function Ue(r,e){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(r);e&&(t=t.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),n.push.apply(n,t)}return n}function h(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ue(Object(n),!0).forEach(function(t){P(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Ue(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function mr(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function Xe(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,mt(t.key),t)}}function vr(r,e,n){return e&&Xe(r.prototype,e),n&&Xe(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function hr(r,e,n){return e=le(e),yr(r,dt()?Reflect.construct(e,n||[],le(r).constructor):e.apply(r,n))}function yr(r,e){if(e&&(U(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return gr(r)}function gr(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function dt(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(dt=function(){return!!r})()}function le(r){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},le(r)}function br(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&ke(r,e)}function ke(r,e){return ke=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},ke(r,e)}function P(r,e,n){return e=mt(e),e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function mt(r){var e=xr(r,"string");return U(e)=="symbol"?e:e+""}function xr(r,e){if(U(r)!="object"||!r)return r;var n=r[Symbol.toPrimitive];if(n!==void 0){var t=n.call(r,e);if(U(t)!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}var E=(function(r){function e(n){var t;return mr(this,e),t=hr(this,e,[n]),P(t,"pieRef",null),P(t,"sectorRefs",[]),P(t,"id",Tt("recharts-pie-")),P(t,"handleAnimationEnd",function(){var i=t.props.onAnimationEnd;t.setState({isAnimationFinished:!0}),C(i)&&i()}),P(t,"handleAnimationStart",function(){var i=t.props.onAnimationStart;t.setState({isAnimationFinished:!1}),C(i)&&i()}),t.state={isAnimationFinished:!n.isAnimationActive,prevIsAnimationActive:n.isAnimationActive,prevAnimationId:n.animationId,sectorToFocus:0},t}return br(e,r),vr(e,[{key:"isActiveIndex",value:function(t){var i=this.props.activeIndex;return Array.isArray(i)?i.indexOf(t)!==-1:t===i}},{key:"hasActiveIndex",value:function(){var t=this.props.activeIndex;return Array.isArray(t)?t.length!==0:t||t===0}},{key:"renderLabels",value:function(t){var i=this.props.isAnimationActive;if(i&&!this.state.isAnimationFinished)return null;var a=this.props,o=a.label,l=a.labelLine,c=a.dataKey,s=a.valueKey,f=A(this.props,!1),d=A(o,!1),y=A(l,!1),k=o&&o.offsetRadius||20,v=t.map(function(p,g){var b=(p.startAngle+p.endAngle)/2,x=S(p.cx,p.cy,p.outerRadius+k,b),j=h(h(h(h({},f),p),{},{stroke:"none"},d),{},{index:g,textAnchor:e.getTextAnchor(x.x,p.cx)},x),B=h(h(h(h({},f),p),{},{fill:"none",stroke:p.fill},y),{},{index:g,points:[S(p.cx,p.cy,p.outerRadius,b),x]}),w=c;return W(c)&&W(s)?w="value":W(c)&&(w=s),m.createElement(_,{key:"label-".concat(p.startAngle,"-").concat(p.endAngle,"-").concat(p.midAngle,"-").concat(g)},l&&e.renderLabelLineItem(l,B,"line"),e.renderLabelItem(o,j,F(p,w)))});return m.createElement(_,{className:"recharts-pie-labels"},v)}},{key:"renderSectorsStatically",value:function(t){var i=this,a=this.props,o=a.activeShape,l=a.blendStroke,c=a.inactiveShape;return t.map(function(s,f){if((s==null?void 0:s.startAngle)===0&&(s==null?void 0:s.endAngle)===0&&t.length!==1)return null;var d=i.isActiveIndex(f),y=c&&i.hasActiveIndex()?c:null,k=d?o:y,v=h(h({},s),{},{stroke:l?s.fill:s.stroke,tabIndex:-1});return m.createElement(_,q({ref:function(g){g&&!i.sectorRefs.includes(g)&&i.sectorRefs.push(g)},tabIndex:-1,className:"recharts-pie-sector"},Pe(i.props,s,f),{key:"sector-".concat(s==null?void 0:s.startAngle,"-").concat(s==null?void 0:s.endAngle,"-").concat(s.midAngle,"-").concat(f)}),m.createElement(Pt,q({option:k,isActive:d,shapeType:"sector"},v)))})}},{key:"renderSectorsWithAnimation",value:function(){var t=this,i=this.props,a=i.sectors,o=i.isAnimationActive,l=i.animationBegin,c=i.animationDuration,s=i.animationEasing,f=i.animationId,d=this.state,y=d.prevSectors,k=d.prevIsAnimationActive;return m.createElement(jt,{begin:l,duration:c,isActive:o,easing:s,from:{t:0},to:{t:1},key:"pie-".concat(f,"-").concat(k),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(v){var p=v.t,g=[],b=a&&a[0],x=b.startAngle;return a.forEach(function(j,B){var w=y&&y[B],I=B>0?_t(j,"paddingAngle",0):0;if(w){var X=De(w.endAngle-w.startAngle,j.endAngle-j.startAngle),O=h(h({},j),{},{startAngle:x+I,endAngle:x+X(p)+I});g.push(O),x=O.endAngle}else{var K=j.endAngle,T=j.startAngle,ee=De(0,K-T),te=ee(p),R=h(h({},j),{},{startAngle:x+I,endAngle:x+te+I});g.push(R),x=R.endAngle}}),m.createElement(_,null,t.renderSectorsStatically(g))})}},{key:"attachKeyboardHandlers",value:function(t){var i=this;t.onkeydown=function(a){if(!a.altKey)switch(a.key){case"ArrowLeft":{var o=++i.state.sectorToFocus%i.sectorRefs.length;i.sectorRefs[o].focus(),i.setState({sectorToFocus:o});break}case"ArrowRight":{var l=--i.state.sectorToFocus<0?i.sectorRefs.length-1:i.state.sectorToFocus%i.sectorRefs.length;i.sectorRefs[l].focus(),i.setState({sectorToFocus:l});break}case"Escape":{i.sectorRefs[i.state.sectorToFocus].blur(),i.setState({sectorToFocus:0});break}}}}},{key:"renderSectors",value:function(){var t=this.props,i=t.sectors,a=t.isAnimationActive,o=this.state.prevSectors;return a&&i&&i.length&&(!o||!wt(o,i))?this.renderSectorsWithAnimation():this.renderSectorsStatically(i)}},{key:"componentDidMount",value:function(){this.pieRef&&this.attachKeyboardHandlers(this.pieRef)}},{key:"render",value:function(){var t=this,i=this.props,a=i.hide,o=i.sectors,l=i.className,c=i.label,s=i.cx,f=i.cy,d=i.innerRadius,y=i.outerRadius,k=i.isAnimationActive,v=this.state.isAnimationFinished;if(a||!o||!o.length||!M(s)||!M(f)||!M(d)||!M(y))return null;var p=N("recharts-pie",l);return m.createElement(_,{tabIndex:this.props.rootTabIndex,className:p,ref:function(b){t.pieRef=b}},this.renderSectors(),c&&this.renderLabels(o),nt.renderCallByParent(this.props,null,!1),(!k||v)&&je.renderCallByParent(this.props,o,!1))}}],[{key:"getDerivedStateFromProps",value:function(t,i){return i.prevIsAnimationActive!==t.isAnimationActive?{prevIsAnimationActive:t.isAnimationActive,prevAnimationId:t.animationId,curSectors:t.sectors,prevSectors:[],isAnimationFinished:!0}:t.isAnimationActive&&t.animationId!==i.prevAnimationId?{prevAnimationId:t.animationId,curSectors:t.sectors,prevSectors:i.curSectors,isAnimationFinished:!0}:t.sectors!==i.curSectors?{curSectors:t.sectors,isAnimationFinished:!0}:null}},{key:"getTextAnchor",value:function(t,i){return t>i?"start":t<i?"end":"middle"}},{key:"renderLabelLineItem",value:function(t,i,a){if(m.isValidElement(t))return m.cloneElement(t,i);if(C(t))return t(i);var o=N("recharts-pie-label-line",typeof t!="boolean"?t.className:"");return m.createElement(Ot,q({},i,{key:a,type:"linear",className:o}))}},{key:"renderLabelItem",value:function(t,i,a){if(m.isValidElement(t))return m.cloneElement(t,i);var o=a;if(C(t)&&(o=t(i),m.isValidElement(o)))return o;var l=N("recharts-pie-label-text",typeof t!="boolean"&&!C(t)?t.className:"");return m.createElement(Oe,q({},i,{alignmentBaseline:"middle",className:l}),o)}}])})(ue.PureComponent);ae=E;P(E,"displayName","Pie");P(E,"defaultProps",{stroke:"#fff",fill:"#808080",legendType:"rect",cx:"50%",cy:"50%",startAngle:0,endAngle:360,innerRadius:0,outerRadius:"80%",paddingAngle:0,labelLine:!0,hide:!1,minAngle:0,isAnimationActive:!St.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0});P(E,"parseDeltaAngle",function(r,e){var n=ie(e-r),t=Math.min(Math.abs(e-r),360);return n*t});P(E,"getRealPieData",function(r){var e=r.data,n=r.children,t=A(r,!1),i=Et(n,_e);return e&&e.length?e.map(function(a,o){return h(h(h({payload:a},t),a),i&&i[o]&&i[o].props)}):i&&i.length?i.map(function(a){return h(h({},t),a.props)}):[]});P(E,"parseCoordinateOfPie",function(r,e){var n=e.top,t=e.left,i=e.width,a=e.height,o=Rt(i,a),l=t+ne(r.cx,i,i/2),c=n+ne(r.cy,a,a/2),s=ne(r.innerRadius,o,0),f=ne(r.outerRadius,o,o*.8),d=r.maxRadius||Math.sqrt(i*i+a*a)/2;return{cx:l,cy:c,innerRadius:s,outerRadius:f,maxRadius:d}});P(E,"getComposedData",function(r){var e=r.item,n=r.offset,t=e.type.defaultProps!==void 0?h(h({},e.type.defaultProps),e.props):e.props,i=ae.getRealPieData(t);if(!i||!i.length)return null;var a=t.cornerRadius,o=t.startAngle,l=t.endAngle,c=t.paddingAngle,s=t.dataKey,f=t.nameKey,d=t.valueKey,y=t.tooltipType,k=Math.abs(t.minAngle),v=ae.parseCoordinateOfPie(t,n),p=ae.parseDeltaAngle(o,l),g=Math.abs(p),b=s;W(s)&&W(d)?(Be(!1,`Use "dataKey" to specify the value of pie,
|
|
3
|
+
the props "valueKey" will be deprecated in 1.1.0`),b="value"):W(s)&&(Be(!1,`Use "dataKey" to specify the value of pie,
|
|
4
|
+
the props "valueKey" will be deprecated in 1.1.0`),b=d);var x=i.filter(function(O){return F(O,b,0)!==0}).length,j=(g>=360?x:x-1)*c,B=g-x*k-j,w=i.reduce(function(O,K){var T=F(K,b,0);return O+(M(T)?T:0)},0),I;if(w>0){var X;I=i.map(function(O,K){var T=F(O,b,0),ee=F(O,f,K),te=(M(T)?T:0)/w,R;K?R=X.endAngle+ie(p)*c*(T!==0?1:0):R=o;var Le=R+ie(p)*((T!==0?k:0)+te*B),$e=(R+Le)/2,Ce=(v.innerRadius+v.outerRadius)/2,gt=[{name:ee,value:T,payload:O,dataKey:b,type:y}],bt=S(v.cx,v.cy,Ce,$e);return X=h(h(h({percent:te,cornerRadius:a,name:ee,tooltipPayload:gt,midAngle:$e,middleRadius:Ce,tooltipPosition:bt},O),v),{},{value:F(O,b),startAngle:R,endAngle:Le,payload:O,paddingAngle:ie(p)*c}),X})}return h(h({},v),{},{sectors:I,data:i})});var vt=it({chartName:"BarChart",GraphicalChild:we,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:Te},{axisType:"yAxis",AxisComp:Se}],formatAxisMap:Nt}),Ar=it({chartName:"PieChart",GraphicalChild:E,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:he},{axisType:"radiusAxis",AxisComp:me}],formatAxisMap:It,defaultProps:{layout:"centric",startAngle:0,endAngle:360,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"}});const ht={fill:"var(--color-bg-2)"},yt={fill:"var(--color-fg-dim)",fontSize:10,fontFamily:"var(--font-mono)"},kr=Ie(r=>{var e,n;return[{label:"cost",value:G(((e=r[0])==null?void 0:e.value)??0),color:(n=r[0])==null?void 0:n.color}]},{title:r=>J(r)}),Or=Ie(r=>{var e,n;return[{label:"tokens",value:z(((e=r[0])==null?void 0:e.value)??0),color:(n=r[0])==null?void 0:n.color}]},{title:r=>J(r)}),Pr=Ie(r=>{var e,n;return[{label:"saved",value:G(((e=r[0])==null?void 0:e.value)??0),color:(n=r[0])==null?void 0:n.color}]},{title:r=>J(r)});function wr({derived:r,height:e=280,limit:n=10,metric:t="cost",periodLabel:i}){const a=Ee(),o=at("(min-width: 768px)"),l=o?124:92,c=o?60:44,s=t==="tokens",f=[...r.byModel].sort((d,y)=>s?y.tokens-d.tokens:y.cost-d.cost).slice(0,n);return u.jsx(fe,{title:s?"tokens by model":"cost by model",titleTag:i,captureName:s?"tokens-by-model":"cost-by-model",children:f.length===0?u.jsx(pe,{children:"no models in period"}):u.jsx(Re,{height:e,children:u.jsx(Ne,{children:u.jsxs(vt,{data:f,layout:"vertical",margin:{top:4,right:c,left:4,bottom:0},children:[u.jsx(ot,{...st,horizontal:!1,vertical:!0}),u.jsx(Te,{type:"number",...oe,tickFormatter:s?z:Ye}),u.jsx(Se,{type:"category",dataKey:"model",...oe,width:l,tickFormatter:J}),u.jsx(ct,{content:s?Or:kr,cursor:ht}),u.jsxs(we,{dataKey:s?"tokens":"cost",radius:[0,3,3,0],isAnimationActive:a,animationDuration:350,children:[f.map(d=>u.jsx(_e,{fill:d.color},d.model)),u.jsx(je,{dataKey:s?"tokens":"cost",position:"right",offset:6,...yt,formatter:d=>s?z(d):G(d)})]})]})})})})}function Tr({derived:r,height:e=240,limit:n=12,periodLabel:t}){const i=Ee(),a=at("(min-width: 768px)"),o=a?124:92,l=a?60:44,c=[...r.byModel].filter(s=>s.cacheSavings>0).sort((s,f)=>f.cacheSavings-s.cacheSavings).slice(0,n);return u.jsx(fe,{title:"cache savings by model",titleTag:t,captureName:"cache-savings-by-model",children:c.length===0?u.jsx(pe,{children:"no cache savings in period"}):u.jsx(Re,{height:e,children:u.jsx(Ne,{children:u.jsxs(vt,{data:c,layout:"vertical",margin:{top:4,right:l,left:4,bottom:0},children:[u.jsx(ot,{...st,horizontal:!1,vertical:!0}),u.jsx(Te,{type:"number",...oe,tickFormatter:Ye}),u.jsx(Se,{type:"category",dataKey:"model",...oe,width:o,tickFormatter:J}),u.jsx(ct,{content:Pr,cursor:ht}),u.jsx(we,{dataKey:"cacheSavings",radius:[0,3,3,0],fill:"var(--color-positive)",isAnimationActive:i,animationDuration:350,children:u.jsx(je,{dataKey:"cacheSavings",position:"right",offset:6,...yt,formatter:s=>G(s)})})]})})})})}function Sr({derived:r,height:e=280,periodLabel:n}){const t=Ee(),i=r.byProvider,a=r.totals.cost,[o,l]=ue.useState(null),c=o!=null?i[o]:null,s=c&&a>0?c.cost/a:0;return u.jsx(fe,{title:"provider split",titleTag:n,captureName:"provider-split",children:i.length===0?u.jsx(pe,{children:"no spend in period"}):u.jsxs("div",{className:"relative",onMouseLeave:()=>l(null),children:[u.jsx(Re,{height:e,children:u.jsx(Ne,{children:u.jsx(Ar,{children:u.jsx(E,{data:i,dataKey:"cost",nameKey:"name",innerRadius:"60%",outerRadius:"88%",paddingAngle:i.length>1?2:0,stroke:"var(--color-bg-1)",strokeWidth:2,isAnimationActive:t,animationDuration:350,onMouseEnter:(f,d)=>l(d),children:i.map((f,d)=>u.jsx(_e,{fill:f.color,"aria-label":`${f.name}: ${G(f.cost)}`,fillOpacity:o==null||o===d?1:.32,style:{transition:"fill-opacity 150ms ease"}},f.id))})})})}),u.jsxs("div",{className:"pointer-events-none absolute inset-0 flex flex-col items-center justify-center",children:[u.jsx("div",{className:"tnum text-xl",style:{color:c?c.color:"var(--color-fg-bright)"},children:G(c?c.cost:a)}),u.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:c?`${c.name} · ${Je(s,s>0&&s<.01?1:0)}`:"total"})]})]})})}function Er({derived:r,periodLabel:e}){const n=r.tokenComposition,t=n.input+n.output+n.cacheCreate+n.cacheRead,i=[{key:"cacheRead",label:"cache read",value:n.cacheRead,color:re.cacheRead},{key:"input",label:"input",value:n.input,color:re.input},{key:"output",label:"output",value:n.output,color:re.output},{key:"cacheCreate",label:"cache write",value:n.cacheCreate,color:re.cacheCreate}];return u.jsx(fe,{title:"token composition",titleTag:e,captureName:"token-composition",right:u.jsx("span",{className:"tnum text-xs text-fg-dim",children:z(t)}),children:t===0?u.jsx(pe,{children:"no tokens in period"}):u.jsxs("div",{className:"flex flex-col gap-4 pt-1",children:[u.jsx("div",{className:"flex h-3 w-full overflow-hidden rounded-full bg-bg-3",children:i.map(a=>a.value>0&&u.jsx("div",{style:{width:`${a.value/t*100}%`,minWidth:"2px",background:a.color},title:`${a.label}: ${z(a.value)}`},a.key))}),u.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-2.5",children:i.map(a=>{const o=t>0?a.value/t:0;return u.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[u.jsxs("span",{className:"flex items-center gap-1.5 text-fg-dim",children:[u.jsx("span",{className:"inline-block size-2 rounded-[2px]",style:{background:a.color}}),a.label]}),u.jsxs("span",{className:"text-fg",children:[u.jsx("span",{className:"tnum text-fg-bright",children:z(a.value)}),u.jsx("span",{className:"ml-1.5 text-fg-faint",children:Je(o,o>0&&o<.01?1:0)})]})]},a.key)})})]})})}export{Tr as CacheByModel,wr as CostByModel,Sr as ProviderDonut,Er as TokenComposition};
|