@carlonicora/nextjs-jsonapi 2.4.0 → 3.0.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/{BlockNoteEditor-7WGCH2KB.js → BlockNoteEditor-CDTU6DRN.js} +19 -19
- package/dist/{BlockNoteEditor-7WGCH2KB.js.map → BlockNoteEditor-CDTU6DRN.js.map} +1 -1
- package/dist/{BlockNoteEditor-GWAV5ESO.mjs → BlockNoteEditor-VVAY73V2.mjs} +4 -4
- package/dist/billing/index.d.mts +127 -46
- package/dist/billing/index.d.ts +127 -46
- package/dist/billing/index.js +1243 -1084
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +983 -824
- package/dist/billing/index.mjs.map +1 -1
- package/dist/{chunk-V66AZWPG.js → chunk-53B6NPGA.js} +278 -8
- package/dist/chunk-53B6NPGA.js.map +1 -0
- package/dist/{chunk-M2EGUO2F.mjs → chunk-J54546YC.mjs} +1608 -1419
- package/dist/chunk-J54546YC.mjs.map +1 -0
- package/dist/{chunk-TOKHHZSP.js → chunk-JKGEJGSD.js} +7 -7
- package/dist/{chunk-TOKHHZSP.js.map → chunk-JKGEJGSD.js.map} +1 -1
- package/dist/{chunk-3LVSA7IM.mjs → chunk-PHEFWL6L.mjs} +2 -2
- package/dist/{chunk-LCCRUWWY.mjs → chunk-TWXKAY34.mjs} +273 -3
- package/dist/chunk-TWXKAY34.mjs.map +1 -0
- package/dist/{chunk-GYGMEDVS.js → chunk-UGNLKDI6.js} +1012 -823
- package/dist/chunk-UGNLKDI6.js.map +1 -0
- package/dist/client/index.js +4 -4
- package/dist/client/index.mjs +3 -3
- package/dist/components/index.d.mts +16 -1
- package/dist/components/index.d.ts +16 -1
- package/dist/components/index.js +4 -4
- package/dist/components/index.mjs +3 -3
- package/dist/{tokenusage-admin.module-5wJ_tZTj.d.ts → config-BIjrg5wd.d.ts} +39 -1
- package/dist/{tokenusage-admin.module-DQVT4O4j.d.mts → config-BRUjtCd1.d.mts} +39 -1
- package/dist/contexts/index.js +4 -4
- package/dist/contexts/index.mjs +3 -3
- package/dist/core/index.d.mts +22 -3
- package/dist/core/index.d.ts +22 -3
- package/dist/core/index.js +12 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +11 -1
- package/dist/features/help/index.js +37 -37
- package/dist/features/help/index.mjs +3 -3
- package/dist/features/tokenusage/index.d.mts +413 -14
- package/dist/features/tokenusage/index.d.ts +413 -14
- package/dist/features/tokenusage/index.js +481 -120
- package/dist/features/tokenusage/index.js.map +1 -1
- package/dist/features/tokenusage/index.mjs +431 -70
- package/dist/features/tokenusage/index.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -2
- package/dist/server/index.js +3 -3
- package/dist/server/index.mjs +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +4 -0
- package/src/core/index.ts +10 -0
- package/src/core/registry/ModuleRegistry.ts +4 -0
- package/src/features/administration/components/AdminIndexContainer.tsx +1 -1
- package/src/features/administration/components/__tests__/AdminIndexContainer.spec.tsx +1 -1
- package/src/features/billing/contexts/PriceContext.tsx +202 -0
- package/src/features/billing/contexts/ProductContext.tsx +185 -0
- package/src/features/billing/contexts/__tests__/PriceContext.spec.tsx +89 -0
- package/src/features/billing/contexts/__tests__/ProductContext.spec.tsx +81 -0
- package/src/features/billing/contexts/index.ts +2 -1
- package/src/features/billing/i18n-keys.ts +88 -0
- package/src/features/billing/stripe-price/components/containers/PriceContainer.tsx +21 -0
- package/src/features/billing/stripe-price/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-price/components/details/PriceDetails.tsx +131 -0
- package/src/features/billing/stripe-price/components/details/index.ts +1 -0
- package/src/features/billing/stripe-price/components/forms/PriceArchiver.tsx +55 -0
- package/src/features/billing/stripe-price/components/forms/PriceEditor.tsx +307 -374
- package/src/features/billing/stripe-price/components/forms/index.ts +3 -1
- package/src/features/billing/stripe-price/components/index.ts +2 -0
- package/src/features/billing/stripe-price/components/lists/PricesList.tsx +49 -267
- package/src/features/billing/stripe-price/data/index.ts +1 -0
- package/src/features/billing/stripe-price/data/stripe-price.fields.ts +8 -0
- package/src/features/billing/stripe-price/hooks/useStripePriceTableStructure.tsx +119 -0
- package/src/features/billing/stripe-price/stripe-price.module.ts +5 -1
- package/src/features/billing/stripe-product/components/containers/ProductContainer.tsx +45 -0
- package/src/features/billing/stripe-product/components/containers/ProductsListContainer.tsx +27 -0
- package/src/features/billing/stripe-product/components/containers/index.ts +2 -2
- package/src/features/billing/stripe-product/components/details/ProductDetails.tsx +45 -0
- package/src/features/billing/stripe-product/components/details/index.ts +1 -0
- package/src/features/billing/stripe-product/components/forms/ProductArchiver.tsx +55 -0
- package/src/features/billing/stripe-product/components/forms/ProductEditor.tsx +92 -81
- package/src/features/billing/stripe-product/components/forms/index.ts +3 -1
- package/src/features/billing/stripe-product/components/index.ts +1 -0
- package/src/features/billing/stripe-product/components/lists/ProductsList.tsx +45 -187
- package/src/features/billing/stripe-product/data/index.ts +1 -0
- package/src/features/billing/stripe-product/data/stripe-product.fields.ts +6 -0
- package/src/features/billing/stripe-product/hooks/useStripeProductTableStructure.tsx +80 -0
- package/src/features/billing/stripe-product/stripe-product.module.ts +5 -1
- package/src/features/tokenusage/components/TokenUsageAdminContainer.tsx +20 -4
- package/src/features/tokenusage/components/TokenUsageAdminTiles.tsx +31 -18
- package/src/features/tokenusage/components/TokenUsageBreakdownTable.tsx +13 -13
- package/src/features/tokenusage/components/TokenUsageRankedBar.tsx +24 -7
- package/src/features/tokenusage/components/TokenUsageReportContainer.tsx +102 -0
- package/src/features/tokenusage/components/TokenUsageReportFilterBar.tsx +34 -0
- package/src/features/tokenusage/components/TokenUsageReportTiles.tsx +161 -0
- package/src/features/tokenusage/components/TokenUsageTimelineChart.tsx +15 -13
- package/src/features/tokenusage/components/__tests__/TokenUsageAdminTiles.spec.tsx +4 -2
- package/src/features/tokenusage/components/__tests__/TokenUsageRankedBar.spec.tsx +3 -1
- package/src/features/tokenusage/contexts/TokenUsageAdminContext.tsx +6 -3
- package/src/features/tokenusage/contexts/TokenUsageReportContext.tsx +199 -0
- package/src/features/tokenusage/data/TokenUsageReportService.ts +65 -0
- package/src/features/tokenusage/data/index.ts +9 -0
- package/src/features/tokenusage/data/tokenusage-report-breakdown.interface.ts +12 -0
- package/src/features/tokenusage/data/tokenusage-report-breakdown.ts +94 -0
- package/src/features/tokenusage/data/tokenusage-report-summary.interface.ts +12 -0
- package/src/features/tokenusage/data/tokenusage-report-summary.ts +87 -0
- package/src/features/tokenusage/data/tokenusage-report-timeline.interface.ts +13 -0
- package/src/features/tokenusage/data/tokenusage-report-timeline.ts +94 -0
- package/src/features/tokenusage/data/tokenusage-report.types.ts +51 -0
- package/src/features/tokenusage/i18n-keys.ts +28 -0
- package/src/features/tokenusage/index.ts +18 -0
- package/src/features/tokenusage/lib/config.ts +22 -0
- package/src/features/tokenusage/lib/formatters.ts +100 -0
- package/src/features/tokenusage/lib/metrics.ts +8 -26
- package/src/features/tokenusage/lib/palette.ts +41 -14
- package/src/features/tokenusage/tokenusage-admin.module.ts +4 -0
- package/src/features/tokenusage/tokenusage.modules.ts +40 -0
- package/src/shadcnui/ui/chart.tsx +30 -3
- package/dist/chunk-GYGMEDVS.js.map +0 -1
- package/dist/chunk-LCCRUWWY.mjs.map +0 -1
- package/dist/chunk-M2EGUO2F.mjs.map +0 -1
- package/dist/chunk-V66AZWPG.js.map +0 -1
- package/src/features/billing/contexts/BillingContext.tsx +0 -95
- package/src/features/billing/stripe-product/components/containers/ProductsAdminContainer.tsx +0 -98
- package/src/features/billing/stripe-product/components/containers/ProductsAdminPageContainer.tsx +0 -27
- /package/dist/{BlockNoteEditor-GWAV5ESO.mjs.map → BlockNoteEditor-VVAY73V2.mjs.map} +0 -0
- /package/dist/{chunk-3LVSA7IM.mjs.map → chunk-PHEFWL6L.mjs.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { A as ApiDataInterface, J as JsonApiHydratedDataInterface } from '../../ApiDataInterface-BcZeXy5X.mjs';
|
|
4
|
-
import { A as AbstractApiData } from '../../
|
|
5
|
-
export { b as TokenUsageAdminBreakdownModule, T as TokenUsageAdminSummaryModule, a as TokenUsageAdminTimelineModule } from '../../
|
|
4
|
+
import { A as AbstractApiData } from '../../config-BRUjtCd1.mjs';
|
|
5
|
+
export { b as TokenUsageAdminBreakdownModule, T as TokenUsageAdminSummaryModule, a as TokenUsageAdminTimelineModule, c as configureTokenUsage, g as getTokenUsageCurrency, t as tokenUsageModules } from '../../config-BRUjtCd1.mjs';
|
|
6
6
|
import { A as AbstractService } from '../../AbstractService-B0T7h8fX.mjs';
|
|
7
7
|
import '../../ApiRequestDataTypeInterface-CYEcRUrh.mjs';
|
|
8
8
|
import '../../types-Bq_UA8Lg.mjs';
|
|
@@ -142,6 +142,8 @@ type TokenUsageAdminProviderProps = {
|
|
|
142
142
|
initialTo?: string;
|
|
143
143
|
/** Rows per ranked panel. Defaults to 10. */
|
|
144
144
|
topN?: number;
|
|
145
|
+
/** Route the breadcrumb links back to. */
|
|
146
|
+
pageUrl?: string;
|
|
145
147
|
};
|
|
146
148
|
/**
|
|
147
149
|
* Owns every filter the administrative token-usage page reads, fetches the five
|
|
@@ -152,7 +154,7 @@ type TokenUsageAdminProviderProps = {
|
|
|
152
154
|
* `SharedContext`, and a descendant cannot inject nodes into an ancestor's
|
|
153
155
|
* provider value. That is why the filter state lives at this level.
|
|
154
156
|
*/
|
|
155
|
-
declare const TokenUsageAdminProvider: ({ children, initialCompanyId, initialFrom, initialTo, topN, }: TokenUsageAdminProviderProps) => React.JSX.Element;
|
|
157
|
+
declare const TokenUsageAdminProvider: ({ children, initialCompanyId, initialFrom, initialTo, topN, pageUrl, }: TokenUsageAdminProviderProps) => React.JSX.Element;
|
|
156
158
|
declare const useTokenUsageAdmin: () => TokenUsageAdminContextType;
|
|
157
159
|
|
|
158
160
|
/**
|
|
@@ -172,7 +174,7 @@ type FilterState = {
|
|
|
172
174
|
companyId?: string;
|
|
173
175
|
metric: Metric;
|
|
174
176
|
};
|
|
175
|
-
type Props$
|
|
177
|
+
type Props$6 = FilterState & {
|
|
176
178
|
companies: {
|
|
177
179
|
id: string;
|
|
178
180
|
label: string;
|
|
@@ -188,9 +190,9 @@ type Props$3 = FilterState & {
|
|
|
188
190
|
* what lets the page issue a single coordinated batch of requests instead of one
|
|
189
191
|
* per control.
|
|
190
192
|
*/
|
|
191
|
-
declare function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, onChange }: Props$
|
|
193
|
+
declare function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, onChange }: Props$6): React.JSX.Element;
|
|
192
194
|
|
|
193
|
-
type Props$
|
|
195
|
+
type Props$5 = {
|
|
194
196
|
/** The six summary rows: {customer, platform, total} × {current, previous}. */
|
|
195
197
|
summary: TokenUsageAdminSummaryInterface[];
|
|
196
198
|
metric: Metric;
|
|
@@ -207,13 +209,49 @@ type Props$2 = {
|
|
|
207
209
|
* The backend always returns both windows, which is why no tile has to branch on
|
|
208
210
|
* a missing row: an absent scope is simply zero-filled here.
|
|
209
211
|
*/
|
|
210
|
-
declare function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }: Props$
|
|
212
|
+
declare function TokenUsageAdminTiles({ summary, metric, singleCustomerMode }: Props$5): React.JSX.Element;
|
|
211
213
|
|
|
212
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Locale-free arithmetic for the token-usage surfaces.
|
|
216
|
+
*
|
|
217
|
+
* Everything that turns a number into a STRING lives in `./formatters` instead,
|
|
218
|
+
* because it depends on the request's locale and the app's configured currency.
|
|
219
|
+
* This file stays pure arithmetic so it needs neither.
|
|
220
|
+
*/
|
|
221
|
+
/**
|
|
222
|
+
* The metric field set every admin token-usage resource carries. Declared
|
|
223
|
+
* structurally so it accepts the summary, timeline and breakdown interfaces
|
|
224
|
+
* alike — all three expose exactly these getters.
|
|
225
|
+
*/
|
|
226
|
+
type TokenUsageMetrics = {
|
|
227
|
+
cost: number;
|
|
228
|
+
credits: number;
|
|
229
|
+
tokensIn: number;
|
|
230
|
+
tokensOut: number;
|
|
231
|
+
cached: number;
|
|
232
|
+
calls: number;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Everything this component actually reads from a row.
|
|
237
|
+
*
|
|
238
|
+
* Declared STRUCTURALLY rather than as one of the breakdown interfaces on
|
|
239
|
+
* purpose: the same list ranks administrative rows (which additionally carry
|
|
240
|
+
* activeUsers / monthlyCredits / availableMonthlyCredits) and self-service
|
|
241
|
+
* report rows (which do not). Narrowing this to the administrative interface
|
|
242
|
+
* would force every self-service caller into a cast, and duplicating the
|
|
243
|
+
* component would fork the ramp and the share arithmetic.
|
|
244
|
+
*/
|
|
245
|
+
type TokenUsageRankedRow = TokenUsageMetrics & {
|
|
246
|
+
/** Row identity; the literal "other" marks the folded tail. */
|
|
247
|
+
id: string;
|
|
248
|
+
label: string;
|
|
249
|
+
};
|
|
250
|
+
type Props$4 = {
|
|
213
251
|
/** Ranked rows, already ordered descending by the backend, "other" last. */
|
|
214
|
-
rows:
|
|
252
|
+
rows: TokenUsageRankedRow[];
|
|
215
253
|
metric: Metric;
|
|
216
|
-
/**
|
|
254
|
+
/** Copy shown when there is nothing to rank, already translated by the caller. */
|
|
217
255
|
emptyLabel: string;
|
|
218
256
|
/**
|
|
219
257
|
* Whether `row.label` is an operation TYPE (vocabulary the consuming app
|
|
@@ -236,9 +274,9 @@ type Props$1 = {
|
|
|
236
274
|
* There is exactly one series, so there is no legend: every bar is
|
|
237
275
|
* direct-labelled with its value and its share of the total.
|
|
238
276
|
*/
|
|
239
|
-
declare function TokenUsageRankedBar({ rows, metric, emptyLabel, labelsAreOperationTypes }: Props$
|
|
277
|
+
declare function TokenUsageRankedBar({ rows, metric, emptyLabel, labelsAreOperationTypes }: Props$4): React.JSX.Element;
|
|
240
278
|
|
|
241
|
-
type Props = {
|
|
279
|
+
type Props$3 = {
|
|
242
280
|
rows: TokenUsageAdminBreakdownInterface[];
|
|
243
281
|
metric: Metric;
|
|
244
282
|
};
|
|
@@ -249,7 +287,7 @@ type Props = {
|
|
|
249
287
|
* because the whole ranked set — top-N plus the "other" rollup — is already in
|
|
250
288
|
* memory, so a round trip would buy nothing.
|
|
251
289
|
*/
|
|
252
|
-
declare function TokenUsageBreakdownTable({ rows, metric }: Props): React.JSX.Element;
|
|
290
|
+
declare function TokenUsageBreakdownTable({ rows, metric }: Props$3): React.JSX.Element;
|
|
253
291
|
|
|
254
292
|
type TokenUsageTimelineChartProps = {
|
|
255
293
|
rows: TokenUsageAdminTimelineInterface[];
|
|
@@ -372,6 +410,188 @@ declare class TokenUsageAdminService extends AbstractService {
|
|
|
372
410
|
}): Promise<TokenUsageAdminBreakdownInterface[]>;
|
|
373
411
|
}
|
|
374
412
|
|
|
413
|
+
/** Metrics the self-service surface may request. `cost` is deliberately absent. */
|
|
414
|
+
type ReportMetric = "credits" | "tokens";
|
|
415
|
+
/** Dimensions the self-service breakdown can group by. */
|
|
416
|
+
type ReportDimension = "operation" | "target";
|
|
417
|
+
type TokenUsageReportFilters = {
|
|
418
|
+
/** ISO 8601 instant. */
|
|
419
|
+
from: string;
|
|
420
|
+
/** ISO 8601 instant. */
|
|
421
|
+
to: string;
|
|
422
|
+
};
|
|
423
|
+
type TokenUsageReportSummaryInput = {
|
|
424
|
+
id: string;
|
|
425
|
+
window: string;
|
|
426
|
+
cost: number;
|
|
427
|
+
credits: number;
|
|
428
|
+
tokensIn: number;
|
|
429
|
+
tokensOut: number;
|
|
430
|
+
cached: number;
|
|
431
|
+
calls: number;
|
|
432
|
+
};
|
|
433
|
+
type TokenUsageReportTimelineInput = {
|
|
434
|
+
id: string;
|
|
435
|
+
/** Backend field type is "date" — emitted via formatLocalDate, never raw. */
|
|
436
|
+
bucket: Date;
|
|
437
|
+
series: string;
|
|
438
|
+
cost: number;
|
|
439
|
+
credits: number;
|
|
440
|
+
tokensIn: number;
|
|
441
|
+
tokensOut: number;
|
|
442
|
+
cached: number;
|
|
443
|
+
calls: number;
|
|
444
|
+
};
|
|
445
|
+
type TokenUsageReportBreakdownInput = {
|
|
446
|
+
id: string;
|
|
447
|
+
label: string;
|
|
448
|
+
sublabel?: string;
|
|
449
|
+
cost: number;
|
|
450
|
+
credits: number;
|
|
451
|
+
tokensIn: number;
|
|
452
|
+
tokensOut: number;
|
|
453
|
+
cached: number;
|
|
454
|
+
calls: number;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
interface TokenUsageReportSummaryInterface extends ApiDataInterface {
|
|
458
|
+
/** "current" or "previous" — the equal-length preceding span. */
|
|
459
|
+
get window(): string;
|
|
460
|
+
get cost(): number;
|
|
461
|
+
get credits(): number;
|
|
462
|
+
get tokensIn(): number;
|
|
463
|
+
get tokensOut(): number;
|
|
464
|
+
get cached(): number;
|
|
465
|
+
get calls(): number;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* One row of the self-service summary: the caller's own company observed over
|
|
470
|
+
* one time window. Two rows are returned per request — "current" and the
|
|
471
|
+
* equal-length "previous" span — so the KPI tiles can render a value and its
|
|
472
|
+
* delta without a second call.
|
|
473
|
+
*
|
|
474
|
+
* There is no `scope` here: a company only ever sees itself, so the
|
|
475
|
+
* customer/platform split that the administrative summary carries is absent.
|
|
476
|
+
*/
|
|
477
|
+
declare class TokenUsageReportSummary extends AbstractApiData implements TokenUsageReportSummaryInterface {
|
|
478
|
+
private _window;
|
|
479
|
+
private _cost;
|
|
480
|
+
private _credits;
|
|
481
|
+
private _tokensIn;
|
|
482
|
+
private _tokensOut;
|
|
483
|
+
private _cached;
|
|
484
|
+
private _calls;
|
|
485
|
+
get window(): string;
|
|
486
|
+
get cost(): number;
|
|
487
|
+
get credits(): number;
|
|
488
|
+
get tokensIn(): number;
|
|
489
|
+
get tokensOut(): number;
|
|
490
|
+
get cached(): number;
|
|
491
|
+
get calls(): number;
|
|
492
|
+
rehydrate(data: JsonApiHydratedDataInterface): this;
|
|
493
|
+
createJsonApi(data: TokenUsageReportSummaryInput): any;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
interface TokenUsageReportTimelineInterface extends ApiDataInterface {
|
|
497
|
+
/** Backend declares this `type: "date"`, so it is a Date in memory. */
|
|
498
|
+
get bucket(): Date;
|
|
499
|
+
get series(): string;
|
|
500
|
+
get cost(): number;
|
|
501
|
+
get credits(): number;
|
|
502
|
+
get tokensIn(): number;
|
|
503
|
+
get tokensOut(): number;
|
|
504
|
+
get cached(): number;
|
|
505
|
+
get calls(): number;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* One (bucket, series) cell of the self-service usage-over-time chart. Rows
|
|
510
|
+
* arrive flat; the chart pivots them into stacked columns.
|
|
511
|
+
*/
|
|
512
|
+
declare class TokenUsageReportTimeline extends AbstractApiData implements TokenUsageReportTimelineInterface {
|
|
513
|
+
private _bucket;
|
|
514
|
+
private _series;
|
|
515
|
+
private _cost;
|
|
516
|
+
private _credits;
|
|
517
|
+
private _tokensIn;
|
|
518
|
+
private _tokensOut;
|
|
519
|
+
private _cached;
|
|
520
|
+
private _calls;
|
|
521
|
+
get bucket(): Date;
|
|
522
|
+
get series(): string;
|
|
523
|
+
get cost(): number;
|
|
524
|
+
get credits(): number;
|
|
525
|
+
get tokensIn(): number;
|
|
526
|
+
get tokensOut(): number;
|
|
527
|
+
get cached(): number;
|
|
528
|
+
get calls(): number;
|
|
529
|
+
rehydrate(data: JsonApiHydratedDataInterface): this;
|
|
530
|
+
createJsonApi(data: TokenUsageReportTimelineInput): any;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
interface TokenUsageReportBreakdownInterface extends ApiDataInterface {
|
|
534
|
+
get label(): string;
|
|
535
|
+
get sublabel(): string | undefined;
|
|
536
|
+
get cost(): number;
|
|
537
|
+
get credits(): number;
|
|
538
|
+
get tokensIn(): number;
|
|
539
|
+
get tokensOut(): number;
|
|
540
|
+
get cached(): number;
|
|
541
|
+
get calls(): number;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* One ranked row of a self-service breakdown. The same shape serves both
|
|
546
|
+
* dimensions — operation and target — which is why the two "by-X" panels
|
|
547
|
+
* collapse into a single `breakdown?dimension=` call.
|
|
548
|
+
*
|
|
549
|
+
* Deliberately narrower than the administrative row: no `activeUsers`,
|
|
550
|
+
* `monthlyCredits` or `availableMonthlyCredits`, which are company-fleet
|
|
551
|
+
* figures a single company has no business seeing.
|
|
552
|
+
*/
|
|
553
|
+
declare class TokenUsageReportBreakdown extends AbstractApiData implements TokenUsageReportBreakdownInterface {
|
|
554
|
+
private _label;
|
|
555
|
+
private _sublabel?;
|
|
556
|
+
private _cost;
|
|
557
|
+
private _credits;
|
|
558
|
+
private _tokensIn;
|
|
559
|
+
private _tokensOut;
|
|
560
|
+
private _cached;
|
|
561
|
+
private _calls;
|
|
562
|
+
get label(): string;
|
|
563
|
+
get sublabel(): string | undefined;
|
|
564
|
+
get cost(): number;
|
|
565
|
+
get credits(): number;
|
|
566
|
+
get tokensIn(): number;
|
|
567
|
+
get tokensOut(): number;
|
|
568
|
+
get cached(): number;
|
|
569
|
+
get calls(): number;
|
|
570
|
+
rehydrate(data: JsonApiHydratedDataInterface): this;
|
|
571
|
+
createJsonApi(data: TokenUsageReportBreakdownInput): any;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* The self-service token-usage endpoints.
|
|
576
|
+
*
|
|
577
|
+
* No companyId parameter anywhere: the backend scopes every query to the
|
|
578
|
+
* caller's own company through the CLS preamble, so there is nothing for the
|
|
579
|
+
* client to name. No `metric: "cost"` either — the controller rejects it.
|
|
580
|
+
*/
|
|
581
|
+
declare class TokenUsageReportService extends AbstractService {
|
|
582
|
+
/** Two rows: window "current" and "previous". */
|
|
583
|
+
static getSummary(filters: TokenUsageReportFilters): Promise<TokenUsageReportSummaryInterface[]>;
|
|
584
|
+
static getTimeline(params: TokenUsageReportFilters & {
|
|
585
|
+
granularity: "day";
|
|
586
|
+
}): Promise<TokenUsageReportTimelineInterface[]>;
|
|
587
|
+
static getBreakdown(params: TokenUsageReportFilters & {
|
|
588
|
+
dimension: ReportDimension;
|
|
589
|
+
targetLabel?: string;
|
|
590
|
+
metric: ReportMetric;
|
|
591
|
+
limit?: number;
|
|
592
|
+
}): Promise<TokenUsageReportBreakdownInterface[]>;
|
|
593
|
+
}
|
|
594
|
+
|
|
375
595
|
/**
|
|
376
596
|
* The fixed namespace of i18n keys the administrative token-usage feature reads
|
|
377
597
|
* via useTranslations/getTranslations. Consuming apps must define each entry in
|
|
@@ -384,5 +604,184 @@ declare class TokenUsageAdminService extends AbstractService {
|
|
|
384
604
|
* app has no entry, so that namespace stays the app's own vocabulary.
|
|
385
605
|
*/
|
|
386
606
|
declare const TOKEN_USAGE_ADMIN_I18N_KEYS: readonly ["token_usage.admin.title", "token_usage.admin.customer_spend", "token_usage.admin.platform_spend", "token_usage.admin.total_cost", "token_usage.admin.avg_per_call", "token_usage.admin.cache_hit", "token_usage.admin.vs_previous", "token_usage.admin.usage_over_time", "token_usage.admin.by_company", "token_usage.admin.by_user", "token_usage.admin.customer_by_operation", "token_usage.admin.platform_by_operation", "token_usage.admin.detail", "token_usage.admin.other", "token_usage.admin.no_data", "token_usage.admin.all_companies", "token_usage.admin.granularity.label", "token_usage.admin.granularity.day", "token_usage.admin.granularity.week", "token_usage.admin.granularity.month", "token_usage.admin.metric.label", "token_usage.admin.metric.cost", "token_usage.admin.metric.credits", "token_usage.admin.metric.tokens", "token_usage.admin.stack_by", "token_usage.admin.stack.scope", "token_usage.admin.stack.type", "token_usage.admin.stack.company", "token_usage.admin.columns.label", "token_usage.admin.columns.sublabel", "token_usage.admin.columns.calls", "token_usage.admin.columns.tokens_in", "token_usage.admin.columns.tokens_out", "token_usage.admin.columns.cost", "token_usage.admin.columns.credits", "token_usage.admin.columns.share", "token_usage.admin.columns.active_users", "token_usage.series.other", "token_usage.timeline.empty"];
|
|
607
|
+
/**
|
|
608
|
+
* The fixed namespace of i18n keys the self-service token-usage feature reads.
|
|
609
|
+
* Consuming apps must define each entry in their messages/<locale>.json — this
|
|
610
|
+
* list is the contract between the package and the app.
|
|
611
|
+
*
|
|
612
|
+
* The target panel's title is NOT listed: its key is supplied per app through
|
|
613
|
+
* the provider's `targetPanelTitleKey`, because what usage is attributed to is
|
|
614
|
+
* application-specific. Operation labels resolve through
|
|
615
|
+
* `token_usage.types.<camelCase>` with the raw key as fallback, so that
|
|
616
|
+
* namespace stays the app's own vocabulary.
|
|
617
|
+
*/
|
|
618
|
+
declare const TOKEN_USAGE_REPORT_I18N_KEYS: readonly ["token_usage.report.title", "token_usage.report.used_in_period", "token_usage.report.vs_previous", "token_usage.report.monthly_left", "token_usage.report.extra_credits", "token_usage.report.calls", "token_usage.report.usage_over_time", "token_usage.report.by_operation", "token_usage.report.no_data"];
|
|
619
|
+
|
|
620
|
+
type TokenUsageReportFilterState = {
|
|
621
|
+
/** ISO 8601 instant. */
|
|
622
|
+
from: string;
|
|
623
|
+
/** ISO 8601 instant. */
|
|
624
|
+
to: string;
|
|
625
|
+
};
|
|
626
|
+
interface TokenUsageReportContextType {
|
|
627
|
+
summary: TokenUsageReportSummaryInterface[];
|
|
628
|
+
timeline: TokenUsageReportTimelineInterface[];
|
|
629
|
+
byOperation: TokenUsageReportBreakdownInterface[];
|
|
630
|
+
/** Empty unless the host app declared a targetLabel. */
|
|
631
|
+
byTarget: TokenUsageReportBreakdownInterface[];
|
|
632
|
+
/** i18n key for the target panel's title; undefined when the host set no targetLabel. */
|
|
633
|
+
targetPanelTitleKey?: string;
|
|
634
|
+
filters: TokenUsageReportFilterState;
|
|
635
|
+
/** Merges a partial patch into the current filters; every key is optional. */
|
|
636
|
+
setFilters: (next: Partial<TokenUsageReportFilterState>) => void;
|
|
637
|
+
isLoading: boolean;
|
|
638
|
+
error: string | null;
|
|
639
|
+
}
|
|
640
|
+
type TokenUsageReportProviderProps = {
|
|
641
|
+
children: ReactNode;
|
|
642
|
+
/**
|
|
643
|
+
* The Neo4j label the "by target" panel groups by, e.g. "Campaign". The set of
|
|
644
|
+
* things usage can be attributed to is application-specific, so the package
|
|
645
|
+
* cannot pick one — omit it and the panel is skipped rather than rendered
|
|
646
|
+
* empty, and no request is issued.
|
|
647
|
+
*/
|
|
648
|
+
targetLabel?: string;
|
|
649
|
+
/** i18n key for the target panel's title. Required when targetLabel is set. */
|
|
650
|
+
targetPanelTitleKey?: string;
|
|
651
|
+
/** ISO 8601 instant. Defaults to the start of the current month. */
|
|
652
|
+
initialFrom?: string;
|
|
653
|
+
/** ISO 8601 instant. Defaults to now. */
|
|
654
|
+
initialTo?: string;
|
|
655
|
+
/** Rows per ranked panel. Defaults to 10. */
|
|
656
|
+
topN?: number;
|
|
657
|
+
/** Route the breadcrumb links back to. */
|
|
658
|
+
pageUrl?: string;
|
|
659
|
+
};
|
|
660
|
+
/**
|
|
661
|
+
* Owns the date range of the self-service token-usage page, fetches the three
|
|
662
|
+
* panels behind it, and publishes the filter bar into the page title bar.
|
|
663
|
+
*
|
|
664
|
+
* The filter bar is rendered into `title.functions` here — NOT in the container —
|
|
665
|
+
* because `RoundPageContainer`'s title bar reads `title.functions` from
|
|
666
|
+
* `SharedContext`, and a descendant cannot inject nodes into an ancestor's
|
|
667
|
+
* provider value. That is why the filter state lives at this level.
|
|
668
|
+
*/
|
|
669
|
+
declare const TokenUsageReportProvider: ({ children, targetLabel, targetPanelTitleKey, initialFrom, initialTo, topN, pageUrl, }: TokenUsageReportProviderProps) => React.JSX.Element;
|
|
670
|
+
declare const useTokenUsageReport: () => TokenUsageReportContextType;
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* The caller's own credit position, as the host app reads it from its
|
|
674
|
+
* CurrentUserContext. The package has no access to that context, so the numbers
|
|
675
|
+
* arrive as a prop.
|
|
676
|
+
*/
|
|
677
|
+
type TokenUsageBalances = {
|
|
678
|
+
monthlyCredits: number;
|
|
679
|
+
availableMonthlyCredits: number;
|
|
680
|
+
availableExtraCredits: number;
|
|
681
|
+
};
|
|
682
|
+
type Props$2 = {
|
|
683
|
+
/** Two rows: window "current" and "previous". */
|
|
684
|
+
summary: TokenUsageReportSummaryInterface[];
|
|
685
|
+
metric: ReportMetric;
|
|
686
|
+
/** The caller's own balances, read from CurrentUserContext by the container. */
|
|
687
|
+
balances: TokenUsageBalances | null;
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* The KPI header of the self-service token-usage page.
|
|
691
|
+
*
|
|
692
|
+
* One lead tile carries the number the page exists to answer — how much was
|
|
693
|
+
* spent in the period — with its delta against the equal-length preceding
|
|
694
|
+
* window. Three supporting tiles give it context: what is left this month, what
|
|
695
|
+
* extra sits behind that, and how many calls produced the spend.
|
|
696
|
+
*
|
|
697
|
+
* Credits are fractional. Customer-facing BALANCES are floored to whole credits
|
|
698
|
+
* (Math.max(0, Math.floor(v))) so nobody is told they have 715.4 of something
|
|
699
|
+
* indivisible; the percentage arithmetic behind the colour keeps the raw floats.
|
|
700
|
+
* Spend is NOT floored — it is a measurement, not a wallet.
|
|
701
|
+
*/
|
|
702
|
+
declare function TokenUsageReportTiles({ summary, metric, balances }: Props$2): React.JSX.Element;
|
|
703
|
+
|
|
704
|
+
type Props$1 = {
|
|
705
|
+
/**
|
|
706
|
+
* The caller's own credit balances. Supplied by the host app, which reads them
|
|
707
|
+
* from its CurrentUserContext — the package has no access to that context.
|
|
708
|
+
*/
|
|
709
|
+
balances?: TokenUsageBalances | null;
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* Page body for the self-service token-usage dashboard.
|
|
713
|
+
*
|
|
714
|
+
* Stateless by design — every value comes from useTokenUsageReport(). The filter
|
|
715
|
+
* bar is deliberately NOT here: it belongs to the page title bar, which
|
|
716
|
+
* RoundPageContainer fills from SharedContext, so the provider publishes it.
|
|
717
|
+
*
|
|
718
|
+
* The timeline and the ranked bars are the PACKAGE'S EXISTING components, used
|
|
719
|
+
* verbatim. They take the same six metric getters the report interfaces were
|
|
720
|
+
* given, which is what makes that reuse possible.
|
|
721
|
+
*/
|
|
722
|
+
declare function TokenUsageReportContainer({ balances }: Props$1): React.JSX.Element;
|
|
723
|
+
|
|
724
|
+
type Props = {
|
|
725
|
+
/** Receives ONLY the keys that changed. */
|
|
726
|
+
onChange: (next: {
|
|
727
|
+
from?: string;
|
|
728
|
+
to?: string;
|
|
729
|
+
}) => void;
|
|
730
|
+
};
|
|
731
|
+
/**
|
|
732
|
+
* The single control row above the KPI tiles.
|
|
733
|
+
*
|
|
734
|
+
* Deliberately stateless: the control reports the keys it changed and the owning
|
|
735
|
+
* context re-fetches, which is what lets the page issue a single coordinated
|
|
736
|
+
* batch of requests instead of one per control.
|
|
737
|
+
*
|
|
738
|
+
* There is NO metric selector. A game master is billed in credits, so credits
|
|
739
|
+
* are the only unit this surface speaks: cost would leak platform margin (the
|
|
740
|
+
* controller rejects metric=cost outright) and a raw token count is an
|
|
741
|
+
* implementation detail nobody is charged for. There is no company selector
|
|
742
|
+
* either — a self-service caller has exactly one company.
|
|
743
|
+
*/
|
|
744
|
+
declare function TokenUsageReportFilterBar({ onChange }: Props): React.JSX.Element;
|
|
745
|
+
|
|
746
|
+
type UsageFormatters = {
|
|
747
|
+
/** Locale-aware fixed-decimal number, e.g. 9.46 → "9,46" in it-IT. */
|
|
748
|
+
decimal(value: number, decimals: number): string;
|
|
749
|
+
/** Currency for cost, 2 decimals for credits, whole numbers for tokens. */
|
|
750
|
+
metricValue(value: number, metric: Metric): string;
|
|
751
|
+
/** Currency with an explicit decimal count — the per-call tile needs 4. */
|
|
752
|
+
currency(value: number, decimals: number): string;
|
|
753
|
+
/** Percentage with one decimal by default, e.g. 60 → "60,0 %" in it-IT. */
|
|
754
|
+
percent(value: number, decimals?: number): string;
|
|
755
|
+
/** Compact notation for axis ticks, e.g. 1500000 → "1,5 Mln" in it-IT. */
|
|
756
|
+
compact(value: number): string;
|
|
757
|
+
/** A "YYYY-MM-DD" bucket key rendered as an axis or tooltip label, in UTC. */
|
|
758
|
+
bucketDate(iso: string, granularity: "day" | "week" | "month"): string;
|
|
759
|
+
/** Locale collation for client-side table sorting. */
|
|
760
|
+
compare(a: string, b: string): number;
|
|
761
|
+
};
|
|
762
|
+
/**
|
|
763
|
+
* Builds every formatter the token-usage surfaces need, for one locale and one
|
|
764
|
+
* currency.
|
|
765
|
+
*
|
|
766
|
+
* A pure factory on purpose: it takes no React context, so the arithmetic and
|
|
767
|
+
* the formatting are unit-testable without rendering, and a server component or
|
|
768
|
+
* a test can construct a set for an arbitrary locale.
|
|
769
|
+
*
|
|
770
|
+
* The currency symbol is placed with a space rather than through
|
|
771
|
+
* `style: "currency"`, which is what the previous hard-coded implementation
|
|
772
|
+
* rendered ("€ 9,46"). Keeping that shape means a consuming app on EUR sees
|
|
773
|
+
* byte-identical output after this refactor.
|
|
774
|
+
*
|
|
775
|
+
* `bucketDate` formats in UTC, always. The wire value is a `type: "date"` — a
|
|
776
|
+
* calendar day — parsed to UTC midnight; reading it back with local getters
|
|
777
|
+
* would shift the label a day early west of UTC.
|
|
778
|
+
*/
|
|
779
|
+
declare function createUsageFormatters(locale: string, currency: string): UsageFormatters;
|
|
780
|
+
/**
|
|
781
|
+
* The formatter set for the current request's locale and the app's configured
|
|
782
|
+
* currency. Memoised on both, so the Intl objects are built once per locale
|
|
783
|
+
* rather than on every render.
|
|
784
|
+
*/
|
|
785
|
+
declare function useUsageFormatters(): UsageFormatters;
|
|
387
786
|
|
|
388
|
-
export { type Dimension, type Granularity, type Metric, type Scope, type StackBy, TOKEN_USAGE_ADMIN_I18N_KEYS, TokenUsageAdminBreakdown, type TokenUsageAdminBreakdownInput, type TokenUsageAdminBreakdownInterface, TokenUsageAdminContainer, type TokenUsageAdminContextType, TokenUsageAdminFilterBar, type TokenUsageAdminFilterState, type TokenUsageAdminFilters, TokenUsageAdminProvider, TokenUsageAdminService, TokenUsageAdminSummary, type TokenUsageAdminSummaryInput, type TokenUsageAdminSummaryInterface, TokenUsageAdminTiles, TokenUsageAdminTimeline, type TokenUsageAdminTimelineInput, type TokenUsageAdminTimelineInterface, TokenUsageBreakdownTable, TokenUsageRankedBar, TokenUsageTimelineChart, useTokenUsageAdmin };
|
|
787
|
+
export { type Dimension, type Granularity, type Metric, type ReportDimension, type ReportMetric, type Scope, type StackBy, TOKEN_USAGE_ADMIN_I18N_KEYS, TOKEN_USAGE_REPORT_I18N_KEYS, TokenUsageAdminBreakdown, type TokenUsageAdminBreakdownInput, type TokenUsageAdminBreakdownInterface, TokenUsageAdminContainer, type TokenUsageAdminContextType, TokenUsageAdminFilterBar, type TokenUsageAdminFilterState, type TokenUsageAdminFilters, TokenUsageAdminProvider, TokenUsageAdminService, TokenUsageAdminSummary, type TokenUsageAdminSummaryInput, type TokenUsageAdminSummaryInterface, TokenUsageAdminTiles, TokenUsageAdminTimeline, type TokenUsageAdminTimelineInput, type TokenUsageAdminTimelineInterface, type TokenUsageBalances, TokenUsageBreakdownTable, TokenUsageRankedBar, TokenUsageReportBreakdown, type TokenUsageReportBreakdownInput, type TokenUsageReportBreakdownInterface, TokenUsageReportContainer, type TokenUsageReportContextType, TokenUsageReportFilterBar, type TokenUsageReportFilterState, type TokenUsageReportFilters, TokenUsageReportProvider, TokenUsageReportService, TokenUsageReportSummary, type TokenUsageReportSummaryInput, type TokenUsageReportSummaryInterface, TokenUsageReportTiles, TokenUsageReportTimeline, type TokenUsageReportTimelineInput, type TokenUsageReportTimelineInterface, TokenUsageTimelineChart, type UsageFormatters, createUsageFormatters, useTokenUsageAdmin, useTokenUsageReport, useUsageFormatters };
|