tokmon 0.28.1 → 0.28.3

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.
Files changed (57) hide show
  1. package/README.md +156 -234
  2. package/THIRD_PARTY_NOTICES.md +62 -0
  3. package/dist/{bootstrap-ink-L7QSJBMS.js → bootstrap-ink-WG4WG3R2.js} +1579 -1135
  4. package/dist/chunk-7CH6S7BR.js +447 -0
  5. package/dist/{chunk-CVKCVHS7.js → chunk-CFKUZCMB.js} +70 -310
  6. package/dist/chunk-HNWEJ6MS.js +1094 -0
  7. package/dist/chunk-JZSZEHVD.js +406 -0
  8. package/dist/{chunk-S33XIUAW.js → chunk-P57DVFNH.js} +277 -49
  9. package/dist/{chunk-4HU4EI5T.js → chunk-P5JN5DDX.js} +25 -46
  10. package/dist/chunk-TN6V7XSL.js +512 -0
  11. package/dist/chunk-USKOQIE3.js +278 -0
  12. package/dist/chunk-UYPDMVW5.js +21 -0
  13. package/dist/{cli-command-75LP4IDS.js → cli-command-MD3RJRP4.js} +249 -15
  14. package/dist/cli.js +6 -6
  15. package/dist/{config-HXFJTNLM.js → config-3DGZ47F7.js} +23 -3
  16. package/dist/daemon-EMOA36WB.js +377 -0
  17. package/dist/daemon-handle-JHE5MKMI.js +11 -0
  18. package/dist/server-EPSH52DR.js +12 -0
  19. package/dist/web/assets/{Area-CMXvOw33.js → Area-stRnp8Km.js} +1 -1
  20. package/dist/web/assets/analytics-moZZt9L_.js +2 -0
  21. package/dist/web/assets/breakdown-km9w7myU.js +4 -0
  22. package/dist/web/assets/button-DrX04Cc2.js +1 -0
  23. package/dist/web/assets/{chart-cZoLgpmG.js → chart-D0CtuL2k.js} +1 -1
  24. package/dist/web/assets/explore-B11uNJV1.js +22 -0
  25. package/dist/web/assets/index-RDhXsCNG.js +83 -0
  26. package/dist/web/assets/index-ZmOS8p9O.css +1 -0
  27. package/dist/web/assets/models-DYbZnY34.js +2 -0
  28. package/dist/web/assets/overview-CruICbfJ.js +2 -0
  29. package/dist/web/assets/panel-xckM3_GC.js +1 -0
  30. package/dist/web/assets/settings-sheet-G-BTSIF6.js +1 -0
  31. package/dist/web/assets/share-sheet-weIdd4DW.js +2 -0
  32. package/dist/web/assets/timeline-BHgniliZ.js +1 -0
  33. package/dist/web/index.html +30 -4
  34. package/package.json +13 -4
  35. package/site/THIRD_PARTY_NOTICES.md +83 -0
  36. package/site/public/fonts/OFL.txt +93 -0
  37. package/dist/chunk-3RTWFGGD.js +0 -275
  38. package/dist/chunk-FMP3P2WV.js +0 -299
  39. package/dist/chunk-HP5UZCXP.js +0 -436
  40. package/dist/chunk-SMPY52EV.js +0 -125
  41. package/dist/chunk-XDA5RJST.js +0 -193
  42. package/dist/daemon-CL4FJW26.js +0 -219
  43. package/dist/daemon-handle-QQLJE46Y.js +0 -10
  44. package/dist/server-EUO7CWYH.js +0 -11
  45. package/dist/web/assets/analytics-DqdZXOJL.js +0 -2
  46. package/dist/web/assets/breakdown-kOSSJ3mI.js +0 -4
  47. package/dist/web/assets/explore-vcsM8K9I.js +0 -22
  48. package/dist/web/assets/index-BErCXT7f.css +0 -1
  49. package/dist/web/assets/index-DH3dOnbg.js +0 -83
  50. package/dist/web/assets/models-B5ikm83_.js +0 -2
  51. package/dist/web/assets/overview-DD1kP8CP.js +0 -2
  52. package/dist/web/assets/panel-DTQBwExW.js +0 -1
  53. package/dist/web/assets/primitives-C36qJlA2.js +0 -1
  54. package/dist/web/assets/settings-sheet-_i2zTQjf.js +0 -1
  55. package/dist/web/assets/share-sheet-BLHmrFbm.js +0 -2
  56. package/dist/web/assets/timeline-B4uG-Emo.js +0 -1
  57. package/dist/web/assets/use-dialog-trap-bfaXEMz9.js +0 -1
