tokmon 0.28.2 → 0.28.4

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 (56) hide show
  1. package/README.md +156 -234
  2. package/THIRD_PARTY_NOTICES.md +62 -0
  3. package/dist/{bootstrap-ink-IMT3S5HU.js → bootstrap-ink-WG4WG3R2.js} +1579 -1136
  4. package/dist/chunk-5B3XCEMC.js +294 -0
  5. package/dist/chunk-7CH6S7BR.js +447 -0
  6. package/dist/{chunk-LCAHTRGP.js → chunk-CFKUZCMB.js} +56 -29
  7. package/dist/{chunk-LKYOWBD4.js → chunk-FLANGRI6.js} +21 -42
  8. package/dist/chunk-HNWEJ6MS.js +1094 -0
  9. package/dist/{chunk-WUK3MQUB.js → chunk-JZSZEHVD.js} +167 -10
  10. package/dist/{chunk-6ZEW2M6P.js → chunk-P57DVFNH.js} +125 -25
  11. package/dist/chunk-TN6V7XSL.js +512 -0
  12. package/dist/chunk-UYPDMVW5.js +21 -0
  13. package/dist/{cli-command-DCENRCO3.js → cli-command-I4GRR3MF.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-ZXV3V5CS.js +384 -0
  17. package/dist/daemon-handle-G4OGPFR3.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-44ZSQEOS.js +0 -299
  38. package/dist/chunk-HP5UZCXP.js +0 -436
  39. package/dist/chunk-J3JW3RFP.js +0 -196
  40. package/dist/chunk-M7XMV36F.js +0 -275
  41. package/dist/daemon-6Y4O7NXS.js +0 -241
  42. package/dist/daemon-handle-GVCYVDPO.js +0 -10
  43. package/dist/server-GXXOWUVZ.js +0 -11
  44. package/dist/web/assets/analytics-DqdZXOJL.js +0 -2
  45. package/dist/web/assets/breakdown-kOSSJ3mI.js +0 -4
  46. package/dist/web/assets/explore-vcsM8K9I.js +0 -22
  47. package/dist/web/assets/index-BErCXT7f.css +0 -1
  48. package/dist/web/assets/index-DH3dOnbg.js +0 -83
  49. package/dist/web/assets/models-B5ikm83_.js +0 -2
  50. package/dist/web/assets/overview-DD1kP8CP.js +0 -2
  51. package/dist/web/assets/panel-DTQBwExW.js +0 -1
  52. package/dist/web/assets/primitives-C36qJlA2.js +0 -1
  53. package/dist/web/assets/settings-sheet-_i2zTQjf.js +0 -1
  54. package/dist/web/assets/share-sheet-BLHmrFbm.js +0 -2
  55. package/dist/web/assets/timeline-B4uG-Emo.js +0 -1
  56. package/dist/web/assets/use-dialog-trap-bfaXEMz9.js +0 -1
@@ -1,275 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- TOKMON_WS_METHODS,
4
- TOKMON_WS_PATH,
5
- TokmonRpcGroup
6
- } from "./chunk-WUK3MQUB.js";
7
-
8
- // src/client/daemon-rpc-client.ts
9
- import { Cause, Context, Duration, Effect, Exit, Fiber, Layer, ManagedRuntime, Schedule, Stream } from "effect";
10
- import { RpcClient, RpcSerialization } from "effect/unstable/rpc";
11
- import * as Socket from "effect/unstable/socket/Socket";
12
- var TokmonRpcClient = class extends Context.Service()(
13
- "tokmon/client/DaemonRpcClient/TokmonRpcClient"
14
- ) {
15
- };
16
- var dynamicImport = new Function("specifier", "return import(specifier)");
17
- function toWsUrl(baseUrl) {
18
- const base = typeof window === "undefined" ? void 0 : window.location.origin;
19
- const url = new URL(baseUrl, base);
20
- if (url.protocol === "http:") url.protocol = "ws:";
21
- else if (url.protocol === "https:") url.protocol = "wss:";
22
- if (url.protocol !== "ws:" && url.protocol !== "wss:") {
23
- throw new Error(`unsupported daemon RPC protocol: ${url.protocol}`);
24
- }
25
- url.hash = "";
26
- url.searchParams.delete("tokmonToken");
27
- url.searchParams.delete("wsToken");
28
- url.pathname = TOKMON_WS_PATH;
29
- return url.toString();
30
- }
31
- function shouldUseNodeTransport(transport) {
32
- if (transport === "node") return true;
33
- if (transport === "browser") return false;
34
- return typeof window === "undefined";
35
- }
36
- async function socketLayerFor(url, transport) {
37
- if (shouldUseNodeTransport(transport)) {
38
- const NodeSocket = await dynamicImport("@effect/platform-node/NodeSocket");
39
- return NodeSocket.layerWebSocket(url);
40
- }
41
- return Socket.layerWebSocket(url).pipe(
42
- Layer.provide(Socket.layerWebSocketConstructorGlobal)
43
- );
44
- }
45
- function retryPolicy(options) {
46
- const baseDelay = options.reconnectBaseDelayMs ?? 250;
47
- const policy = Schedule.exponential(Duration.millis(baseDelay), 1.5).pipe(
48
- Schedule.either(Schedule.spaced(Duration.millis(2500)))
49
- );
50
- return typeof options.reconnectAttempts === "number" ? policy.pipe(Schedule.both(Schedule.recurs(options.reconnectAttempts))) : policy;
51
- }
52
- function createDaemonRpcClient(baseUrl, options = {}) {
53
- const url = toWsUrl(baseUrl);
54
- const fibers = /* @__PURE__ */ new Set();
55
- let session = null;
56
- let sessionPromise = null;
57
- let closed = false;
58
- const setConn = (state, error) => {
59
- options.onConn?.(state, error);
60
- };
61
- const resetSession = (active) => {
62
- if (active !== void 0 && active !== null && active !== session) {
63
- void active.runtime.dispose().catch(() => {
64
- });
65
- return;
66
- }
67
- const dead = active ?? session;
68
- session = null;
69
- sessionPromise = null;
70
- if (dead) void dead.runtime.dispose().catch(() => {
71
- });
72
- };
73
- const makeProtocolLayer = async () => {
74
- const socketLayer = await socketLayerFor(url, options.transport);
75
- const connectionHooksLayer = Layer.succeed(
76
- RpcClient.ConnectionHooks,
77
- RpcClient.ConnectionHooks.of({
78
- onConnect: Effect.sync(() => {
79
- setConn("live");
80
- }),
81
- onDisconnect: Effect.sync(() => {
82
- if (!closed) {
83
- setConn("reconnecting");
84
- }
85
- })
86
- })
87
- );
88
- return Layer.effect(
89
- RpcClient.Protocol,
90
- RpcClient.makeProtocolSocket({
91
- retryPolicy: retryPolicy(options),
92
- retryTransientErrors: true
93
- })
94
- ).pipe(
95
- Layer.provide(Layer.mergeAll(socketLayer, RpcSerialization.layerJson, connectionHooksLayer))
96
- );
97
- };
98
- const ensureSession = async () => {
99
- if (closed) throw new Error("daemon RPC client is closed");
100
- if (session) return session;
101
- if (sessionPromise) return sessionPromise;
102
- setConn("connecting");
103
- sessionPromise = (async () => {
104
- let runtime;
105
- try {
106
- const protocolLayer = await makeProtocolLayer();
107
- const clientLayer = Layer.effect(
108
- TokmonRpcClient,
109
- RpcClient.make(TokmonRpcGroup)
110
- ).pipe(
111
- Layer.provide(protocolLayer)
112
- );
113
- runtime = ManagedRuntime.make(clientLayer);
114
- await runtime.runPromise(TokmonRpcClient.asEffect());
115
- if (closed) {
116
- await runtime.dispose();
117
- throw new Error("daemon RPC client is closed");
118
- }
119
- session = { runtime };
120
- return session;
121
- } catch (error) {
122
- sessionPromise = null;
123
- await runtime?.dispose().catch(() => {
124
- });
125
- if (!closed) setConn("error", error);
126
- throw error;
127
- }
128
- })();
129
- return sessionPromise;
130
- };
131
- const run = async (effectFor) => {
132
- const active = await ensureSession();
133
- try {
134
- return await active.runtime.runPromise(
135
- TokmonRpcClient.use((client) => effectFor(client))
136
- );
137
- } catch (error) {
138
- if (!closed) {
139
- resetSession(active);
140
- setConn("error", error);
141
- }
142
- throw error;
143
- }
144
- };
145
- const subscribe = (streamFor, onValue, staleAfterFor) => {
146
- if (closed) return () => {
147
- };
148
- let fiber = null;
149
- let unsubscribed = false;
150
- let retryTimer = null;
151
- let watchdogTimer = null;
152
- let lastValueAt = 0;
153
- let staleAfterMs = Number.POSITIVE_INFINITY;
154
- let watchdogRestart = false;
155
- const stopFiber = () => {
156
- if (!fiber) return;
157
- const current = fiber;
158
- fiber = null;
159
- fibers.delete(current);
160
- void (session?.runtime.runPromise(Fiber.interrupt(current)) ?? Effect.runPromise(Fiber.interrupt(current))).catch(() => {
161
- });
162
- };
163
- const scheduleRetry = () => {
164
- if (closed || unsubscribed || retryTimer) return;
165
- retryTimer = setTimeout(() => {
166
- retryTimer = null;
167
- start();
168
- }, options.reconnectBaseDelayMs ?? 250);
169
- retryTimer.unref?.();
170
- };
171
- if (staleAfterFor) {
172
- const checkEveryMs = Math.min(5e3, Math.max(10, (options.snapshotStaleFloorMs ?? 9e4) / 2));
173
- watchdogTimer = setInterval(() => {
174
- if (!fiber || lastValueAt === 0 || Date.now() - lastValueAt <= staleAfterMs) return;
175
- watchdogRestart = true;
176
- lastValueAt = Date.now();
177
- setConn("reconnecting");
178
- stopFiber();
179
- }, checkEveryMs);
180
- watchdogTimer.unref?.();
181
- }
182
- const start = () => {
183
- void (async () => {
184
- try {
185
- const active = await ensureSession();
186
- if (closed || unsubscribed) return;
187
- lastValueAt = Date.now();
188
- staleAfterMs = options.snapshotStaleFloorMs ?? 9e4;
189
- const currentFiber = active.runtime.runFork(
190
- TokmonRpcClient.use(
191
- (client) => streamFor(client).pipe(
192
- Stream.runForEach(
193
- (value) => Effect.sync(() => {
194
- lastValueAt = Date.now();
195
- if (staleAfterFor) staleAfterMs = staleAfterFor(value);
196
- try {
197
- onValue(value);
198
- } catch {
199
- }
200
- })
201
- )
202
- )
203
- )
204
- );
205
- fiber = currentFiber;
206
- fibers.add(currentFiber);
207
- currentFiber.addObserver((exit) => {
208
- fibers.delete(currentFiber);
209
- if (fiber === currentFiber) fiber = null;
210
- if (closed || unsubscribed) return;
211
- const stale = watchdogRestart;
212
- watchdogRestart = false;
213
- resetSession(active);
214
- if (stale || Exit.isSuccess(exit)) setConn("reconnecting");
215
- else setConn("error", Cause.squash(exit.cause));
216
- scheduleRetry();
217
- });
218
- } catch (error) {
219
- if (!closed && !unsubscribed) {
220
- resetSession();
221
- setConn("error", error);
222
- scheduleRetry();
223
- }
224
- }
225
- })();
226
- };
227
- start();
228
- return () => {
229
- unsubscribed = true;
230
- if (retryTimer) {
231
- clearTimeout(retryTimer);
232
- retryTimer = null;
233
- }
234
- if (watchdogTimer) {
235
- clearInterval(watchdogTimer);
236
- watchdogTimer = null;
237
- }
238
- stopFiber();
239
- };
240
- };
241
- return {
242
- getConfig: () => run((client) => client[TOKMON_WS_METHODS.getConfig]({})).then((state) => state),
243
- setConfig: (config) => run((client) => client[TOKMON_WS_METHODS.setConfig](config)).then((state) => state),
244
- refresh: (scope = "all") => run((client) => client[TOKMON_WS_METHODS.refresh]({ scope })),
245
- browseFs: (path) => run((client) => client[TOKMON_WS_METHODS.browseFs]({ path })),
246
- subscribeSnapshot: (onSnapshot) => subscribe(
247
- (client) => client[TOKMON_WS_METHODS.snapshot]({}).pipe(Stream.map((value) => value)),
248
- onSnapshot,
249
- (snapshot) => Math.max(options.snapshotStaleFloorMs ?? 9e4, snapshot.intervalMs * 3)
250
- ),
251
- subscribeConfig: (onConfig) => subscribe((client) => client[TOKMON_WS_METHODS.config]({}).pipe(Stream.map((value) => value)), onConfig),
252
- async close() {
253
- if (closed) return;
254
- closed = true;
255
- setConn("closed");
256
- const active = [...fibers];
257
- fibers.clear();
258
- const activeSession = session ?? await sessionPromise?.catch(() => null) ?? null;
259
- await Promise.all(active.map(
260
- (fiber) => (activeSession?.runtime.runPromise(Fiber.interrupt(fiber)) ?? Effect.runPromise(Fiber.interrupt(fiber))).catch(() => {
261
- })
262
- ));
263
- session = null;
264
- sessionPromise = null;
265
- if (activeSession) {
266
- await activeSession.runtime.dispose().catch(() => {
267
- });
268
- }
269
- }
270
- };
271
- }
272
-
273
- export {
274
- createDaemonRpcClient
275
- };
@@ -1,241 +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-J3JW3RFP.js";
12
- import {
13
- appVersion,
14
- startWebServer
15
- } from "./chunk-6ZEW2M6P.js";
16
- import "./chunk-44ZSQEOS.js";
17
- import {
18
- flushDisk
19
- } from "./chunk-LCAHTRGP.js";
20
- import {
21
- TOKMON_CAPABILITIES,
22
- TOKMON_PROTOCOL_VERSION
23
- } from "./chunk-WUK3MQUB.js";
24
- import {
25
- loadConfig
26
- } from "./chunk-HP5UZCXP.js";
27
-
28
- // src/web/daemon.ts
29
- import { randomBytes } from "crypto";
30
-
31
- // src/web/open.ts
32
- import { spawn } from "child_process";
33
- import { appendFileSync } from "fs";
34
- function openBrowser(url) {
35
- const target = url;
36
- if (process.env.TOKMON_OPENLOG) {
37
- try {
38
- appendFileSync(process.env.TOKMON_OPENLOG, target + "\n");
39
- } catch {
40
- }
41
- return;
42
- }
43
- try {
44
- if (process.platform === "darwin") {
45
- spawn("open", [target], { stdio: "ignore", detached: true }).unref();
46
- } else if (process.platform === "win32") {
47
- spawn("cmd", ["/c", "start", "", target], { stdio: "ignore", detached: true }).unref();
48
- } else {
49
- spawn("xdg-open", [target], { stdio: "ignore", detached: true }).unref();
50
- }
51
- } catch {
52
- }
53
- }
54
-
55
- // src/web/daemon.ts
56
- function parseDaemonArgs(args) {
57
- let port;
58
- let open = true;
59
- let help = false;
60
- for (let i = 0; i < args.length; i++) {
61
- const arg = args[i];
62
- if ((arg === "--port" || arg === "-p") && args[i + 1]) port = Number(args[++i]);
63
- else if (arg.startsWith("--port=")) port = Number(arg.slice("--port=".length));
64
- else if (arg === "--no-open") open = false;
65
- else if (arg === "--help" || arg === "-h") help = true;
66
- }
67
- if (port !== void 0 && (!Number.isInteger(port) || port < 0 || port > 65535)) port = void 0;
68
- return { port, open, help };
69
- }
70
- var SERVE_HELP = `tokmon serve - Launch the tokmon web dashboard
71
-
72
- Usage: tokmon serve [options]
73
-
74
- Options:
75
- -p, --port <n> Port to listen on (default: 4317, auto-falls back if taken)
76
- --no-open Don't open the browser automatically
77
- -h, --help Show this help
78
- `;
79
- function handshake(lock) {
80
- process.stdout.write(JSON.stringify({
81
- ready: 1,
82
- url: lock.url,
83
- port: lock.port,
84
- wsToken: lock.wsToken,
85
- version: lock.version,
86
- protocolVersion: lock.protocolVersion,
87
- capabilities: lock.capabilities,
88
- ownerKind: lock.ownerKind
89
- }) + "\n");
90
- }
91
- function describeExisting(lock, open) {
92
- process.stdout.write(`
93
- \u25C6 tokmon web \u2192 ${lock.url}
94
- `);
95
- process.stdout.write(" reusing the live singleton daemon\n\n");
96
- if (open) {
97
- openBrowser(lock.url);
98
- process.stdout.write(" opening browser\u2026\n");
99
- }
100
- }
101
- async function runDaemon(args, opts) {
102
- const { port, open, help } = parseDaemonArgs(args);
103
- if (help && opts.foreground) {
104
- process.stdout.write(SERVE_HELP);
105
- return;
106
- }
107
- const version = appVersion();
108
- let current = readLock();
109
- if (!current && reclaimAbandonedLock()) current = readLock();
110
- const live = await verifyLock(current, TOKMON_PROTOCOL_VERSION);
111
- if (live) {
112
- if (opts.foreground) describeExisting(live, open);
113
- else handshake(live);
114
- return;
115
- }
116
- if (current?.state === "starting" && current.protocolVersion === TOKMON_PROTOCOL_VERSION && isAlive(current.pid)) {
117
- for (let attempt = 0; attempt < 60; attempt++) {
118
- await new Promise((resolve) => setTimeout(resolve, 50));
119
- const winner = await verifyLock(readLock(), TOKMON_PROTOCOL_VERSION, 250);
120
- if (winner) {
121
- if (opts.foreground) describeExisting(winner, open);
122
- else handshake(winner);
123
- return;
124
- }
125
- }
126
- }
127
- if (current && isAlive(current.pid)) {
128
- const message = "tokmon: another daemon owns the lock but could not be verified (version/token mismatch)";
129
- if (opts.foreground) {
130
- process.stderr.write(message + "\n");
131
- process.exitCode = 1;
132
- }
133
- return;
134
- }
135
- if (current) reclaimDeadLock();
136
- const ownerId = randomBytes(32).toString("base64url");
137
- const token = randomBytes(32).toString("base64url");
138
- const reservation = {
139
- pid: process.pid,
140
- port: 0,
141
- url: "",
142
- wsToken: token,
143
- version,
144
- protocolVersion: TOKMON_PROTOCOL_VERSION,
145
- capabilities: [...TOKMON_CAPABILITIES],
146
- ownerKind: "cli",
147
- startedAt: Date.now(),
148
- ownerId,
149
- state: "starting"
150
- };
151
- if (!acquireLock(reservation)) {
152
- for (let attempt = 0; attempt < 60; attempt++) {
153
- await new Promise((resolve) => setTimeout(resolve, 50));
154
- const winner = await verifyLock(readLock(), TOKMON_PROTOCOL_VERSION, 250);
155
- if (winner) {
156
- if (opts.foreground) describeExisting(winner, open);
157
- else handshake(winner);
158
- return;
159
- }
160
- }
161
- if (opts.foreground) {
162
- process.stderr.write("tokmon: daemon startup is already in progress\n");
163
- process.exitCode = 1;
164
- }
165
- return;
166
- }
167
- let controller = null;
168
- try {
169
- const config = await loadConfig();
170
- controller = await startWebServer({
171
- config,
172
- port,
173
- log: opts.foreground,
174
- wsToken: token,
175
- ownerKind: reservation.ownerKind,
176
- protocolVersion: reservation.protocolVersion,
177
- capabilities: reservation.capabilities
178
- });
179
- const ready = {
180
- ...reservation,
181
- port: controller.port,
182
- url: controller.url,
183
- state: "ready"
184
- };
185
- if (!writeLock(ready)) throw new Error("lost daemon lock ownership during startup");
186
- let shuttingDown = false;
187
- const shutdown = async (exitCode = 0) => {
188
- if (shuttingDown) return;
189
- shuttingDown = true;
190
- if (opts.foreground) process.stdout.write("\n stopping tokmon web\u2026\n");
191
- try {
192
- await controller?.stop();
193
- } catch {
194
- }
195
- await flushDisk().catch(() => {
196
- });
197
- unlinkLock(ownerId);
198
- process.exit(exitCode);
199
- };
200
- process.once("exit", () => {
201
- unlinkLock(ownerId);
202
- });
203
- process.once("SIGINT", () => {
204
- void shutdown(0);
205
- });
206
- process.once("SIGTERM", () => {
207
- void shutdown(0);
208
- });
209
- if (opts.foreground) {
210
- process.stdout.write(`
211
- \u25C6 tokmon web \u2192 ${controller.url}
212
- `);
213
- process.stdout.write(" live dashboard \xB7 Ctrl-C to stop\n\n");
214
- if (config.allowNetworkAccess) {
215
- process.stdout.write(" \u26A0 unsafe network access enabled \u2014 dashboard is reachable from your LAN\n\n");
216
- }
217
- if (open) {
218
- openBrowser(controller.url);
219
- process.stdout.write(" opening browser\u2026\n");
220
- }
221
- } else {
222
- handshake(ready);
223
- }
224
- await new Promise(() => {
225
- });
226
- } catch (error) {
227
- try {
228
- await controller?.stop();
229
- } catch {
230
- }
231
- unlinkLock(ownerId);
232
- const message = `tokmon: failed to start web server: ${error.message}`;
233
- if (opts.foreground) {
234
- process.stderr.write(message + "\n");
235
- process.exitCode = 1;
236
- }
237
- }
238
- }
239
- export {
240
- runDaemon
241
- };
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- attachOrSpawn
4
- } from "./chunk-LKYOWBD4.js";
5
- import "./chunk-J3JW3RFP.js";
6
- import "./chunk-WUK3MQUB.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-6ZEW2M6P.js";
5
- import "./chunk-44ZSQEOS.js";
6
- import "./chunk-LCAHTRGP.js";
7
- import "./chunk-WUK3MQUB.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};