@laoyuehanni/dsh-token-usage 0.3.7
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/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh.md +182 -0
- package/cordis.patch.yml +7 -0
- package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
- package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
- package/lib/client/CostDeltaFlyLabel.js +24 -0
- package/lib/client/CostDeltaFlyLabel.js.map +1 -0
- package/lib/client/HitRateText.d.ts +21 -0
- package/lib/client/HitRateText.d.ts.map +1 -0
- package/lib/client/HitRateText.js +16 -0
- package/lib/client/HitRateText.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +70 -0
- package/lib/client/QuotaButton.d.ts.map +1 -0
- package/lib/client/QuotaButton.js +346 -0
- package/lib/client/QuotaButton.js.map +1 -0
- package/lib/client/SessionStatsChip.d.ts +47 -0
- package/lib/client/SessionStatsChip.d.ts.map +1 -0
- package/lib/client/SessionStatsChip.js +141 -0
- package/lib/client/SessionStatsChip.js.map +1 -0
- package/lib/client/StatCard.d.ts +26 -0
- package/lib/client/StatCard.d.ts.map +1 -0
- package/lib/client/StatCard.js +10 -0
- package/lib/client/StatCard.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts +41 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -0
- package/lib/client/TokenUsageCard.js +164 -0
- package/lib/client/TokenUsageCard.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +32 -0
- package/lib/client/TokenUsageSection.d.ts.map +1 -0
- package/lib/client/TokenUsageSection.js +266 -0
- package/lib/client/TokenUsageSection.js.map +1 -0
- package/lib/client/TrendChart.d.ts +53 -0
- package/lib/client/TrendChart.d.ts.map +1 -0
- package/lib/client/TrendChart.js +141 -0
- package/lib/client/TrendChart.js.map +1 -0
- package/lib/client/UsageView.d.ts +42 -0
- package/lib/client/UsageView.d.ts.map +1 -0
- package/lib/client/UsageView.js +158 -0
- package/lib/client/UsageView.js.map +1 -0
- package/lib/client/async-resource.d.ts +54 -0
- package/lib/client/async-resource.d.ts.map +1 -0
- package/lib/client/async-resource.js +90 -0
- package/lib/client/async-resource.js.map +1 -0
- package/lib/client/card-form.d.ts +171 -0
- package/lib/client/card-form.d.ts.map +1 -0
- package/lib/client/card-form.js +300 -0
- package/lib/client/card-form.js.map +1 -0
- package/lib/client/cost-inflate-motion.d.ts +17 -0
- package/lib/client/cost-inflate-motion.d.ts.map +1 -0
- package/lib/client/cost-inflate-motion.js +61 -0
- package/lib/client/cost-inflate-motion.js.map +1 -0
- package/lib/client/cost-inflate.d.ts +28 -0
- package/lib/client/cost-inflate.d.ts.map +1 -0
- package/lib/client/cost-inflate.js +49 -0
- package/lib/client/cost-inflate.js.map +1 -0
- package/lib/client/day.d.ts +49 -0
- package/lib/client/day.d.ts.map +1 -0
- package/lib/client/day.js +84 -0
- package/lib/client/day.js.map +1 -0
- package/lib/client/format.d.ts +120 -0
- package/lib/client/format.d.ts.map +1 -0
- package/lib/client/format.js +163 -0
- package/lib/client/format.js.map +1 -0
- package/lib/client/index.d.ts +26 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +131 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/locales.d.ts +131 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/locales.js +230 -0
- package/lib/client/locales.js.map +1 -0
- package/lib/client/quota-format.d.ts +69 -0
- package/lib/client/quota-format.d.ts.map +1 -0
- package/lib/client/quota-format.js +147 -0
- package/lib/client/quota-format.js.map +1 -0
- package/lib/client/session-stats.d.ts +105 -0
- package/lib/client/session-stats.d.ts.map +1 -0
- package/lib/client/session-stats.js +142 -0
- package/lib/client/session-stats.js.map +1 -0
- package/lib/client/trend-chart/axis.d.ts +21 -0
- package/lib/client/trend-chart/axis.d.ts.map +1 -0
- package/lib/client/trend-chart/axis.js +33 -0
- package/lib/client/trend-chart/axis.js.map +1 -0
- package/lib/client/trend-chart/bucket.d.ts +24 -0
- package/lib/client/trend-chart/bucket.d.ts.map +1 -0
- package/lib/client/trend-chart/bucket.js +28 -0
- package/lib/client/trend-chart/bucket.js.map +1 -0
- package/lib/client/trend-chart/index.d.ts +12 -0
- package/lib/client/trend-chart/index.d.ts.map +1 -0
- package/lib/client/trend-chart/index.js +9 -0
- package/lib/client/trend-chart/index.js.map +1 -0
- package/lib/client/trend-chart/points.d.ts +46 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -0
- package/lib/client/trend-chart/points.js +82 -0
- package/lib/client/trend-chart/points.js.map +1 -0
- package/lib/client/trend-chart/scale.d.ts +47 -0
- package/lib/client/trend-chart/scale.d.ts.map +1 -0
- package/lib/client/trend-chart/scale.js +75 -0
- package/lib/client/trend-chart/scale.js.map +1 -0
- package/lib/client/use-color-scheme.d.ts +18 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -0
- package/lib/client/use-color-scheme.js +37 -0
- package/lib/client/use-color-scheme.js.map +1 -0
- package/lib/client/use-cost-inflate.d.ts +33 -0
- package/lib/client/use-cost-inflate.d.ts.map +1 -0
- package/lib/client/use-cost-inflate.js +108 -0
- package/lib/client/use-cost-inflate.js.map +1 -0
- package/lib/client.js +3892 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +599 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +60 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +126 -0
- package/lib/migrate.js.map +1 -0
- package/lib/pricing.d.ts +212 -0
- package/lib/pricing.d.ts.map +1 -0
- package/lib/pricing.js +492 -0
- package/lib/pricing.js.map +1 -0
- package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
- package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
- package/lib/quota/adapters/deepseek-balance.js +76 -0
- package/lib/quota/adapters/deepseek-balance.js.map +1 -0
- package/lib/quota/adapters/kimi.d.ts +26 -0
- package/lib/quota/adapters/kimi.d.ts.map +1 -0
- package/lib/quota/adapters/kimi.js +91 -0
- package/lib/quota/adapters/kimi.js.map +1 -0
- package/lib/quota/adapters/minimax.d.ts +24 -0
- package/lib/quota/adapters/minimax.d.ts.map +1 -0
- package/lib/quota/adapters/minimax.js +136 -0
- package/lib/quota/adapters/minimax.js.map +1 -0
- package/lib/quota/adapters/opencode-go.d.ts +25 -0
- package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
- package/lib/quota/adapters/opencode-go.js +105 -0
- package/lib/quota/adapters/opencode-go.js.map +1 -0
- package/lib/quota/adapters/openrouter.d.ts +15 -0
- package/lib/quota/adapters/openrouter.d.ts.map +1 -0
- package/lib/quota/adapters/openrouter.js +54 -0
- package/lib/quota/adapters/openrouter.js.map +1 -0
- package/lib/quota/adapters/zhipu.d.ts +38 -0
- package/lib/quota/adapters/zhipu.d.ts.map +1 -0
- package/lib/quota/adapters/zhipu.js +246 -0
- package/lib/quota/adapters/zhipu.js.map +1 -0
- package/lib/quota/credentials.d.ts +79 -0
- package/lib/quota/credentials.d.ts.map +1 -0
- package/lib/quota/credentials.js +130 -0
- package/lib/quota/credentials.js.map +1 -0
- package/lib/quota/http.d.ts +49 -0
- package/lib/quota/http.d.ts.map +1 -0
- package/lib/quota/http.js +114 -0
- package/lib/quota/http.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +45 -0
- package/lib/quota/provider-tracking.d.ts.map +1 -0
- package/lib/quota/provider-tracking.js +52 -0
- package/lib/quota/provider-tracking.js.map +1 -0
- package/lib/quota/quota-route.d.ts +22 -0
- package/lib/quota/quota-route.d.ts.map +1 -0
- package/lib/quota/quota-route.js +57 -0
- package/lib/quota/quota-route.js.map +1 -0
- package/lib/quota/quota-service.d.ts +54 -0
- package/lib/quota/quota-service.d.ts.map +1 -0
- package/lib/quota/quota-service.js +171 -0
- package/lib/quota/quota-service.js.map +1 -0
- package/lib/quota/registry.d.ts +24 -0
- package/lib/quota/registry.d.ts.map +1 -0
- package/lib/quota/registry.js +38 -0
- package/lib/quota/registry.js.map +1 -0
- package/lib/quota/types.d.ts +79 -0
- package/lib/quota/types.d.ts.map +1 -0
- package/lib/quota/types.js +24 -0
- package/lib/quota/types.js.map +1 -0
- package/lib/record-cache.d.ts +38 -0
- package/lib/record-cache.d.ts.map +1 -0
- package/lib/record-cache.js +143 -0
- package/lib/record-cache.js.map +1 -0
- package/lib/rollup.d.ts +52 -0
- package/lib/rollup.d.ts.map +1 -0
- package/lib/rollup.js +117 -0
- package/lib/rollup.js.map +1 -0
- package/lib/stats-route.d.ts +88 -0
- package/lib/stats-route.d.ts.map +1 -0
- package/lib/stats-route.js +313 -0
- package/lib/stats-route.js.map +1 -0
- package/lib/stats.d.ts +158 -0
- package/lib/stats.d.ts.map +1 -0
- package/lib/stats.js +426 -0
- package/lib/stats.js.map +1 -0
- package/lib/sync-state.d.ts +27 -0
- package/lib/sync-state.d.ts.map +1 -0
- package/lib/sync-state.js +56 -0
- package/lib/sync-state.js.map +1 -0
- package/lib/sync.d.ts +74 -0
- package/lib/sync.d.ts.map +1 -0
- package/lib/sync.js +64 -0
- package/lib/sync.js.map +1 -0
- package/lib/trend-bucket.d.ts +48 -0
- package/lib/trend-bucket.d.ts.map +1 -0
- package/lib/trend-bucket.js +87 -0
- package/lib/trend-bucket.js.map +1 -0
- package/lib/usage-log.d.ts +64 -0
- package/lib/usage-log.d.ts.map +1 -0
- package/lib/usage-log.js +144 -0
- package/lib/usage-log.js.map +1 -0
- package/lib/usage-record.d.ts +59 -0
- package/lib/usage-record.d.ts.map +1 -0
- package/lib/usage-record.js +115 -0
- package/lib/usage-record.js.map +1 -0
- package/lib/wire.d.ts +452 -0
- package/lib/wire.d.ts.map +1 -0
- package/lib/wire.js +144 -0
- package/lib/wire.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-inflate.js","sourceRoot":"","sources":["../../src/client/cost-inflate.ts"],"names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AA;IACnD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,CAAA;IACjD,OAAO,OAAO,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,CAAC,CAAA;AAC1C,CAAC;AAWD,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,QAAQ,CAAC,CAAS;IAChC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACjD,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG;QACzC,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;QACvC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;KACrD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side day vocabulary of the token-usage settings page: local day
|
|
3
|
+
* keys, quick-range arithmetic, and the zero-filled per-day series backing
|
|
4
|
+
* the trend chart. Pure functions only, so the chart and its tests share one
|
|
5
|
+
* implementation.
|
|
6
|
+
*
|
|
7
|
+
* @module token-usage/client/day
|
|
8
|
+
*/
|
|
9
|
+
import type { UsageDayRow, UsageHourRow, UsageTotals } from '../wire.ts';
|
|
10
|
+
/** Total tokens across the four buckets (billed input = input + cacheRead + cacheWrite). */
|
|
11
|
+
export declare function totalTokens(totals: UsageTotals): number;
|
|
12
|
+
/** Local `YYYY-MM-DD` key of a date, matching the host's day-file convention. */
|
|
13
|
+
export declare function dayKeyOf(date: Date): string;
|
|
14
|
+
/** Local day key of today shifted by whole days (test seam on `now`). */
|
|
15
|
+
export declare function shiftedDayKey(deltaDays: number, now?: () => Date): string;
|
|
16
|
+
/** One plotted day of the trend chart. */
|
|
17
|
+
export interface DayPoint {
|
|
18
|
+
day: string;
|
|
19
|
+
tokens: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The zero-filled daily token series over a day range: every calendar day of
|
|
23
|
+
* the range appears once (days without records plot as zero). Absent bounds
|
|
24
|
+
* fall back to the first/last row day; no rows and no range yield [].
|
|
25
|
+
* @param rows - the (already filtered) per-day rows.
|
|
26
|
+
* @param from - first day key, inclusive.
|
|
27
|
+
* @param to - last day key, inclusive.
|
|
28
|
+
*/
|
|
29
|
+
export declare function daySeries(rows: readonly UsageDayRow[], from?: string, to?: string): DayPoint[];
|
|
30
|
+
/** One plotted hour of the single-day trend chart. */
|
|
31
|
+
export interface HourPoint {
|
|
32
|
+
hour: string;
|
|
33
|
+
tokens: number;
|
|
34
|
+
}
|
|
35
|
+
/** Local `YYYY-MM-DDTHH` key of a date, matching the host's hour convention. */
|
|
36
|
+
export declare function hourKeyOf(date: Date): string;
|
|
37
|
+
/**
|
|
38
|
+
* The zero-filled hourly token series over a day range: every whole hour of
|
|
39
|
+
* the range appears once (hours without records plot as zero), so a single
|
|
40
|
+
* day yields the full 00:00–23:00 sequence and future hours of today read
|
|
41
|
+
* zero. The per-(hour, model) rows fold by hour. Absent bounds fall back to
|
|
42
|
+
* the first/last row hour; no rows and no range yield [].
|
|
43
|
+
* @param rows - the (already filtered) per-hour × per-model rows.
|
|
44
|
+
* @param from - first day key (`YYYY-MM-DD`), inclusive; the series starts
|
|
45
|
+
* at that day's 00:00.
|
|
46
|
+
* @param to - last day key, inclusive; the series ends at that day's 23:00.
|
|
47
|
+
*/
|
|
48
|
+
export declare function hourSeries(rows: readonly UsageHourRow[], from?: string, to?: string): HourPoint[];
|
|
49
|
+
//# sourceMappingURL=day.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"day.d.ts","sourceRoot":"","sources":["../../src/client/day.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExE,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAEvD;AAED,iFAAiF;AACjF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAI3C;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,IAAuB,GAAG,MAAM,CAI3F;AAED,0CAA0C;AAC1C,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,QAAQ,EAAE,CAc9F;AAED,sDAAsD;AACtD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAG5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAiBjG"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side day vocabulary of the token-usage settings page: local day
|
|
3
|
+
* keys, quick-range arithmetic, and the zero-filled per-day series backing
|
|
4
|
+
* the trend chart. Pure functions only, so the chart and its tests share one
|
|
5
|
+
* implementation.
|
|
6
|
+
*
|
|
7
|
+
* @module token-usage/client/day
|
|
8
|
+
*/
|
|
9
|
+
/** Total tokens across the four buckets (billed input = input + cacheRead + cacheWrite). */
|
|
10
|
+
export function totalTokens(totals) {
|
|
11
|
+
return totals.inputTokens + totals.outputTokens + totals.cacheReadTokens + totals.cacheWriteTokens;
|
|
12
|
+
}
|
|
13
|
+
/** Local `YYYY-MM-DD` key of a date, matching the host's day-file convention. */
|
|
14
|
+
export function dayKeyOf(date) {
|
|
15
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
16
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
17
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
18
|
+
}
|
|
19
|
+
/** Local day key of today shifted by whole days (test seam on `now`). */
|
|
20
|
+
export function shiftedDayKey(deltaDays, now = () => new Date()) {
|
|
21
|
+
const date = now();
|
|
22
|
+
date.setDate(date.getDate() + deltaDays);
|
|
23
|
+
return dayKeyOf(date);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The zero-filled daily token series over a day range: every calendar day of
|
|
27
|
+
* the range appears once (days without records plot as zero). Absent bounds
|
|
28
|
+
* fall back to the first/last row day; no rows and no range yield [].
|
|
29
|
+
* @param rows - the (already filtered) per-day rows.
|
|
30
|
+
* @param from - first day key, inclusive.
|
|
31
|
+
* @param to - last day key, inclusive.
|
|
32
|
+
*/
|
|
33
|
+
export function daySeries(rows, from, to) {
|
|
34
|
+
const first = from ?? rows[0]?.day;
|
|
35
|
+
const last = to ?? (rows.length > 0 ? rows[rows.length - 1].day : undefined);
|
|
36
|
+
if (first === undefined || last === undefined || first > last)
|
|
37
|
+
return [];
|
|
38
|
+
const tokens = new Map(rows.map(row => [row.day, totalTokens(row.totals)]));
|
|
39
|
+
const points = [];
|
|
40
|
+
const cursor = new Date(`${first}T00:00:00`);
|
|
41
|
+
const end = new Date(`${last}T00:00:00`);
|
|
42
|
+
while (cursor <= end) {
|
|
43
|
+
const day = dayKeyOf(cursor);
|
|
44
|
+
points.push({ day, tokens: tokens.get(day) ?? 0 });
|
|
45
|
+
cursor.setDate(cursor.getDate() + 1);
|
|
46
|
+
}
|
|
47
|
+
return points;
|
|
48
|
+
}
|
|
49
|
+
/** Local `YYYY-MM-DDTHH` key of a date, matching the host's hour convention. */
|
|
50
|
+
export function hourKeyOf(date) {
|
|
51
|
+
const hour = String(date.getHours()).padStart(2, '0');
|
|
52
|
+
return `${dayKeyOf(date)}T${hour}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The zero-filled hourly token series over a day range: every whole hour of
|
|
56
|
+
* the range appears once (hours without records plot as zero), so a single
|
|
57
|
+
* day yields the full 00:00–23:00 sequence and future hours of today read
|
|
58
|
+
* zero. The per-(hour, model) rows fold by hour. Absent bounds fall back to
|
|
59
|
+
* the first/last row hour; no rows and no range yield [].
|
|
60
|
+
* @param rows - the (already filtered) per-hour × per-model rows.
|
|
61
|
+
* @param from - first day key (`YYYY-MM-DD`), inclusive; the series starts
|
|
62
|
+
* at that day's 00:00.
|
|
63
|
+
* @param to - last day key, inclusive; the series ends at that day's 23:00.
|
|
64
|
+
*/
|
|
65
|
+
export function hourSeries(rows, from, to) {
|
|
66
|
+
const first = from !== undefined ? `${from}T00` : rows[0]?.hour;
|
|
67
|
+
const last = to !== undefined ? `${to}T23` : rows.length > 0 ? rows[rows.length - 1].hour : undefined;
|
|
68
|
+
if (first === undefined || last === undefined || first > last)
|
|
69
|
+
return [];
|
|
70
|
+
const tokens = new Map();
|
|
71
|
+
for (const row of rows) {
|
|
72
|
+
tokens.set(row.hour, (tokens.get(row.hour) ?? 0) + totalTokens(row.totals));
|
|
73
|
+
}
|
|
74
|
+
const points = [];
|
|
75
|
+
const cursor = new Date(`${first.slice(0, 10)}T${first.slice(11)}:00:00`);
|
|
76
|
+
const end = new Date(`${last.slice(0, 10)}T${last.slice(11)}:00:00`);
|
|
77
|
+
while (cursor <= end) {
|
|
78
|
+
const hour = hourKeyOf(cursor);
|
|
79
|
+
points.push({ hour, tokens: tokens.get(hour) ?? 0 });
|
|
80
|
+
cursor.setHours(cursor.getHours() + 1);
|
|
81
|
+
}
|
|
82
|
+
return points;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=day.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"day.js","sourceRoot":"","sources":["../../src/client/day.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,4FAA4F;AAC5F,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,OAAO,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAA;AACpG,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnD,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,KAAK,IAAI,GAAG,EAAE,CAAA;AAChD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;IACjF,MAAM,IAAI,GAAG,GAAG,EAAE,CAAA;IACl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C,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;IACzE,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;IACpE,OAAO,MAAM,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;QAC9B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACpD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;IACxC,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side display formatting of the token-usage settings page: token
|
|
3
|
+
* abbreviation (K/M/B), the cache hit rate, and the cost/rate figures of the
|
|
4
|
+
* pricing layer (wire amounts are RMB; the currency view converts them to
|
|
5
|
+
* the region-picked display currency, ¥ or $). Pure functions only, shared
|
|
6
|
+
* by the section and the trend chart.
|
|
7
|
+
*
|
|
8
|
+
* @module token-usage/client/format
|
|
9
|
+
*/
|
|
10
|
+
import type { UsageSummary, UsageTotals } from '../wire.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Abbreviate a token count: raw below 1K, `xxK` below 1M, `xxM` below 10 亿
|
|
13
|
+
* (1e9) — 1 亿 is `100M`, 2.5 亿 is `250M`, 9.5 亿 is `950M` — and `xxB`
|
|
14
|
+
* only from 10 亿 up (B = 10 亿, no fractional-B tier): `1B`, `1.5B`, `3B`.
|
|
15
|
+
* One decimal while the scaled value is below 10, integer otherwise —
|
|
16
|
+
* `950K`, `1.5M`, `950M`, `3B`.
|
|
17
|
+
* @param count - a non-negative token count.
|
|
18
|
+
* @returns the compact display string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatTokens(count: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Cache hit rate as display text: cache reads over served input
|
|
23
|
+
* (missed input + cache reads). `—` when nothing was served.
|
|
24
|
+
* @param totals - the aggregated totals.
|
|
25
|
+
* @returns e.g. `87.5%`, or `—` for an empty denominator.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatHitRate(totals: UsageTotals): string;
|
|
28
|
+
/**
|
|
29
|
+
* The threshold bucket the chip color picks from. Four levels (worst →
|
|
30
|
+
* best) along one warm→cool traffic-light arc:
|
|
31
|
+
* <60% `critical` (red)
|
|
32
|
+
* 60–80% `amber` (orange-yellow — "needs attention")
|
|
33
|
+
* 80–95% `lime` (yellow-green — "almost there")
|
|
34
|
+
* ≥95% `healthy` (green)
|
|
35
|
+
*
|
|
36
|
+
* Violet/teal were tried earlier to dodge the cost cell's warn accent,
|
|
37
|
+
* but they sit on opposite sides of the hue wheel so the middle two
|
|
38
|
+
* stops never read as a progression. Cost figures are now uncolored,
|
|
39
|
+
* so the classic red→amber→lime→green scale is free again.
|
|
40
|
+
*
|
|
41
|
+
* The empty-denominator path lands in `amber` so a brand-new session
|
|
42
|
+
* neither alarms (`critical`) nor celebrates (`healthy`).
|
|
43
|
+
*/
|
|
44
|
+
export type HitRateBand = 'critical' | 'amber' | 'lime' | 'healthy';
|
|
45
|
+
/** Map a 0-1 fraction to one of the four chip color buckets. */
|
|
46
|
+
export declare function bandOf(hitRate: number): HitRateBand;
|
|
47
|
+
/** Cache hit rate broken out into a display shape: the text the user sees
|
|
48
|
+
* plus the color bucket the UI maps onto it. Sessions with no served input
|
|
49
|
+
* read `—` in the `amber` bucket so a fresh session never paints cold. */
|
|
50
|
+
export interface HitRateDisplay {
|
|
51
|
+
text: string;
|
|
52
|
+
band: HitRateBand;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Compute the cache hit rate's display shape in one pass.
|
|
56
|
+
* @param totals - the aggregated totals.
|
|
57
|
+
* @returns `{ text, band }` — `text` is `—` for an empty denominator,
|
|
58
|
+
* `band` defaults to `amber` so an unused session reads as a mild
|
|
59
|
+
* "no signal yet" (neither alarming nor celebratory).
|
|
60
|
+
*/
|
|
61
|
+
export declare function hitRateDisplay(totals: UsageTotals): HitRateDisplay;
|
|
62
|
+
/**
|
|
63
|
+
* How cost figures render: the symbol plus, for USD, the RMB-per-USD
|
|
64
|
+
* divisor every wire amount (always RMB) divides by for display.
|
|
65
|
+
*/
|
|
66
|
+
export interface CurrencyView {
|
|
67
|
+
symbol: '¥' | '$';
|
|
68
|
+
/** RMB per USD; 1 in the CNY view (amounts pass through untouched). */
|
|
69
|
+
rate: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The display view of one stats summary: USD when the region pick says so
|
|
73
|
+
* (amounts ÷ `usdExchangeRate`, `$` prefix), else RMB as stored.
|
|
74
|
+
* @param summary - the stats payload (its `currency`/`usdExchangeRate` fields).
|
|
75
|
+
* @returns the view the format functions render through.
|
|
76
|
+
*/
|
|
77
|
+
export declare function currencyViewOf(summary: Pick<UsageSummary, 'currency' | 'usdExchangeRate'>): CurrencyView;
|
|
78
|
+
/**
|
|
79
|
+
* Cost as display text: the view's symbol plus two decimals, following the
|
|
80
|
+
* analyzer's cost formatting (`¥1.25`, `$0.18`). A cost is always shown,
|
|
81
|
+
* never omitted. USD divides the wire's RMB amount by the exchange rate.
|
|
82
|
+
* @param cost - a non-negative cost in ¥ (as carried on the wire).
|
|
83
|
+
* @param view - the display currency view.
|
|
84
|
+
* @returns e.g. `¥1.25`, or `$0.18` under a rate-7 USD view.
|
|
85
|
+
*/
|
|
86
|
+
export declare function formatCost(cost: number, view?: CurrencyView): string;
|
|
87
|
+
/**
|
|
88
|
+
* A per-million-token rate as display text, converted through the view:
|
|
89
|
+
* integral rates stay bare (`8`, `$1.14`-style conversion applied first for
|
|
90
|
+
* USD), fractional ones keep up to four decimals with trailing zeros
|
|
91
|
+
* stripped and a two-decimal minimum (`0.50`, `0.25`, `0.025`). The caller
|
|
92
|
+
* appends the `/M` unit and the view's symbol where needed.
|
|
93
|
+
* @param rate - a non-negative rate in ¥ per million tokens.
|
|
94
|
+
* @param view - the display currency view.
|
|
95
|
+
* @returns the display string (symbol-less, converted for USD).
|
|
96
|
+
*/
|
|
97
|
+
export declare function formatRate(rate: number, view?: CurrencyView): string;
|
|
98
|
+
/**
|
|
99
|
+
* A per-million-token rate as complete display text: the view's symbol plus
|
|
100
|
+
* {@link formatRate}'s converted number — what the pricing table cells render.
|
|
101
|
+
* @param rate - a non-negative rate in ¥ per million tokens.
|
|
102
|
+
* @param view - the display currency view.
|
|
103
|
+
* @returns e.g. `¥8`, or `$1.1429` under a rate-7 USD view.
|
|
104
|
+
*/
|
|
105
|
+
export declare function formatRateWithSymbol(rate: number, view?: CurrencyView): string;
|
|
106
|
+
/**
|
|
107
|
+
* Average first-token latency in the shell's compact duration shape:
|
|
108
|
+
* one decimal under a minute (`45.2s`), `2m42s` from there on.
|
|
109
|
+
* @param ms - total first-token latency.
|
|
110
|
+
* @returns the display string.
|
|
111
|
+
*/
|
|
112
|
+
export declare function formatTtft(ms: number): string;
|
|
113
|
+
/**
|
|
114
|
+
* Decode-throughput display figure in the shell's shape: whole tokens from
|
|
115
|
+
* ten up, one decimal below (the `tok/s` unit lives in the locale template).
|
|
116
|
+
* @param tokensPerSecond - tokens per second.
|
|
117
|
+
* @returns the display number.
|
|
118
|
+
*/
|
|
119
|
+
export declare function formatSpeed(tokensPerSecond: number): string;
|
|
120
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/client/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,Y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;GAKG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAG3D"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side display formatting of the token-usage settings page: token
|
|
3
|
+
* abbreviation (K/M/B), the cache hit rate, and the cost/rate figures of the
|
|
4
|
+
* pricing layer (wire amounts are RMB; the currency view converts them to
|
|
5
|
+
* the region-picked display currency, ¥ or $). Pure functions only, shared
|
|
6
|
+
* by the section and the trend chart.
|
|
7
|
+
*
|
|
8
|
+
* @module token-usage/client/format
|
|
9
|
+
*/
|
|
10
|
+
/** One decimal below 10, integer otherwise, trailing `.0` stripped. */
|
|
11
|
+
function scale(value) {
|
|
12
|
+
if (value >= 10)
|
|
13
|
+
return String(Math.round(value));
|
|
14
|
+
const oneDecimal = value.toFixed(1);
|
|
15
|
+
return oneDecimal.endsWith('.0') ? oneDecimal.slice(0, -2) : oneDecimal;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Abbreviate a token count: raw below 1K, `xxK` below 1M, `xxM` below 10 亿
|
|
19
|
+
* (1e9) — 1 亿 is `100M`, 2.5 亿 is `250M`, 9.5 亿 is `950M` — and `xxB`
|
|
20
|
+
* only from 10 亿 up (B = 10 亿, no fractional-B tier): `1B`, `1.5B`, `3B`.
|
|
21
|
+
* One decimal while the scaled value is below 10, integer otherwise —
|
|
22
|
+
* `950K`, `1.5M`, `950M`, `3B`.
|
|
23
|
+
* @param count - a non-negative token count.
|
|
24
|
+
* @returns the compact display string.
|
|
25
|
+
*/
|
|
26
|
+
export function formatTokens(count) {
|
|
27
|
+
if (count < 1_000)
|
|
28
|
+
return String(count);
|
|
29
|
+
if (count < 1_000_000)
|
|
30
|
+
return scale(count / 1_000) + 'K';
|
|
31
|
+
if (count < 1_000_000_000)
|
|
32
|
+
return scale(count / 1_000_000) + 'M';
|
|
33
|
+
return scale(count / 1_000_000_000) + 'B';
|
|
34
|
+
}
|
|
35
|
+
/** Always one decimal (stripped when `.0`), unlike {@link scale}: percentages keep their precision. */
|
|
36
|
+
function percent(value) {
|
|
37
|
+
const oneDecimal = value.toFixed(1);
|
|
38
|
+
return oneDecimal.endsWith('.0') ? oneDecimal.slice(0, -2) : oneDecimal;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Cache hit rate as display text: cache reads over served input
|
|
42
|
+
* (missed input + cache reads). `—` when nothing was served.
|
|
43
|
+
* @param totals - the aggregated totals.
|
|
44
|
+
* @returns e.g. `87.5%`, or `—` for an empty denominator.
|
|
45
|
+
*/
|
|
46
|
+
export function formatHitRate(totals) {
|
|
47
|
+
return hitRateDisplay(totals).text;
|
|
48
|
+
}
|
|
49
|
+
/** Hit-rate thresholds (inclusive lower bound, exclusive upper). Boundary
|
|
50
|
+
* values sit in the higher tier: 0.60 is `amber`, 0.80 is `lime`, 0.95
|
|
51
|
+
* is `healthy`. The numbers are guideposts, not hard cutoffs — a 78%
|
|
52
|
+
* cache hit rate is still in `amber`, exactly because cache misses at
|
|
53
|
+
* ~1/5 of requests is worth flagging. */
|
|
54
|
+
const HIT_RATE_AMBER = 0.60;
|
|
55
|
+
const HIT_RATE_LIME = 0.80;
|
|
56
|
+
const HIT_RATE_HEALTHY = 0.95;
|
|
57
|
+
/** Map a 0-1 fraction to one of the four chip color buckets. */
|
|
58
|
+
export function bandOf(hitRate) {
|
|
59
|
+
if (hitRate >= HIT_RATE_HEALTHY)
|
|
60
|
+
return 'healthy';
|
|
61
|
+
if (hitRate >= HIT_RATE_LIME)
|
|
62
|
+
return 'lime';
|
|
63
|
+
if (hitRate >= HIT_RATE_AMBER)
|
|
64
|
+
return 'amber';
|
|
65
|
+
return 'critical';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Compute the cache hit rate's display shape in one pass.
|
|
69
|
+
* @param totals - the aggregated totals.
|
|
70
|
+
* @returns `{ text, band }` — `text` is `—` for an empty denominator,
|
|
71
|
+
* `band` defaults to `amber` so an unused session reads as a mild
|
|
72
|
+
* "no signal yet" (neither alarming nor celebratory).
|
|
73
|
+
*/
|
|
74
|
+
export function hitRateDisplay(totals) {
|
|
75
|
+
const served = totals.inputTokens + totals.cacheReadTokens;
|
|
76
|
+
if (served === 0)
|
|
77
|
+
return { text: '—', band: 'amber' };
|
|
78
|
+
const rate = totals.cacheReadTokens / served;
|
|
79
|
+
return {
|
|
80
|
+
text: `${percent(rate * 100)}%`,
|
|
81
|
+
band: bandOf(rate),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** The RMB display view: amounts render as stored. */
|
|
85
|
+
const CNY_VIEW = { symbol: '¥', rate: 1 };
|
|
86
|
+
/**
|
|
87
|
+
* The display view of one stats summary: USD when the region pick says so
|
|
88
|
+
* (amounts ÷ `usdExchangeRate`, `$` prefix), else RMB as stored.
|
|
89
|
+
* @param summary - the stats payload (its `currency`/`usdExchangeRate` fields).
|
|
90
|
+
* @returns the view the format functions render through.
|
|
91
|
+
*/
|
|
92
|
+
export function currencyViewOf(summary) {
|
|
93
|
+
return summary.currency === 'USD' ? { symbol: '$', rate: summary.usdExchangeRate } : CNY_VIEW;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Cost as display text: the view's symbol plus two decimals, following the
|
|
97
|
+
* analyzer's cost formatting (`¥1.25`, `$0.18`). A cost is always shown,
|
|
98
|
+
* never omitted. USD divides the wire's RMB amount by the exchange rate.
|
|
99
|
+
* @param cost - a non-negative cost in ¥ (as carried on the wire).
|
|
100
|
+
* @param view - the display currency view.
|
|
101
|
+
* @returns e.g. `¥1.25`, or `$0.18` under a rate-7 USD view.
|
|
102
|
+
*/
|
|
103
|
+
export function formatCost(cost, view = CNY_VIEW) {
|
|
104
|
+
return `${view.symbol}${(cost / view.rate).toFixed(2)}`;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A per-million-token rate as display text, converted through the view:
|
|
108
|
+
* integral rates stay bare (`8`, `$1.14`-style conversion applied first for
|
|
109
|
+
* USD), fractional ones keep up to four decimals with trailing zeros
|
|
110
|
+
* stripped and a two-decimal minimum (`0.50`, `0.25`, `0.025`). The caller
|
|
111
|
+
* appends the `/M` unit and the view's symbol where needed.
|
|
112
|
+
* @param rate - a non-negative rate in ¥ per million tokens.
|
|
113
|
+
* @param view - the display currency view.
|
|
114
|
+
* @returns the display string (symbol-less, converted for USD).
|
|
115
|
+
*/
|
|
116
|
+
export function formatRate(rate, view = CNY_VIEW) {
|
|
117
|
+
const converted = rate / view.rate;
|
|
118
|
+
if (Number.isInteger(converted))
|
|
119
|
+
return String(converted);
|
|
120
|
+
let s = converted.toFixed(4);
|
|
121
|
+
const dot = s.indexOf('.');
|
|
122
|
+
s = s.replace(/0+$/u, '');
|
|
123
|
+
if (s.endsWith('.'))
|
|
124
|
+
s += '00';
|
|
125
|
+
const minEnd = dot + 3;
|
|
126
|
+
while (s.length < minEnd)
|
|
127
|
+
s += '0';
|
|
128
|
+
return s;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A per-million-token rate as complete display text: the view's symbol plus
|
|
132
|
+
* {@link formatRate}'s converted number — what the pricing table cells render.
|
|
133
|
+
* @param rate - a non-negative rate in ¥ per million tokens.
|
|
134
|
+
* @param view - the display currency view.
|
|
135
|
+
* @returns e.g. `¥8`, or `$1.1429` under a rate-7 USD view.
|
|
136
|
+
*/
|
|
137
|
+
export function formatRateWithSymbol(rate, view = CNY_VIEW) {
|
|
138
|
+
return `${view.symbol}${formatRate(rate, view)}`;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Average first-token latency in the shell's compact duration shape:
|
|
142
|
+
* one decimal under a minute (`45.2s`), `2m42s` from there on.
|
|
143
|
+
* @param ms - total first-token latency.
|
|
144
|
+
* @returns the display string.
|
|
145
|
+
*/
|
|
146
|
+
export function formatTtft(ms) {
|
|
147
|
+
const s = ms / 1000;
|
|
148
|
+
if (s < 60)
|
|
149
|
+
return `${String(Math.round(s * 10) / 10)}s`;
|
|
150
|
+
const whole = Math.round(s);
|
|
151
|
+
return `${Math.floor(whole / 60)}m${whole % 60}s`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Decode-throughput display figure in the shell's shape: whole tokens from
|
|
155
|
+
* ten up, one decimal below (the `tok/s` unit lives in the locale template).
|
|
156
|
+
* @param tokensPerSecond - tokens per second.
|
|
157
|
+
* @returns the display number.
|
|
158
|
+
*/
|
|
159
|
+
export function formatSpeed(tokensPerSecond) {
|
|
160
|
+
const clamped = Math.max(0, tokensPerSecond);
|
|
161
|
+
return clamped >= 10 ? String(Math.round(clamped)) : String(Math.round(clamped * 10) / 10);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/client/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,uEAAuE;AACvE,SAAS,KAAK,CAAC,KAAa;IAC1B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACjD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACnC,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,KAAK,GAAG,KAAK;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACvC,IAAI,KAAK,GAAG,SAAS;QAAE,OAAO,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,CAAA;IACxD,IAAI,KAAK,GAAG,aAAa;QAAE,OAAO,KAAK,CAAC,KAAK,GA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MAAM;QAAE,CAAC,IAAI,GAAG,CAAA;IAClC,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,OAAqB,QAAQ;IAC9E,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;IACnB,IAAI,CAAC,GAAG,EAAE;QAAE,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAA;IACxD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3B,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,KAAK,GAAG,EAAE,GAAG,CAAA;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,eAAuB;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,eAAe,CAAC,CAAA;IAC5C,OAAO,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAA;AAC5F,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of the token-usage plugin. Two registrations share one
|
|
3
|
+
* dictionary pair: the Token Usage stats page on the settings surface (data
|
|
4
|
+
* from the host half's stats route, `/token-usage/stats`), and the plugin
|
|
5
|
+
* configuration card on the Plugins tab (the `token-usage` settings
|
|
6
|
+
* namespace — the data directory and the pricing region — edited through
|
|
7
|
+
* the settings scope, with the relocation progress polled from
|
|
8
|
+
* `/token-usage/migration`). The card's browse button rides the shell's
|
|
9
|
+
* workspace service (`ctx.workspaces.pickDirectory`), the same native
|
|
10
|
+
* directory picker the workspace flows use. Export discipline: the /client
|
|
11
|
+
* entry exposes only what cordis loading needs.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/client
|
|
14
|
+
*/
|
|
15
|
+
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client';
|
|
16
|
+
/** Required services: the slot registry, the locale dictionaries, the
|
|
17
|
+
* settings scope, and the workspace service (its native directory picker
|
|
18
|
+
* backs the card's browse button). */
|
|
19
|
+
export declare const inject: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Register the dictionary pair, then the settings page and the plugin
|
|
22
|
+
* configuration card once the shell's declarations are on the ledger.
|
|
23
|
+
* @param ctx - client root context.
|
|
24
|
+
*/
|
|
25
|
+
export declare function apply(ctx: ClientContext): void;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AA8B3E;;sCAEsC;AACtC,eAAO,MAAM,MAAM,UAA6E,CAAA;AAEhG;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAkG9C"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of the token-usage plugin. Two registrations share one
|
|
3
|
+
* dictionary pair: the Token Usage stats page on the settings surface (data
|
|
4
|
+
* from the host half's stats route, `/token-usage/stats`), and the plugin
|
|
5
|
+
* configuration card on the Plugins tab (the `token-usage` settings
|
|
6
|
+
* namespace — the data directory and the pricing region — edited through
|
|
7
|
+
* the settings scope, with the relocation progress polled from
|
|
8
|
+
* `/token-usage/migration`). The card's browse button rides the shell's
|
|
9
|
+
* workspace service (`ctx.workspaces.pickDirectory`), the same native
|
|
10
|
+
* directory picker the workspace flows use. Export discipline: the /client
|
|
11
|
+
* entry exposes only what cordis loading needs.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/client
|
|
14
|
+
*/
|
|
15
|
+
import { CardForm } from "./card-form.js";
|
|
16
|
+
import { QuotaButton } from "./QuotaButton.js";
|
|
17
|
+
import { SessionStatsChip } from "./SessionStatsChip.js";
|
|
18
|
+
import { TokenUsageCard } from "./TokenUsageCard.js";
|
|
19
|
+
import { TokenUsageSection } from "./TokenUsageSection.js";
|
|
20
|
+
import { UsageView } from "./UsageView.js";
|
|
21
|
+
import { en, NS, zh } from "./locales.js";
|
|
22
|
+
/**
|
|
23
|
+
* Namespace of the token-usage settings section. Spelled here rather than
|
|
24
|
+
* imported: a client package must not depend on a Host package.
|
|
25
|
+
*/
|
|
26
|
+
const TOKEN_USAGE_NS = 'token-usage';
|
|
27
|
+
/** Required services: the slot registry, the locale dictionaries, the
|
|
28
|
+
* settings scope, and the workspace service (its native directory picker
|
|
29
|
+
* backs the card's browse button). */
|
|
30
|
+
export const inject = ['slots', 'locale', 'connection', 'remote', 'settingsScope', 'workspaces'];
|
|
31
|
+
/**
|
|
32
|
+
* Register the dictionary pair, then the settings page and the plugin
|
|
33
|
+
* configuration card once the shell's declarations are on the ledger.
|
|
34
|
+
* @param ctx - client root context.
|
|
35
|
+
*/
|
|
36
|
+
export function apply(ctx) {
|
|
37
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'token-usage: dictionaries');
|
|
38
|
+
// Stable per-namespace translate reading the active locale at call time;
|
|
39
|
+
// the label thunk re-evaluates it per read, so the nav row follows switches.
|
|
40
|
+
const t = ctx.locale.bind(NS);
|
|
41
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
42
|
+
name: 'settings.section',
|
|
43
|
+
id: 'token-usage',
|
|
44
|
+
order: 50,
|
|
45
|
+
label: () => t('nav.label'),
|
|
46
|
+
locale: NS,
|
|
47
|
+
}, TokenUsageSection));
|
|
48
|
+
// The Usage view tab: one entry of the conversation view ring (beside the
|
|
49
|
+
// built-in Chat tab and the Trajectory tab from ui-trajectory, rendered
|
|
50
|
+
// by the session header's tab ring, one at a time). Registration is the
|
|
51
|
+
// same trajectory pattern — a label thunk follows the active locale, and
|
|
52
|
+
// the component reads the session through the standard kit.
|
|
53
|
+
ctx.slots.inject('conversation.view', () => ctx.slots.register({
|
|
54
|
+
name: 'conversation.view',
|
|
55
|
+
id: 'usage',
|
|
56
|
+
order: 20,
|
|
57
|
+
label: () => t('view.usage'),
|
|
58
|
+
locale: NS,
|
|
59
|
+
}, UsageView));
|
|
60
|
+
// The session-header stats chip: one entry of the
|
|
61
|
+
// `conversation.session.header.utilities` slot list (right-aligned
|
|
62
|
+
// utilities kept outside the title-adjacent action group). The chip
|
|
63
|
+
// reads the active session id and the session-list mirror from the
|
|
64
|
+
// standard kit, walks the subagent subtree, and fetches the folded
|
|
65
|
+
// summary from the host's `/token-usage/stats` route — the same
|
|
66
|
+
// "with subagents" range the Usage view tab offers. The component
|
|
67
|
+
// self-gates: a session with zero recorded requests renders nothing
|
|
68
|
+
// (the spec's empty rule); a transient fetch miss keeps the previous
|
|
69
|
+
// render so the chip never blanks to "—" mid-conversation.
|
|
70
|
+
//
|
|
71
|
+
// Position: the chip sits IMMEDIATELY LEFT of the Session log button
|
|
72
|
+
// (`session-log-download` registers with no explicit `order`, defaulting
|
|
73
|
+
// to 0). A negative order puts the chip ahead of every positive-order
|
|
74
|
+
// utility, mirroring the convention `ui-agent-preset` uses for static
|
|
75
|
+
// session context in `conversation.session.header.actions`.
|
|
76
|
+
ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
77
|
+
name: 'conversation.session.header.utilities',
|
|
78
|
+
id: 'session-stats',
|
|
79
|
+
order: -10,
|
|
80
|
+
locale: NS,
|
|
81
|
+
}, SessionStatsChip));
|
|
82
|
+
// The input-bar quota button: one entry of the `conversation.input.right`
|
|
83
|
+
// slot list (the tool row's right end, before the send button — the host
|
|
84
|
+
// renders slot entries left of the model chip). The button polls the
|
|
85
|
+
// host's `/token-usage/quota` route for the ACTIVE session's provider and
|
|
86
|
+
// self-gates: it renders nothing while the provider is undeterminable or
|
|
87
|
+
// has no quota adapter, so the toolbar stays clean on unsupported
|
|
88
|
+
// providers and the button reappears when a supported one takes over.
|
|
89
|
+
// `order: 10` keeps it after any future lower-order utilities in the
|
|
90
|
+
// same slot.
|
|
91
|
+
//
|
|
92
|
+
// Provider resolution follows the model CHIP: the shell's model-selection
|
|
93
|
+
// service (`ctx.modelDirectories`, from ui-model-selection — the same
|
|
94
|
+
// shared per-session directory the chip renders from) reports the host's
|
|
95
|
+
// NEXT selection live, so the button appears the moment the user picks a
|
|
96
|
+
// provider, before any request is sent. The service attaches through an
|
|
97
|
+
// OPTIONAL inject — a shell without it falls back to the host's own
|
|
98
|
+
// resolution (last request's provider, else the default selection).
|
|
99
|
+
const modelDirectory = { service: undefined };
|
|
100
|
+
ctx.inject(['modelDirectories'], (modelCtx) => {
|
|
101
|
+
modelCtx.effect(() => {
|
|
102
|
+
modelDirectory.service = modelCtx.modelDirectories;
|
|
103
|
+
return () => { modelDirectory.service = undefined; };
|
|
104
|
+
}, 'token-usage: model directory seam');
|
|
105
|
+
});
|
|
106
|
+
ctx.slots.inject('conversation.input.right', () => ctx.slots.register({
|
|
107
|
+
name: 'conversation.input.right',
|
|
108
|
+
id: 'token-usage-quota',
|
|
109
|
+
order: 10,
|
|
110
|
+
locale: NS,
|
|
111
|
+
inject: () => ({ modelDirectory }),
|
|
112
|
+
}, QuotaButton));
|
|
113
|
+
// The Plugins configuration tab dispatches keyed cards for the namespaces
|
|
114
|
+
// the Host serves; the token-usage host half registers this key, so the
|
|
115
|
+
// pricing card pairs with it without any upstream change.
|
|
116
|
+
const form = new CardForm(ctx.settingsScope.bind({ namespace: TOKEN_USAGE_NS }));
|
|
117
|
+
const store = form.bind();
|
|
118
|
+
ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
|
|
119
|
+
name: 'settings.plugin.item',
|
|
120
|
+
key: TOKEN_USAGE_NS,
|
|
121
|
+
locale: NS,
|
|
122
|
+
inject: () => ({
|
|
123
|
+
hooks: { tokenUsageCard: store },
|
|
124
|
+
...form.actions(),
|
|
125
|
+
// The shell's own directory picker (the workspace flows' chooser):
|
|
126
|
+
// resolves the chosen absolute path, or null when the user dismisses.
|
|
127
|
+
pickDirectory: () => ctx.workspaces.pickDirectory(),
|
|
128
|
+
}),
|
|
129
|
+
}, TokenUsageCard));
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkBH,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAA6B,MAAM,kBAAmB,CAAA;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAwB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAsB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAiB,CAAA;AAC3C,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAEzC;;;GAGG;AACH,MAAM,cAAc,GAAG,aAAa,CAAA;AAEpC;;sCAEsC;AACtC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,CAAC,CAAA;AAEhG;;;;GAIG;AACH,MAAM,UAAU,K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