@@ -1,193 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- cacheDir
4
- } from "./chunk-HP5UZCXP.js";
5
-
6
- // src/web/lockfile.ts
7
- import { closeSync, fchmodSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "fs";
8
- import { isAbsolute, join } from "path";
9
- function lockDir(opts = {}) {
10
- const injected = opts.cachePath ?? process.env.TOKMON_DAEMON_CACHE_DIR;
11
- return injected && isAbsolute(injected) ? injected : cacheDir();
12
- }
13
- function lockfilePath(opts = {}) {
14
- return join(lockDir(opts), "daemon.json");
15
- }
16
- function isLoopbackUrl(value) {
17
- try {
18
- const url = new URL(value);
19
- return url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "::1");
20
- } catch {
21
- return false;
22
- }
23
- }
24
- function validLock(value) {
25
- const lock = value;
26
- return !!lock && typeof lock.pid === "number" && Number.isInteger(lock.pid) && lock.pid > 0 && typeof lock.port === "number" && Number.isInteger(lock.port) && lock.port >= 0 && lock.port <= 65535 && typeof lock.url === "string" && (lock.state === "starting" || isLoopbackUrl(lock.url)) && typeof lock.wsToken === "string" && lock.wsToken.length >= 32 && typeof lock.version === "string" && typeof lock.startedAt === "number" && typeof lock.ownerId === "string" && lock.ownerId.length >= 32 && (lock.state === "starting" || lock.state === "ready");
27
- }
28
- function readLock(opts = {}) {
29
- try {
30
- const path = lockfilePath(opts);
31
- const stat = statSync(path);
32
- if (!stat.isFile() || (stat.mode & 63) !== 0) return null;
33
- const parsed = JSON.parse(readFileSync(path, "utf-8"));
34
- return validLock(parsed) ? parsed : null;
35
- } catch {
36
- return null;
37
- }
38
- }
39
- function ensureLockDir(opts) {
40
- const dir = lockDir(opts);
41
- mkdirSync(dir, { recursive: true, mode: 448 });
42
- let fd;
43
- try {
44
- fd = openSync(dir, "r");
45
- fchmodSync(fd, 448);
46
- } catch {
47
- } finally {
48
- if (fd !== void 0) try {
49
- closeSync(fd);
50
- } catch {
51
- }
52
- }
53
- }
54
- function writeNew(path, lock) {
55
- let fd;
56
- let created = false;
57
- try {
58
- fd = openSync(path, "wx", 384);
59
- created = true;
60
- fchmodSync(fd, 384);
61
- writeFileSync(fd, JSON.stringify(lock));
62
- fsyncSync(fd);
63
- return true;
64
- } catch {
65
- if (created) try {
66
- unlinkSync(path);
67
- } catch {
68
- }
69
- return false;
70
- } finally {
71
- if (fd !== void 0) try {
72
- closeSync(fd);
73
- } catch {
74
- }
75
- }
76
- }
77
- function acquireLock(lock, opts = {}) {
78
- try {
79
- ensureLockDir(opts);
80
- return writeNew(lockfilePath(opts), lock);
81
- } catch {
82
- return false;
83
- }
84
- }
85
- function writeLock(lock, opts = {}) {
86
- const current = readLock(opts);
87
- if (!current || current.ownerId !== lock.ownerId || current.pid !== process.pid) return false;
88
- const path = lockfilePath(opts);
89
- const tmp = join(lockDir(opts), `daemon.json.${process.pid}.${lock.ownerId}.tmp`);
90
- let fd;
91
- try {
92
- writeFileSync(tmp, JSON.stringify(lock), { mode: 384 });
93
- try {
94
- fd = openSync(tmp, "r");
95
- fchmodSync(fd, 384);
96
- fsyncSync(fd);
97
- } catch {
98
- }
99
- renameSync(tmp, path);
100
- return true;
101
- } catch {
102
- try {
103
- unlinkSync(tmp);
104
- } catch {
105
- }
106
- return false;
107
- } finally {
108
- if (fd !== void 0) try {
109
- closeSync(fd);
110
- } catch {
111
- }
112
- }
113
- }
114
- function unlinkLock(ownerId, opts = {}) {
115
- const current = readLock(opts);
116
- if (!current || current.ownerId !== ownerId || current.pid !== process.pid) return false;
117
- try {
118
- unlinkSync(lockfilePath(opts));
119
- return true;
120
- } catch {
121
- return false;
122
- }
123
- }
124
- function reclaimDeadLock(opts = {}) {
125
- const current = readLock(opts);
126
- if (!current || isAlive(current.pid)) return false;
127
- try {
128
- unlinkSync(lockfilePath(opts));
129
- return true;
130
- } catch {
131
- return false;
132
- }
133
- }
134
- function reclaimAbandonedLock(opts = {}, graceMs = 1e4) {
135
- const path = lockfilePath(opts);
136
- try {
137
- const before = lstatSync(path);
138
- if (!before.isFile()) return false;
139
- let pid = null;
140
- try {
141
- const parsed = JSON.parse(readFileSync(path, "utf-8"));
142
- if (Number.isInteger(parsed.pid) && parsed.pid > 0) pid = parsed.pid;
143
- } catch {
144
- }
145
- if (pid !== null && isAlive(pid)) return false;
146
- if (pid === null && Date.now() - before.mtimeMs < graceMs) return false;
147
- const after = lstatSync(path);
148
- if (after.dev !== before.dev || after.ino !== before.ino) return false;
149
- unlinkSync(path);
150
- return true;
151
- } catch {
152
- return false;
153
- }
154
- }
155
- function isAlive(pid) {
156
- if (!Number.isInteger(pid) || pid <= 0) return false;
157
- try {
158
- process.kill(pid, 0);
159
- return true;
160
- } catch (err) {
161
- return err.code === "EPERM";
162
- }
163
- }
164
- async function probeHealth(url, token, version, timeoutMs = 500) {
165
- if (!isLoopbackUrl(url) || !token) return false;
166
- try {
167
- const res = await fetch(`${url.replace(/\/+$/, "")}/healthz`, {
168
- headers: { "x-tokmon-token": token },
169
- signal: AbortSignal.timeout(timeoutMs)
170
- });
171
- if (!res.ok) return false;
172
- const body = await res.json();
173
- return body.ok === true && body.owner === true && (version === void 0 || body.version === version);
174
- } catch {
175
- return false;
176
- }
177
- }
178
- async function verifyLock(lock, version, timeoutMs) {
179
- if (!lock || lock.state !== "ready" || lock.version !== version || !isAlive(lock.pid)) return null;
180
- return await probeHealth(lock.url, lock.wsToken, version, timeoutMs) ? lock : null;
181
- }
182
-
183
- export {
184
- readLock,
185
- acquireLock,
186
- writeLock,
187
- unlinkLock,
188
- reclaimDeadLock,
189
- reclaimAbandonedLock,
190
- isAlive,
191
- probeHealth,
192
- verifyLock
193
- };
@@ -1,219 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- acquireLock,
4
- isAlive,
5
- readLock,
6
- reclaimAbandonedLock,
7
- reclaimDeadLock,
8
- unlinkLock,
9
- verifyLock,
10
- writeLock
11
- } from "./chunk-XDA5RJST.js";
12
- import {
13
- startWebServer
14
- } from "./chunk-S33XIUAW.js";
15
- import {
16
- appVersion
17
- } from "./chunk-SMPY52EV.js";
18
- import "./chunk-FMP3P2WV.js";
19
- import {
20
- flushDisk
21
- } from "./chunk-CVKCVHS7.js";
22
- import {
23
- loadConfig
24
- } from "./chunk-HP5UZCXP.js";
25
-
26
- // src/web/daemon.ts
27
- import { randomBytes } from "crypto";
28
-
29
- // src/web/open.ts
30
- import { spawn } from "child_process";
31
- import { appendFileSync } from "fs";
32
- function openBrowser(url) {
33
- const target = url;
34
- if (process.env.TOKMON_OPENLOG) {
35
- try {
36
- appendFileSync(process.env.TOKMON_OPENLOG, target + "\n");
37
- } catch {
38
- }
39
- return;
40
- }
41
- try {
42
- if (process.platform === "darwin") {
43
- spawn("open", [target], { stdio: "ignore", detached: true }).unref();
44
- } else if (process.platform === "win32") {
45
- spawn("cmd", ["/c", "start", "", target], { stdio: "ignore", detached: true }).unref();
46
- } else {
47
- spawn("xdg-open", [target], { stdio: "ignore", detached: true }).unref();
48
- }
49
- } catch {
50
- }
51
- }
52
-
53
- // src/web/daemon.ts
54
- function parseDaemonArgs(args) {
55
- let port;
56
- let open = true;
57
- let help = false;
58
- for (let i = 0; i < args.length; i++) {
59
- const arg = args[i];
60
- if ((arg === "--port" || arg === "-p") && args[i + 1]) port = Number(args[++i]);
61
- else if (arg.startsWith("--port=")) port = Number(arg.slice("--port=".length));
62
- else if (arg === "--no-open") open = false;
63
- else if (arg === "--help" || arg === "-h") help = true;
64
- }
65
- if (port !== void 0 && (!Number.isInteger(port) || port < 0 || port > 65535)) port = void 0;
66
- return { port, open, help };
67
- }
68
- var SERVE_HELP = `tokmon serve - Launch the tokmon web dashboard
69
-
70
- Usage: tokmon serve [options]
71
-
72
- Options:
73
- -p, --port <n> Port to listen on (default: 4317, auto-falls back if taken)
74
- --no-open Don't open the browser automatically
75
- -h, --help Show this help
76
- `;
77
- function handshake(lock) {
78
- process.stdout.write(JSON.stringify({ ready: 1, url: lock.url, port: lock.port, wsToken: lock.wsToken, version: lock.version }) + "\n");
79
- }
80
- function describeExisting(lock, open) {
81
- process.stdout.write(`
82
- \u25C6 tokmon web \u2192 ${lock.url}
83
- `);
84
- process.stdout.write(" reusing the live singleton daemon\n\n");
85
- if (open) {
86
- openBrowser(lock.url);
87
- process.stdout.write(" opening browser\u2026\n");
88
- }
89
- }
90
- async function runDaemon(args, opts) {
91
- const { port, open, help } = parseDaemonArgs(args);
92
- if (help && opts.foreground) {
93
- process.stdout.write(SERVE_HELP);
94
- return;
95
- }
96
- const version = appVersion();
97
- let current = readLock();
98
- if (!current && reclaimAbandonedLock()) current = readLock();
99
- const live = await verifyLock(current, version);
100
- if (live) {
101
- if (opts.foreground) describeExisting(live, open);
102
- else handshake(live);
103
- return;
104
- }
105
- if (current?.state === "starting" && current.version === version && isAlive(current.pid)) {
106
- for (let attempt = 0; attempt < 60; attempt++) {
107
- await new Promise((resolve) => setTimeout(resolve, 50));
108
- const winner = await verifyLock(readLock(), version, 250);
109
- if (winner) {
110
- if (opts.foreground) describeExisting(winner, open);
111
- else handshake(winner);
112
- return;
113
- }
114
- }
115
- }
116
- if (current && isAlive(current.pid)) {
117
- const message = "tokmon: another daemon owns the lock but could not be verified (version/token mismatch)";
118
- if (opts.foreground) {
119
- process.stderr.write(message + "\n");
120
- process.exitCode = 1;
121
- }
122
- return;
123
- }
124
- if (current) reclaimDeadLock();
125
- const ownerId = randomBytes(32).toString("base64url");
126
- const token = randomBytes(32).toString("base64url");
127
- const reservation = {
128
- pid: process.pid,
129
- port: 0,
130
- url: "",
131
- wsToken: token,
132
- version,
133
- startedAt: Date.now(),
134
- ownerId,
135
- state: "starting"
136
- };
137
- if (!acquireLock(reservation)) {
138
- for (let attempt = 0; attempt < 60; attempt++) {
139
- await new Promise((resolve) => setTimeout(resolve, 50));
140
- const winner = await verifyLock(readLock(), version, 250);
141
- if (winner) {
142
- if (opts.foreground) describeExisting(winner, open);
143
- else handshake(winner);
144
- return;
145
- }
146
- }
147
- if (opts.foreground) {
148
- process.stderr.write("tokmon: daemon startup is already in progress\n");
149
- process.exitCode = 1;
150
- }
151
- return;
152
- }
153
- let controller = null;
154
- try {
155
- const config = await loadConfig();
156
- controller = await startWebServer({ config, port, log: opts.foreground, wsToken: token });
157
- const ready = {
158
- ...reservation,
159
- port: controller.port,
160
- url: controller.url,
161
- state: "ready"
162
- };
163
- if (!writeLock(ready)) throw new Error("lost daemon lock ownership during startup");
164
- let shuttingDown = false;
165
- const shutdown = async (exitCode = 0) => {
166
- if (shuttingDown) return;
167
- shuttingDown = true;
168
- if (opts.foreground) process.stdout.write("\n stopping tokmon web\u2026\n");
169
- try {
170
- await controller?.stop();
171
- } catch {
172
- }
173
- await flushDisk().catch(() => {
174
- });
175
- unlinkLock(ownerId);
176
- process.exit(exitCode);
177
- };
178
- process.once("exit", () => {
179
- unlinkLock(ownerId);
180
- });
181
- process.once("SIGINT", () => {
182
- void shutdown(0);
183
- });
184
- process.once("SIGTERM", () => {
185
- void shutdown(0);
186
- });
187
- if (opts.foreground) {
188
- process.stdout.write(`
189
- \u25C6 tokmon web \u2192 ${controller.url}
190
- `);
191
- process.stdout.write(" live dashboard \xB7 Ctrl-C to stop\n\n");
192
- if (config.allowNetworkAccess) {
193
- process.stdout.write(" \u26A0 unsafe network access enabled \u2014 dashboard is reachable from your LAN\n\n");
194
- }
195
- if (open) {
196
- openBrowser(controller.url);
197
- process.stdout.write(" opening browser\u2026\n");
198
- }
199
- } else {
200
- handshake(ready);
201
- }
202
- await new Promise(() => {
203
- });
204
- } catch (error) {
205
- try {
206
- await controller?.stop();
207
- } catch {
208
- }
209
- unlinkLock(ownerId);
210
- const message = `tokmon: failed to start web server: ${error.message}`;
211
- if (opts.foreground) {
212
- process.stderr.write(message + "\n");
213
- process.exitCode = 1;
214
- }
215
- }
216
- }
217
- export {
218
- runDaemon
219
- };
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- attachOrSpawn
4
- } from "./chunk-4HU4EI5T.js";
5
- import "./chunk-XDA5RJST.js";
6
- import "./chunk-SMPY52EV.js";
7
- import "./chunk-HP5UZCXP.js";
8
- export {
9
- attachOrSpawn
10
- };
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- startWebServer
4
- } from "./chunk-S33XIUAW.js";
5
- import "./chunk-SMPY52EV.js";
6
- import "./chunk-FMP3P2WV.js";
7
- import "./chunk-CVKCVHS7.js";
8
- import "./chunk-HP5UZCXP.js";
9
- export {
10
- startWebServer
11
- };
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./breakdown-kOSSJ3mI.js","./index-DH3dOnbg.js","./index-BErCXT7f.css","./chart-cZoLgpmG.js","./panel-DTQBwExW.js","./primitives-C36qJlA2.js","./timeline-B4uG-Emo.js","./Area-CMXvOw33.js"])))=>i.map(i=>d[i]);
2
- import{h as D,i as j,k as A,D as k,M as z,r as x,j as e,e as T,f as C,a as E,b as I,m as $,s as B,_ as M}from"./index-DH3dOnbg.js";import{P as F}from"./panel-DTQBwExW.js";import{a as w}from"./primitives-C36qJlA2.js";const R=[0,.32,.55,.78,1],S=t=>t===0?"var(--color-bg-2)":`color-mix(in oklab, var(--color-cost) ${R[t]*100}%, var(--color-bg-2))`,L=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function O(t,n){const i=t,c=i.filter(l=>n(l)>0);if(c.length===0)return null;const h=i.reduce((l,a)=>l+n(a),0),d=c.reduce((l,a)=>n(a)>n(l)?a:l),p=new Array(7).fill(0);for(const l of i)p[D(j(l.date))]+=n(l);const m=p.indexOf(Math.max(...p)),f=new Set(c.map(l=>l.date));let v=0;for(let l=j(c[c.length-1].date);f.has(A(l));l-=k)v++;return{active:c.length,total:h,top:d,avg:h/c.length,busiest:m,streak:v,costed:t.some(l=>l.cost>0)}}function V(t,n,i){const c=new Map(t.map(s=>[s.date,i(s)]));if(t.length===0)return null;const h=t[t.length-1].date,d=t[0].date;let p=j(h),m=j(d);(p-m)/(k*7)>n&&(m=p-n*7*k),m-=D(m)*k;const f=Math.max(...t.map(i),0),v=s=>{if(s<=0||f<=0)return 0;const r=s/f;return r>.66?4:r>.4?3:r>.15?2:1},l=[];let a=new Array(7).fill(null);const u=[];let b=-1,N=0;for(let s=m;s<=p;s+=k){const r=A(s),o=D(s);o===0&&a.some(Boolean)&&(l.push(a),a=new Array(7).fill(null),N++);const g=new Date(s).getUTCMonth();g!==b&&o===0&&(u.push({col:N,text:z[g]}),b=g);const y=s>=j(d);a[o]=y?{date:r,cost:c.get(r)??0,level:v(c.get(r)??0)}:null}return a.some(Boolean)&&l.push(a),{weeks:l,monthLabels:u}}function H({derived:t,maxWeeks:n=26,periodLabel:i}){const[c,h]=x.useState(null),[d,p]=x.useState(null),m=c??d,f=x.useMemo(()=>new Map(t.calendar.map(s=>[s.date,s])),[t.calendar]),v=x.useMemo(()=>t.calendar.some(s=>s.cost>0),[t.calendar]),l=s=>v?s.cost:s.tokens,a=x.useMemo(()=>O(t.calendar,l),[t,v]),u=x.useMemo(()=>V(t.calendar,n,l),[t,n]),b=u?`repeat(${u.weeks.length}, minmax(0,1fr))`:void 0,N=u?u.weeks.length*25:void 0;return e.jsx(e.Fragment,{children:e.jsx(F,{title:"daily spend",titleTag:i,captureName:"calendar",children:!u||!a?e.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no usage yet"}):e.jsxs("div",{className:"grid gap-x-8 gap-y-5 pt-1 md:grid-cols-[minmax(0,1fr)_210px] md:items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[e.jsx("div",{className:"pl-6",children:e.jsx("div",{className:"grid gap-[3px] text-[9px] text-fg-faint",style:{gridTemplateColumns:b,maxWidth:N},children:u.weeks.map((s,r)=>{const o=u.monthLabels.find(g=>g.col===r);return e.jsx("div",{className:"truncate",children:(o==null?void 0:o.text)??""},r)})})}),e.jsxs("div",{className:"flex gap-[3px]",children:[e.jsx("div",{className:"flex w-5 shrink-0 flex-col gap-[3px] text-[9px] text-fg-faint",children:["M","","W","","F","",""].map((s,r)=>e.jsx("div",{className:"flex flex-1 items-center",children:s},r))}),e.jsx("div",{className:"grid min-w-0 flex-1 gap-[3px]",style:{gridTemplateColumns:b,maxWidth:N},onMouseLeave:()=>h(null),children:u.weeks.map((s,r)=>e.jsx("div",{className:"flex flex-col gap-[3px]",children:s.map((o,g)=>o===null?e.jsx("div",{className:"aspect-square"},g):e.jsx("button",{type:"button","aria-label":`${T(o.date)} — click to pin`,"aria-pressed":(d==null?void 0:d.date)===o.date,className:`aspect-square block rounded-[3px] p-0 transition duration-150 hover:scale-[1.18] hover:ring-1 hover:ring-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent ${(d==null?void 0:d.date)===o.date?"ring-1 ring-fg-bright":""}`,style:{background:S(o.level)},onMouseEnter:()=>h(f.get(o.date)??null),onFocus:()=>h(f.get(o.date)??null),onClick:()=>p(y=>(y==null?void 0:y.date)===o.date?null:f.get(o.date)??null)},g))},r))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 pl-6 pt-1 text-[9px] text-fg-faint",children:["less",[0,1,2,3,4].map(s=>e.jsx("span",{className:"size-[11px] rounded-[2px]",style:{background:S(s)}},s)),"more"]})]}),e.jsxs("div",{className:"relative border-line-faint md:border-l md:pl-6",children:[e.jsxs("div",{className:`grid grid-cols-2 gap-x-6 gap-y-4 transition-opacity duration-200 md:grid-cols-1 ${m?"opacity-0":"opacity-100"}`,children:[e.jsx(w,{label:"busiest day",value:a.costed?C(a.top.cost):E(a.top.tokens),sub:T(a.top.date),valueClass:"text-cost"}),e.jsx(w,{label:"daily average",value:a.costed?C(a.avg):E(a.avg),sub:`across ${a.active} active days`}),e.jsx(w,{label:"top weekday",value:L[a.busiest],valueClass:"text-fg-bright"}),e.jsx(w,{label:"latest streak",value:`${a.streak}d`,sub:a.streak>0?"in a row":"idle today",valueClass:"text-positive"})]}),m&&e.jsx("div",{className:"dialog-fade absolute inset-0 md:pl-6",children:e.jsx(W,{day:m,pinned:!c&&m===d})})]})]})})})}function W({day:t,pinned:n=!1}){return e.jsxs("div",{className:"font-mono text-[11px]",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3 border-b border-line-faint pb-2",children:[e.jsxs("span",{className:"text-fg-dim",children:[L[D(j(t.date))]," · ",T(t.date),n&&e.jsx("span",{className:"ml-1.5 text-[9px] uppercase tracking-wide text-accent",children:"pinned"})]}),e.jsx("span",{className:"tnum text-cost",children:t.cost>0?C(t.cost):"—"})]}),t.cost>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 py-2 text-[10px]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"calls"}),e.jsx("div",{className:"tnum text-fg",children:I(t.calls)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"tokens"}),e.jsx("div",{className:"tnum text-fg",children:E(t.tokens)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"saved"}),e.jsx("div",{className:"tnum text-positive",children:C(t.cacheSavings)})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 border-t border-line-faint pt-2",children:[t.models.slice(0,5).map(i=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-1.5 shrink-0 rounded-full",style:{background:$(i.name)}}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-dim",children:B(i.name)}),e.jsx("span",{className:"tnum w-16 shrink-0 text-right text-fg",children:C(i.cost)})]},i.name)),t.models.length>5&&e.jsxs("div",{className:"pt-0.5 text-fg-faint",children:["+",t.models.length-5," more"]})]})]}):e.jsx("div",{className:"pt-2 text-fg-faint",children:"no spend this day"})]})}const Y=x.lazy(()=>M(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>({default:t.CostByModel}))),q=x.lazy(()=>M(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>({default:t.ProviderDonut}))),P=x.lazy(()=>M(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>({default:t.TokenComposition}))),G=x.lazy(()=>M(()=>import("./timeline-B4uG-Emo.js"),__vite__mapDeps([6,1,2,3,4,5,7]),import.meta.url).then(t=>({default:t.CacheSavings}))),K=x.lazy(()=>M(()=>import("./timeline-B4uG-Emo.js"),__vite__mapDeps([6,1,2,3,4,5,7]),import.meta.url).then(t=>({default:t.CumulativeSpend})));function _({children:t}){return e.jsx(x.Suspense,{fallback:e.jsx("div",{className:"min-h-64",role:"status","aria-label":"Loading chart"}),children:t})}function X({derived:t,scopeLabel:n}){const i=t.byProvider.length>1;return e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx("div",{className:"md:col-span-2",children:e.jsx(H,{derived:t,periodLabel:n})}),e.jsx(_,{children:e.jsx(Y,{derived:t,periodLabel:n})}),e.jsx(_,{children:i?e.jsx(q,{derived:t,periodLabel:n}):e.jsx(P,{derived:t,periodLabel:n})}),i?e.jsx(_,{children:e.jsx(P,{derived:t,periodLabel:n})}):null,e.jsx("div",{className:i?void 0:"md:col-span-2",children:e.jsx(_,{children:e.jsx(G,{derived:t,periodLabel:n})})}),e.jsx("div",{className:"md:col-span-2",children:e.jsx(_,{children:e.jsx(K,{derived:t,height:300,periodLabel:n})})})]})}export{X as AnalyticsTab};
@@ -1,4 +0,0 @@
1
- import{R as h,l as Qe,r as J,j as u,g as Ye,s as ee,f as G,a as z,n as Je,o as xt,T as ne}from"./index-DH3dOnbg.js";import{c as I,d as k,r as et,e as At,h as tt,i as kt,j as C,k as Pe,p as S,L as _,l as rt,n as Oe,o as nt,D as Pt,q as Ot,t as W,v as F,S as jt,w as _t,x as wt,y as De,z as Tt,B as M,E as je,F as St,H as Et,I as ae,J as Rt,K as _e,M as It,N as ie,O as Be,g as it,X as we,Y as Te,P as Se,f as Nt,Q as Lt,u as Ee,U as at,C as Re,R as Ie,a as ot,G as st,A as se,T as ct,s as Ne}from"./chart-cZoLgpmG.js";import{P as fe}from"./panel-DTQBwExW.js";import{E as pe}from"./primitives-C36qJlA2.js";var $t=["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 Ct(r,e){if(r==null)return{};var n=Dt(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 Dt(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 Mt(r)||Ft(r)||Kt(r)||Bt()}function Bt(){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 Kt(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 Ft(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function Mt(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},Vt=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=Vt(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,c,f){return"".concat(o).concat(f===0?"M":"L").concat(c.x,",").concat(c.y)},"")}).join("");return t.length===1?"".concat(i,"Z"):i},qt=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))},zt=function(e){var n=e.points,t=e.className,i=e.baseLinePoints,a=e.connectNulls,o=Ct(e,$t);if(!n||!n.length)return null;var c=I("recharts-polygon",t);if(i&&i.length){var f=o.stroke&&o.stroke!=="none",s=qt(n,i,a);return h.createElement("g",{className:c},h.createElement("path",V({},k(o,!0),{fill:s.slice(-1)==="Z"?o.fill:"none",stroke:"none",d:s})),f?h.createElement("path",V({},k(o,!0),{fill:"none",d:Q(n,a)})):null,f?h.createElement("path",V({},k(o,!0),{fill:"none",d:Q(i,a)})):null)}var p=Q(n,a);return h.createElement("path",V({},k(o,!0),{fill:p.slice(-1)==="Z"?o.fill:"none",className:c,d:p}))},ye,Me;function Wt(){if(Me)return ye;Me=1;var r=et(),e=At(),n=tt();function t(i,a){return i&&i.length?r(i,n(a,2),e):void 0}return ye=t,ye}var Gt=Wt();const Ht=Qe(Gt);var ge,Ve;function Ut(){if(Ve)return ge;Ve=1;var r=et(),e=tt(),n=kt();function t(i,a){return i&&i.length?r(i,e(a,2),n):void 0}return ge=t,ge}var Zt=Ut();const Xt=Qe(Zt);var Qt=["cx","cy","angle","ticks","axisLine"],Yt=["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=Jt(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 Jt(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 er(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 tr(r,e,n){return e&&We(r.prototype,e),n&&We(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function rr(r,e,n){return e=ce(e),nr(r,lt()?Reflect.construct(e,n||[],ce(r).constructor):e.apply(r,n))}function nr(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 ir(r)}function ir(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 ce(r){return ce=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},ce(r)}function ar(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=or(r,"string");return H(e)=="symbol"?e:e+""}function or(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 String(r)}var me=(function(r){function e(){return er(this,e),rr(this,e,arguments)}return ar(e,r),tr(e,[{key:"getTickValueCoord",value:function(t){var i=t.coordinate,a=this.props,o=a.angle,c=a.cx,f=a.cy;return S(c,f,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,c=t.ticks,f=Ht(c,function(p){return p.coordinate||0}),s=Xt(c,function(p){return p.coordinate||0});return{cx:i,cy:a,startAngle:o,endAngle:o,innerRadius:s.coordinate||0,outerRadius:f.coordinate||0}}},{key:"renderAxisLine",value:function(){var t=this.props,i=t.cx,a=t.cy,o=t.angle,c=t.ticks,f=t.axisLine,s=ze(t,Qt),p=c.reduce(function(m,l){return[Math.min(m[0],l.coordinate),Math.max(m[1],l.coordinate)]},[1/0,-1/0]),d=S(i,a,p[0],o),v=S(i,a,p[1],o),A=L(L(L({},k(s,!1)),{},{fill:"none"},k(f,!1)),{},{x1:d.x,y1:d.y,x2:v.x,y2:v.y});return h.createElement("line",Y({className:"recharts-polar-radius-axis-line"},A))}},{key:"renderTicks",value:function(){var t=this,i=this.props,a=i.ticks,o=i.tick,c=i.angle,f=i.tickFormatter,s=i.stroke,p=ze(i,Yt),d=this.getTickTextAnchor(),v=k(p,!1),A=k(o,!1),m=a.map(function(l,g){var b=t.getTickValueCoord(l),x=L(L(L(L({textAnchor:d,transform:"rotate(".concat(90-c,", ").concat(b.x,", ").concat(b.y,")")},v),{},{stroke:"none",fill:s},A),{},{index:g},b),{},{payload:l});return h.createElement(_,Y({className:I("recharts-polar-radius-axis-tick",rt(o)),key:"tick-".concat(l.coordinate)},Oe(t.props,l,g)),e.renderTickItem(o,x,f?f(l.value,g):l.value))});return h.createElement(_,{className:"recharts-polar-radius-axis-ticks"},m)}},{key:"render",value:function(){var t=this.props,i=t.ticks,a=t.axisLine,o=t.tick;return!i||!i.length?null:h.createElement(_,{className:I("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 h.isValidElement(t)?o=h.cloneElement(t,i):C(t)?o=t(i):o=h.createElement(Pe,Y({},i,{className:"recharts-polar-radius-axis-tick-value"}),a),o}}])})(J.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 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 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 sr(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 cr(r,e,n){return e&&He(r.prototype,e),n&&He(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function lr(r,e,n){return e=le(e),ur(r,ft()?Reflect.construct(e,n||[],le(r).constructor):e.apply(r,n))}function ur(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 fr(r)}function fr(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 le(r){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},le(r)}function pr(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=dr(r,"string");return U(e)=="symbol"?e:e+""}function dr(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 mr=Math.PI/180,Ue=1e-5,he=(function(r){function e(){return sr(this,e),lr(this,e,arguments)}return pr(e,r),cr(e,[{key:"getTickLineCoord",value:function(t){var i=this.props,a=i.cx,o=i.cy,c=i.radius,f=i.orientation,s=i.tickSize,p=s||8,d=S(a,o,c,t.coordinate),v=S(a,o,c+(f==="inner"?-1:1)*p,t.coordinate);return{x1:d.x,y1:d.y,x2:v.x,y2:v.y}}},{key:"getTickTextAnchor",value:function(t){var i=this.props.orientation,a=Math.cos(-t.coordinate*mr),o;return a>Ue?o=i==="outer"?"start":"end":a<-Ue?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,c=t.axisLine,f=t.axisLineType,s=$($({},k(this.props,!1)),{},{fill:"none"},k(c,!1));if(f==="circle")return h.createElement(Pt,D({className:"recharts-polar-angle-axis-line"},s,{cx:i,cy:a,r:o}));var p=this.props.ticks,d=p.map(function(v){return S(i,a,o,v.coordinate)});return h.createElement(zt,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,c=i.tickLine,f=i.tickFormatter,s=i.stroke,p=k(this.props,!1),d=k(o,!1),v=$($({},p),{},{fill:"none"},k(c,!1)),A=a.map(function(m,l){var g=t.getTickLineCoord(m),b=t.getTickTextAnchor(m),x=$($($({textAnchor:b},p),{},{stroke:"none",fill:s},d),{},{index:l,payload:m,x:g.x2,y:g.y2});return h.createElement(_,D({className:I("recharts-polar-angle-axis-tick",rt(o)),key:"tick-".concat(m.coordinate)},Oe(t.props,m,l)),c&&h.createElement("line",D({className:"recharts-polar-angle-axis-tick-line"},v,g)),o&&e.renderTickItem(o,x,f?f(m.value,l):m.value))});return h.createElement(_,{className:"recharts-polar-angle-axis-ticks"},A)}},{key:"render",value:function(){var t=this.props,i=t.ticks,a=t.radius,o=t.axisLine;return a<=0||!i||!i.length?null:h.createElement(_,{className:I("recharts-polar-angle-axis",this.props.className)},o&&this.renderAxisLine(),this.renderTicks())}}],[{key:"renderTickItem",value:function(t,i,a){var o;return h.isValidElement(t)?o=h.cloneElement(t,i):C(t)?o=t(i):o=h.createElement(Pe,D({},i,{className:"recharts-polar-angle-axis-tick-value"}),a),o}}])})(J.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 oe;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 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 Ze(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 y(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ze(Object(n),!0).forEach(function(t){O(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Ze(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function vr(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 hr(r,e,n){return e&&Xe(r.prototype,e),n&&Xe(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function yr(r,e,n){return e=ue(e),gr(r,dt()?Reflect.construct(e,n||[],ue(r).constructor):e.apply(r,n))}function gr(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 br(r)}function br(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 ue(r){return ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},ue(r)}function xr(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 O(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=Ar(r,"string");return Z(e)=="symbol"?e:e+""}function Ar(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 String(r)}var E=(function(r){function e(n){var t;return vr(this,e),t=yr(this,e,[n]),O(t,"pieRef",null),O(t,"sectorRefs",[]),O(t,"id",St("recharts-pie-")),O(t,"handleAnimationEnd",function(){var i=t.props.onAnimationEnd;t.setState({isAnimationFinished:!0}),C(i)&&i()}),O(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 xr(e,r),hr(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,c=a.labelLine,f=a.dataKey,s=a.valueKey,p=k(this.props,!1),d=k(o,!1),v=k(c,!1),A=o&&o.offsetRadius||20,m=t.map(function(l,g){var b=(l.startAngle+l.endAngle)/2,x=S(l.cx,l.cy,l.outerRadius+A,b),j=y(y(y(y({},p),l),{},{stroke:"none"},d),{},{index:g,textAnchor:e.getTextAnchor(x.x,l.cx)},x),B=y(y(y(y({},p),l),{},{fill:"none",stroke:l.fill},v),{},{index:g,points:[S(l.cx,l.cy,l.outerRadius,b),x]}),w=f;return W(f)&&W(s)?w="value":W(f)&&(w=s),h.createElement(_,{key:"label-".concat(l.startAngle,"-").concat(l.endAngle,"-").concat(l.midAngle,"-").concat(g)},c&&e.renderLabelLineItem(c,B,"line"),e.renderLabelItem(o,j,F(l,w)))});return h.createElement(_,{className:"recharts-pie-labels"},m)}},{key:"renderSectorsStatically",value:function(t){var i=this,a=this.props,o=a.activeShape,c=a.blendStroke,f=a.inactiveShape;return t.map(function(s,p){if((s==null?void 0:s.startAngle)===0&&(s==null?void 0:s.endAngle)===0&&t.length!==1)return null;var d=i.isActiveIndex(p),v=f&&i.hasActiveIndex()?f:null,A=d?o:v,m=y(y({},s),{},{stroke:c?s.fill:s.stroke,tabIndex:-1});return h.createElement(_,q({ref:function(g){g&&!i.sectorRefs.includes(g)&&i.sectorRefs.push(g)},tabIndex:-1,className:"recharts-pie-sector"},Oe(i.props,s,p),{key:"sector-".concat(s==null?void 0:s.startAngle,"-").concat(s==null?void 0:s.endAngle,"-").concat(s.midAngle,"-").concat(p)}),h.createElement(jt,q({option:A,isActive:d,shapeType:"sector"},m)))})}},{key:"renderSectorsWithAnimation",value:function(){var t=this,i=this.props,a=i.sectors,o=i.isAnimationActive,c=i.animationBegin,f=i.animationDuration,s=i.animationEasing,p=i.animationId,d=this.state,v=d.prevSectors,A=d.prevIsAnimationActive;return h.createElement(_t,{begin:c,duration:f,isActive:o,easing:s,from:{t:0},to:{t:1},key:"pie-".concat(p,"-").concat(A),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(m){var l=m.t,g=[],b=a&&a[0],x=b.startAngle;return a.forEach(function(j,B){var w=v&&v[B],N=B>0?wt(j,"paddingAngle",0):0;if(w){var X=De(w.endAngle-w.startAngle,j.endAngle-j.startAngle),P=y(y({},j),{},{startAngle:x+N,endAngle:x+X(l)+N});g.push(P),x=P.endAngle}else{var K=j.endAngle,T=j.startAngle,te=De(0,K-T),re=te(l),R=y(y({},j),{},{startAngle:x+N,endAngle:x+re+N});g.push(R),x=R.endAngle}}),h.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 c=--i.state.sectorToFocus<0?i.sectorRefs.length-1:i.state.sectorToFocus%i.sectorRefs.length;i.sectorRefs[c].focus(),i.setState({sectorToFocus:c});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||!Tt(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,c=i.className,f=i.label,s=i.cx,p=i.cy,d=i.innerRadius,v=i.outerRadius,A=i.isAnimationActive,m=this.state.isAnimationFinished;if(a||!o||!o.length||!M(s)||!M(p)||!M(d)||!M(v))return null;var l=I("recharts-pie",c);return h.createElement(_,{tabIndex:this.props.rootTabIndex,className:l,ref:function(b){t.pieRef=b}},this.renderSectors(),f&&this.renderLabels(o),nt.renderCallByParent(this.props,null,!1),(!A||m)&&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(h.isValidElement(t))return h.cloneElement(t,i);if(C(t))return t(i);var o=I("recharts-pie-label-line",typeof t!="boolean"?t.className:"");return h.createElement(Ot,q({},i,{key:a,type:"linear",className:o}))}},{key:"renderLabelItem",value:function(t,i,a){if(h.isValidElement(t))return h.cloneElement(t,i);var o=a;if(C(t)&&(o=t(i),h.isValidElement(o)))return o;var c=I("recharts-pie-label-text",typeof t!="boolean"&&!C(t)?t.className:"");return h.createElement(Pe,q({},i,{alignmentBaseline:"middle",className:c}),o)}}])})(J.PureComponent);oe=E;O(E,"displayName","Pie");O(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:!Et.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0});O(E,"parseDeltaAngle",function(r,e){var n=ae(e-r),t=Math.min(Math.abs(e-r),360);return n*t});O(E,"getRealPieData",function(r){var e=r.data,n=r.children,t=k(r,!1),i=Rt(n,_e);return e&&e.length?e.map(function(a,o){return y(y(y({payload:a},t),a),i&&i[o]&&i[o].props)}):i&&i.length?i.map(function(a){return y(y({},t),a.props)}):[]});O(E,"parseCoordinateOfPie",function(r,e){var n=e.top,t=e.left,i=e.width,a=e.height,o=It(i,a),c=t+ie(r.cx,i,i/2),f=n+ie(r.cy,a,a/2),s=ie(r.innerRadius,o,0),p=ie(r.outerRadius,o,o*.8),d=r.maxRadius||Math.sqrt(i*i+a*a)/2;return{cx:c,cy:f,innerRadius:s,outerRadius:p,maxRadius:d}});O(E,"getComposedData",function(r){var e=r.item,n=r.offset,t=e.type.defaultProps!==void 0?y(y({},e.type.defaultProps),e.props):e.props,i=oe.getRealPieData(t);if(!i||!i.length)return null;var a=t.cornerRadius,o=t.startAngle,c=t.endAngle,f=t.paddingAngle,s=t.dataKey,p=t.nameKey,d=t.valueKey,v=t.tooltipType,A=Math.abs(t.minAngle),m=oe.parseCoordinateOfPie(t,n),l=oe.parseDeltaAngle(o,c),g=Math.abs(l),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(P){return F(P,b,0)!==0}).length,j=(g>=360?x:x-1)*f,B=g-x*A-j,w=i.reduce(function(P,K){var T=F(K,b,0);return P+(M(T)?T:0)},0),N;if(w>0){var X;N=i.map(function(P,K){var T=F(P,b,0),te=F(P,p,K),re=(M(T)?T:0)/w,R;K?R=X.endAngle+ae(l)*f*(T!==0?1:0):R=o;var Le=R+ae(l)*((T!==0?A:0)+re*B),$e=(R+Le)/2,Ce=(m.innerRadius+m.outerRadius)/2,gt=[{name:te,value:T,payload:P,dataKey:b,type:v}],bt=S(m.cx,m.cy,Ce,$e);return X=y(y(y({percent:re,cornerRadius:a,name:te,tooltipPayload:gt,midAngle:$e,middleRadius:Ce,tooltipPosition:bt},P),m),{},{value:F(P,b),startAngle:R,endAngle:Le,payload:P,paddingAngle:ae(l)*f}),X})}return y(y({},m),{},{sectors:N,data:i})});var vt=it({chartName:"BarChart",GraphicalChild:Se,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:we},{axisType:"yAxis",AxisComp:Te}],formatAxisMap:Nt}),kr=it({chartName:"PieChart",GraphicalChild:E,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:he},{axisType:"radiusAxis",AxisComp:me}],formatAxisMap:Lt,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)"},Pr=Ne("cost",G,r=>{var e;return(e=r[0])==null?void 0:e.color},{title:r=>ee(r)}),Or=Ne("tokens",z,r=>{var e;return(e=r[0])==null?void 0:e.color},{title:r=>ee(r)}),jr=Ne("saved",G,r=>{var e;return(e=r[0])==null?void 0:e.color},{title:r=>ee(r)});function Er({derived:r,height:e=280,limit:n=10,metric:t="cost",periodLabel:i}){const a=Ee(),o=at("(min-width: 768px)"),c=o?124:92,f=o?60:44,s=t==="tokens",p=[...r.byModel].sort((d,v)=>s?v.tokens-d.tokens:v.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:p.length===0?u.jsx(pe,{children:"no models in period"}):u.jsx(Re,{height:e,children:u.jsx(Ie,{children:u.jsxs(vt,{data:p,layout:"vertical",margin:{top:4,right:f,left:4,bottom:0},children:[u.jsx(ot,{...st,horizontal:!1,vertical:!0}),u.jsx(we,{type:"number",...se,tickFormatter:s?z:Ye}),u.jsx(Te,{type:"category",dataKey:"model",...se,width:c,tickFormatter:ee}),u.jsx(ct,{content:s?Or:Pr,cursor:ht}),u.jsxs(Se,{dataKey:s?"tokens":"cost",radius:[0,3,3,0],isAnimationActive:a,animationDuration:350,children:[p.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 Rr({derived:r,height:e=240,limit:n=12,periodLabel:t}){const i=Ee(),a=at("(min-width: 768px)"),o=a?124:92,c=a?60:44,f=[...r.byModel].filter(s=>s.cacheSavings>0).sort((s,p)=>p.cacheSavings-s.cacheSavings).slice(0,n);return u.jsx(fe,{title:"cache savings by model",titleTag:t,captureName:"cache-savings-by-model",children:f.length===0?u.jsx(pe,{children:"no cache savings in period"}):u.jsx(Re,{height:e,children:u.jsx(Ie,{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(we,{type:"number",...se,tickFormatter:Ye}),u.jsx(Te,{type:"category",dataKey:"model",...se,width:o,tickFormatter:ee}),u.jsx(ct,{content:jr,cursor:ht}),u.jsx(Se,{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 Ir({derived:r,height:e=280,periodLabel:n}){const t=Ee(),i=r.byProvider,a=r.totals.cost,[o,c]=J.useState(null),[f,s]=J.useState(null),p=f?i.findIndex(m=>m.id===f):-1,d=o??(p>=0?p:null),v=d!=null?i[d]:null,A=v&&a>0?v.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:()=>c(null),children:[u.jsx(Re,{height:e,children:u.jsx(Ie,{children:u.jsx(kr,{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,style:{cursor:"pointer"},onMouseEnter:(m,l)=>c(l),onClick:(m,l)=>s(g=>{var b,x;return g===((b=i[l])==null?void 0:b.id)?null:((x=i[l])==null?void 0:x.id)??null}),children:i.map((m,l)=>u.jsx(_e,{fill:m.color,"aria-label":`${m.name}: ${G(m.cost)}`,fillOpacity:d==null||d===l?1:.32,style:{transition:"fill-opacity 150ms ease"}},m.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:v?v.color:"var(--color-fg-bright)"},children:G(v?v.cost:a)}),u.jsxs("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:[v?`${v.name} · ${Je(A,A>0&&A<.01?1:0)}`:"total",v&&o==null&&p>=0&&u.jsx("span",{className:"text-accent",children:" · pinned"})]})]})]})})}function Nr({derived:r,periodLabel:e}){const n=r.tokenComposition,t=xt(n),i=[{key:"cacheRead",label:"cache read",value:n.cacheRead,color:ne.cacheRead},{key:"input",label:"input",value:n.input,color:ne.input},{key:"output",label:"output",value:n.output,color:ne.output},{key:"cacheCreate",label:"cache write",value:n.cacheCreate,color:ne.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{Rr as CacheByModel,Er as CostByModel,Ir as ProviderDonut,Nr as TokenComposition};