@carlonicora/nextjs-jsonapi 6.3.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZDUT5JPT.mjs → chunk-DYOSXIEL.mjs} +25 -20
- package/dist/chunk-DYOSXIEL.mjs.map +1 -0
- package/dist/{chunk-V4I3XKOM.js → chunk-ELQHE2DK.js} +25 -20
- package/dist/chunk-ELQHE2DK.js.map +1 -0
- package/dist/features/analytics/index.js +10 -10
- package/dist/features/analytics/index.mjs +1 -1
- package/dist/features/tokenusage/index.d.mts +123 -1
- package/dist/features/tokenusage/index.d.ts +123 -1
- package/dist/features/tokenusage/index.js +30 -27
- package/dist/features/tokenusage/index.js.map +1 -1
- package/dist/features/tokenusage/index.mjs +4 -1
- package/dist/features/tokenusage/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/features/tokenusage/index.ts +5 -0
- package/dist/chunk-V4I3XKOM.js.map +0 -1
- package/dist/chunk-ZDUT5JPT.mjs.map +0 -1
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
var _chunkELQHE2DKjs = require('../../chunk-ELQHE2DK.js');
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
|
|
@@ -365,7 +366,7 @@ var _lucidereact = require('lucide-react');
|
|
|
365
366
|
var ZERO = { cost: 0, credits: 0, tokensIn: 0, tokensOut: 0, cached: 0, calls: 0 };
|
|
366
367
|
function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }) {
|
|
367
368
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
368
|
-
const { decimal, metricValue: formatValue, currency, percent } =
|
|
369
|
+
const { decimal, metricValue: formatValue, currency, percent } = _chunkELQHE2DKjs.useUsageFormatters.call(void 0, );
|
|
369
370
|
const rowFor = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (scope, window) => _nullishCoalesce(summary.find((r) => r.scope === scope && r.window === window), () => ( ZERO)), "rowFor");
|
|
370
371
|
const customerCurrent = rowFor("customer", "current");
|
|
371
372
|
const customerPrevious = rowFor("customer", "previous");
|
|
@@ -374,7 +375,7 @@ function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }) {
|
|
|
374
375
|
const totalCurrent = rowFor("total", "current");
|
|
375
376
|
const totalPrevious = rowFor("total", "previous");
|
|
376
377
|
const averagePerCall = totalCurrent.calls ? totalCurrent.cost / totalCurrent.calls : 0;
|
|
377
|
-
const cacheHit =
|
|
378
|
+
const cacheHit = _chunkELQHE2DKjs.cacheHitPercentage.call(void 0, totalCurrent.cached, totalCurrent.tokensIn);
|
|
378
379
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-3", children: [
|
|
379
380
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunkXZCCIKX3js.cn.call(void 0, "grid gap-3", singleCustomerMode ? "sm:grid-cols-1" : "sm:grid-cols-2"), children: [
|
|
380
381
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -382,8 +383,8 @@ function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }) {
|
|
|
382
383
|
{
|
|
383
384
|
testId: "tile-customer",
|
|
384
385
|
label: t("token_usage.admin.customer_spend"),
|
|
385
|
-
value: formatValue(
|
|
386
|
-
delta:
|
|
386
|
+
value: formatValue(_chunkELQHE2DKjs.metricValue.call(void 0, customerCurrent, metric), metric),
|
|
387
|
+
delta: _chunkELQHE2DKjs.percentageDelta.call(void 0, _chunkELQHE2DKjs.metricValue.call(void 0, customerCurrent, metric), _chunkELQHE2DKjs.metricValue.call(void 0, customerPrevious, metric)),
|
|
387
388
|
previousLabel: t("token_usage.admin.vs_previous"),
|
|
388
389
|
decimal
|
|
389
390
|
}
|
|
@@ -393,8 +394,8 @@ function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }) {
|
|
|
393
394
|
{
|
|
394
395
|
testId: "tile-platform",
|
|
395
396
|
label: t("token_usage.admin.platform_spend"),
|
|
396
|
-
value: formatValue(
|
|
397
|
-
delta:
|
|
397
|
+
value: formatValue(_chunkELQHE2DKjs.metricValue.call(void 0, platformCurrent, metric), metric),
|
|
398
|
+
delta: _chunkELQHE2DKjs.percentageDelta.call(void 0, _chunkELQHE2DKjs.metricValue.call(void 0, platformCurrent, metric), _chunkELQHE2DKjs.metricValue.call(void 0, platformPrevious, metric)),
|
|
398
399
|
previousLabel: t("token_usage.admin.vs_previous"),
|
|
399
400
|
decimal
|
|
400
401
|
}
|
|
@@ -406,8 +407,8 @@ function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }) {
|
|
|
406
407
|
{
|
|
407
408
|
testId: "tile-total",
|
|
408
409
|
label: t("token_usage.admin.total_cost"),
|
|
409
|
-
value: formatValue(
|
|
410
|
-
delta:
|
|
410
|
+
value: formatValue(_chunkELQHE2DKjs.metricValue.call(void 0, totalCurrent, metric), metric),
|
|
411
|
+
delta: _chunkELQHE2DKjs.percentageDelta.call(void 0, _chunkELQHE2DKjs.metricValue.call(void 0, totalCurrent, metric), _chunkELQHE2DKjs.metricValue.call(void 0, totalPrevious, metric)),
|
|
411
412
|
decimal
|
|
412
413
|
}
|
|
413
414
|
),
|
|
@@ -502,10 +503,10 @@ _chunk7QVYU63Ejs.__name.call(void 0, Delta, "Delta");
|
|
|
502
503
|
|
|
503
504
|
function TokenUsageBreakdownTable({ rows, metric }) {
|
|
504
505
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
505
|
-
const { decimal, metricValue: formatValue, percent, compare } =
|
|
506
|
+
const { decimal, metricValue: formatValue, percent, compare } = _chunkELQHE2DKjs.useUsageFormatters.call(void 0, );
|
|
506
507
|
const [sort, setSort] = _react.useState.call(void 0, void 0);
|
|
507
508
|
const showActiveUsers = rows.some((row) => row.activeUsers !== void 0);
|
|
508
|
-
const total = _react.useMemo.call(void 0, () => rows.reduce((sum, row) => sum +
|
|
509
|
+
const total = _react.useMemo.call(void 0, () => rows.reduce((sum, row) => sum + _chunkELQHE2DKjs.metricValue.call(void 0, row, metric), 0), [rows, metric]);
|
|
509
510
|
const sortValue = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (row, key) => {
|
|
510
511
|
switch (key) {
|
|
511
512
|
case "label":
|
|
@@ -515,9 +516,9 @@ function TokenUsageBreakdownTable({ rows, metric }) {
|
|
|
515
516
|
case "activeUsers":
|
|
516
517
|
return _nullishCoalesce(row.activeUsers, () => ( 0));
|
|
517
518
|
case "cacheHit":
|
|
518
|
-
return
|
|
519
|
+
return _chunkELQHE2DKjs.cacheHitPercentage.call(void 0, row.cached, row.tokensIn);
|
|
519
520
|
case "share":
|
|
520
|
-
return
|
|
521
|
+
return _chunkELQHE2DKjs.metricValue.call(void 0, row, metric);
|
|
521
522
|
default:
|
|
522
523
|
return row[key];
|
|
523
524
|
}
|
|
@@ -572,7 +573,7 @@ function TokenUsageBreakdownTable({ rows, metric }) {
|
|
|
572
573
|
}
|
|
573
574
|
) }, column.key)) }) }),
|
|
574
575
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableBody, { children: sortedRows.map((row) => {
|
|
575
|
-
const value =
|
|
576
|
+
const value = _chunkELQHE2DKjs.metricValue.call(void 0, row, metric);
|
|
576
577
|
const share = total > 0 ? value / total * 100 : 0;
|
|
577
578
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkY7JIQNM6js.TableRow, { "data-testid": `breakdown-row-${row.id}`, children: [
|
|
578
579
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-xs", children: row.id === "other" ? t("token_usage.admin.other") : row.label }),
|
|
@@ -581,7 +582,7 @@ function TokenUsageBreakdownTable({ rows, metric }) {
|
|
|
581
582
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.calls, 0) }),
|
|
582
583
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.tokensIn, 0) }),
|
|
583
584
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.tokensOut, 0) }),
|
|
584
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: percent(
|
|
585
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: percent(_chunkELQHE2DKjs.cacheHitPercentage.call(void 0, row.cached, row.tokensIn)) }),
|
|
585
586
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: formatValue(row.cost, "cost") }),
|
|
586
587
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: formatValue(row.credits, "credits") }),
|
|
587
588
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.TableCell, { className: "text-end text-xs tabular-nums", children: percent(share) })
|
|
@@ -618,7 +619,7 @@ var operationDescription = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0,
|
|
|
618
619
|
|
|
619
620
|
function TokenUsageRankedBar({ rows, metric, emptyLabel, labelsAreOperationTypes = false }) {
|
|
620
621
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
621
|
-
const { metricValue: formatValue, percent } =
|
|
622
|
+
const { metricValue: formatValue, percent } = _chunkELQHE2DKjs.useUsageFormatters.call(void 0, );
|
|
622
623
|
const renderLabel = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (row) => {
|
|
623
624
|
if (row.id === "other") return t("token_usage.admin.other");
|
|
624
625
|
if (!labelsAreOperationTypes) return row.label;
|
|
@@ -656,13 +657,13 @@ function TokenUsageRankedBar({ rows, metric, emptyLabel, labelsAreOperationTypes
|
|
|
656
657
|
if (rows.length === 0) {
|
|
657
658
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-muted-foreground py-6 text-center text-sm", children: emptyLabel });
|
|
658
659
|
}
|
|
659
|
-
const values = rows.map((row) =>
|
|
660
|
+
const values = rows.map((row) => _chunkELQHE2DKjs.metricValue.call(void 0, row, metric));
|
|
660
661
|
const total = values.reduce((sum, value) => sum + value, 0);
|
|
661
662
|
const max = Math.max(...values, 0);
|
|
662
663
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "grid gap-0.5", children: rows.map((row, index) => {
|
|
663
664
|
const value = values[index];
|
|
664
665
|
const isOther = row.id === "other";
|
|
665
|
-
const step = isOther ?
|
|
666
|
+
const step = isOther ? _chunkELQHE2DKjs.SEQUENTIAL_RAMP.length - 1 : Math.min(index, _chunkELQHE2DKjs.SEQUENTIAL_RAMP.length - 1);
|
|
666
667
|
const width = max > 0 ? value / max * 100 : 0;
|
|
667
668
|
const share = total > 0 ? value / total * 100 : 0;
|
|
668
669
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-x-3 gap-y-0.5 py-0.5", children: [
|
|
@@ -674,7 +675,7 @@ function TokenUsageRankedBar({ rows, metric, emptyLabel, labelsAreOperationTypes
|
|
|
674
675
|
"data-testid": `ranked-fill-${row.id}`,
|
|
675
676
|
"data-ramp-step": String(step),
|
|
676
677
|
className: "h-full rounded-r-[4px]",
|
|
677
|
-
style: { width: `${width}%`, backgroundColor:
|
|
678
|
+
style: { width: `${width}%`, backgroundColor: _chunkELQHE2DKjs.SEQUENTIAL_RAMP[step] }
|
|
678
679
|
}
|
|
679
680
|
) })
|
|
680
681
|
] }),
|
|
@@ -724,7 +725,7 @@ var inferGranularity = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (buc
|
|
|
724
725
|
}, "inferGranularity");
|
|
725
726
|
function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
726
727
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
727
|
-
const { compact, bucketDate, metricValue: formatValue } =
|
|
728
|
+
const { compact, bucketDate, metricValue: formatValue } = _chunkELQHE2DKjs.useUsageFormatters.call(void 0, );
|
|
728
729
|
const { resolvedTheme } = _nextthemes.useTheme.call(void 0, );
|
|
729
730
|
const mode = resolvedTheme === "dark" ? "dark" : "light";
|
|
730
731
|
const { chartData, seriesKeys } = _react.useMemo.call(void 0, () => {
|
|
@@ -732,8 +733,8 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
|
732
733
|
const totals = /* @__PURE__ */ new Map();
|
|
733
734
|
for (const row of rows) totals.set(row.series, (_nullishCoalesce(totals.get(row.series), () => ( 0))) + metricValue2(row, metric));
|
|
734
735
|
const ranked = [...totals.entries()].sort((a, b) => b[1] - a[1]).map(([series]) => series);
|
|
735
|
-
const named = ranked.slice(0,
|
|
736
|
-
const folded = new Set(ranked.slice(
|
|
736
|
+
const named = ranked.slice(0, _chunkELQHE2DKjs.CATEGORICAL_CEILING);
|
|
737
|
+
const folded = new Set(ranked.slice(_chunkELQHE2DKjs.CATEGORICAL_CEILING));
|
|
737
738
|
const keys = folded.size > 0 ? [...named, OTHER_SERIES] : named;
|
|
738
739
|
const byBucket = /* @__PURE__ */ new Map();
|
|
739
740
|
for (const row of rows) {
|
|
@@ -773,7 +774,7 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
|
773
774
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: className ? `text-muted-foreground text-sm ${className}` : "text-muted-foreground text-sm", children: t.has(key) ? t(key) : "No data in the selected period" });
|
|
774
775
|
}
|
|
775
776
|
const granularity = inferGranularity(chartData.map((entry) => entry.bucket));
|
|
776
|
-
const seriesColorFor = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (series, index) => series === OTHER_SERIES ?
|
|
777
|
+
const seriesColorFor = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (series, index) => series === OTHER_SERIES ? _chunkELQHE2DKjs.OTHER_COLOR : _chunkELQHE2DKjs.seriesColor.call(void 0, index, mode), "seriesColorFor");
|
|
777
778
|
return (
|
|
778
779
|
// The chart is a coordinate system, not prose: recharts lays the axes and the
|
|
779
780
|
// stacked bars out left-to-right, so the whole chart stays an LTR island even
|
|
@@ -1175,7 +1176,7 @@ var useTokenUsageReport = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (
|
|
|
1175
1176
|
var ZERO2 = { cost: 0, credits: 0, tokensIn: 0, tokensOut: 0, cached: 0, calls: 0 };
|
|
1176
1177
|
function TokenUsageReportTiles({ summary, metric, balances }) {
|
|
1177
1178
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
1178
|
-
const { decimal, metricValue: formatValue } =
|
|
1179
|
+
const { decimal, metricValue: formatValue } = _chunkELQHE2DKjs.useUsageFormatters.call(void 0, );
|
|
1179
1180
|
const rowFor = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (window) => _nullishCoalesce(summary.find((row) => row.window === window), () => ( ZERO2)), "rowFor");
|
|
1180
1181
|
const current = rowFor("current");
|
|
1181
1182
|
const previous = rowFor("previous");
|
|
@@ -1185,13 +1186,13 @@ function TokenUsageReportTiles({ summary, metric, balances }) {
|
|
|
1185
1186
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-3", children: [
|
|
1186
1187
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7JIQNM6js.Card, { "data-testid": "tile-used", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkY7JIQNM6js.CardContent, { className: "grid gap-1", children: [
|
|
1187
1188
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.report.used_in_period") }),
|
|
1188
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-primary text-xl font-semibold tabular-nums", children: formatValue(
|
|
1189
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-primary text-xl font-semibold tabular-nums", children: formatValue(_chunkELQHE2DKjs.metricValue.call(void 0, current, metric), metric) }),
|
|
1189
1190
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-1", children: [
|
|
1190
1191
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1191
1192
|
Delta2,
|
|
1192
1193
|
{
|
|
1193
1194
|
testId: "tile-used-delta",
|
|
1194
|
-
delta:
|
|
1195
|
+
delta: _chunkELQHE2DKjs.percentageDelta.call(void 0, _chunkELQHE2DKjs.metricValue.call(void 0, current, metric), _chunkELQHE2DKjs.metricValue.call(void 0, previous, metric)),
|
|
1195
1196
|
decimal
|
|
1196
1197
|
}
|
|
1197
1198
|
),
|
|
@@ -1319,5 +1320,7 @@ _chunk7QVYU63Ejs.__name.call(void 0, TokenUsageReportContainer, "TokenUsageRepor
|
|
|
1319
1320
|
|
|
1320
1321
|
|
|
1321
1322
|
|
|
1322
|
-
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
exports.TOKEN_USAGE_ADMIN_I18N_KEYS = TOKEN_USAGE_ADMIN_I18N_KEYS; exports.TOKEN_USAGE_REPORT_I18N_KEYS = TOKEN_USAGE_REPORT_I18N_KEYS; exports.TokenUsageAdminBreakdown = _chunkXZCCIKX3js.TokenUsageAdminBreakdown; exports.TokenUsageAdminBreakdownModule = _chunkXZCCIKX3js.TokenUsageAdminBreakdownModule; exports.TokenUsageAdminContainer = TokenUsageAdminContainer; exports.TokenUsageAdminFilterBar = TokenUsageAdminFilterBar; exports.TokenUsageAdminProvider = TokenUsageAdminProvider; exports.TokenUsageAdminService = TokenUsageAdminService; exports.TokenUsageAdminSummary = _chunkXZCCIKX3js.TokenUsageAdminSummary; exports.TokenUsageAdminSummaryModule = _chunkXZCCIKX3js.TokenUsageAdminSummaryModule; exports.TokenUsageAdminTiles = TokenUsageAdminTiles; exports.TokenUsageAdminTimeline = _chunkXZCCIKX3js.TokenUsageAdminTimeline; exports.TokenUsageAdminTimelineModule = _chunkXZCCIKX3js.TokenUsageAdminTimelineModule; exports.TokenUsageBreakdownTable = TokenUsageBreakdownTable; exports.TokenUsageRankedBar = TokenUsageRankedBar; exports.TokenUsageReportBreakdown = _chunkXZCCIKX3js.TokenUsageReportBreakdown; exports.TokenUsageReportContainer = TokenUsageReportContainer; exports.TokenUsageReportFilterBar = TokenUsageReportFilterBar; exports.TokenUsageReportProvider = TokenUsageReportProvider; exports.TokenUsageReportService = TokenUsageReportService; exports.TokenUsageReportSummary = _chunkXZCCIKX3js.TokenUsageReportSummary; exports.TokenUsageReportTiles = TokenUsageReportTiles; exports.TokenUsageReportTimeline = _chunkXZCCIKX3js.TokenUsageReportTimeline; exports.TokenUsageTimelineChart = TokenUsageTimelineChart; exports.configureTokenUsage = _chunkXZCCIKX3js.configureTokenUsage; exports.createUsageFormatters = _chunkELQHE2DKjs.createUsageFormatters; exports.getTokenUsageCurrency = _chunkXZCCIKX3js.getTokenUsageCurrency; exports.seriesColor = _chunkELQHE2DKjs.seriesColor; exports.seriesTheme = _chunkELQHE2DKjs.seriesTheme; exports.tokenUsageModules = _chunkXZCCIKX3js.tokenUsageModules; exports.useTokenUsageAdmin = useTokenUsageAdmin; exports.useTokenUsageReport = useTokenUsageReport; exports.useUsageFormatters = _chunkELQHE2DKjs.useUsageFormatters;
|
|
1323
1326
|
//# sourceMappingURL=index.js.map
|