@laoyuehanni/dsh-token-usage 0.4.11 → 0.4.12
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/README.md +4 -2
- package/README.zh.md +4 -2
- package/lib/client/OverheadRows.d.ts +1 -2
- package/lib/client/OverheadRows.d.ts.map +1 -1
- package/lib/client/OverheadRows.js +3 -3
- package/lib/client/OverheadRows.js.map +1 -1
- package/lib/client/RequestPool.d.ts.map +1 -1
- package/lib/client/RequestPool.js +62 -12
- package/lib/client/RequestPool.js.map +1 -1
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +2 -2
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/UsageRows.d.ts +2 -4
- package/lib/client/UsageRows.d.ts.map +1 -1
- package/lib/client/UsageRows.js +3 -3
- package/lib/client/UsageRows.js.map +1 -1
- package/lib/client/UsageView.d.ts +4 -4
- package/lib/client/UsageView.d.ts.map +1 -1
- package/lib/client/card-form.d.ts +8 -6
- package/lib/client/card-form.d.ts.map +1 -1
- package/lib/client/card-form.js +4 -2
- package/lib/client/card-form.js.map +1 -1
- package/lib/client/index.d.ts +2 -2
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +15 -32
- package/lib/client/index.js.map +1 -1
- package/lib/client.js +516 -471
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +20 -28
- package/lib/index.js.map +1 -1
- package/lib/request-observe.d.ts +2 -2
- package/lib/request-observe.js +2 -2
- package/lib/sync.d.ts +21 -42
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +29 -51
- package/lib/sync.js.map +1 -1
- package/lib/usage-log.d.ts.map +1 -1
- package/lib/usage-log.js +3 -4
- package/lib/usage-log.js.map +1 -1
- package/package.json +3 -3
- package/lib/client/SessionStatsChip.d.ts +0 -47
- package/lib/client/SessionStatsChip.d.ts.map +0 -1
- package/lib/client/SessionStatsChip.js +0 -141
- package/lib/client/SessionStatsChip.js.map +0 -1
- package/lib/client/SessionTable.d.ts +0 -40
- package/lib/client/SessionTable.d.ts.map +0 -1
- package/lib/client/SessionTable.js +0 -188
- package/lib/client/SessionTable.js.map +0 -1
- package/lib/client/TokenActivity.d.ts +0 -21
- package/lib/client/TokenActivity.d.ts.map +0 -1
- package/lib/client/TokenActivity.js +0 -71
- package/lib/client/TokenActivity.js.map +0 -1
- package/lib/client/UsageChart.d.ts +0 -20
- package/lib/client/UsageChart.d.ts.map +0 -1
- package/lib/client/UsageChart.js +0 -26
- package/lib/client/UsageChart.js.map +0 -1
- package/lib/client/activity-grid.d.ts +0 -42
- package/lib/client/activity-grid.d.ts.map +0 -1
- package/lib/client/activity-grid.js +0 -86
- package/lib/client/activity-grid.js.map +0 -1
- package/lib/client/cost-split.d.ts +0 -26
- package/lib/client/cost-split.d.ts.map +0 -1
- package/lib/client/cost-split.js +0 -37
- package/lib/client/cost-split.js.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* Codex-style token activity calendar. Each square is one local day; columns
|
|
4
|
-
* are Monday-first weeks and color intensity follows the active daily /
|
|
5
|
-
* weekly / cumulative reading. A capped oldest-to-newest WAAPI stagger makes
|
|
6
|
-
* the bricks arrive progressively without timers in React.
|
|
7
|
-
*
|
|
8
|
-
* @module token-usage/client/TokenActivity
|
|
9
|
-
*/
|
|
10
|
-
import { Fragment, useEffect, useRef } from 'react';
|
|
11
|
-
import { buildActivityGrid } from "./activity-grid.js";
|
|
12
|
-
import { formatTokens } from "./format.js";
|
|
13
|
-
import { motionAllowed } from "./cost-inflate-motion.js";
|
|
14
|
-
import styles from './TokenActivity.module.css';
|
|
15
|
-
/** Keep a year-long entrance below one second of deferred motion. */
|
|
16
|
-
const STAGGER_MS = 8;
|
|
17
|
-
const MAX_DELAY_MS = 960;
|
|
18
|
-
/** Tooltip / accessible name of one cell in the active reading. */
|
|
19
|
-
function cellLabel(t, cell, mode) {
|
|
20
|
-
const tokens = formatTokens(cell.value);
|
|
21
|
-
if (mode === 'weekly') {
|
|
22
|
-
return t('activity.weekLabel', { day: cell.day, from: cell.weekFrom, to: cell.weekTo, tokens });
|
|
23
|
-
}
|
|
24
|
-
return mode === 'cumulative'
|
|
25
|
-
? t('activity.cumulativeLabel', { day: cell.day, tokens })
|
|
26
|
-
: t('activity.dayLabel', { day: cell.day, tokens });
|
|
27
|
-
}
|
|
28
|
-
/** One mount-animated brick. WAAPI avoids the embedded-host CSS keyframe /
|
|
29
|
-
* custom-property failure mode already handled by cost-inflate-motion.ts. */
|
|
30
|
-
function ActivityBrick({ cell, mode, delay, t }) {
|
|
31
|
-
const ref = useRef(null);
|
|
32
|
-
const label = cellLabel(t, cell, mode);
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
const element = ref.current;
|
|
35
|
-
if (element === null || !motionAllowed() || typeof element.animate !== 'function')
|
|
36
|
-
return;
|
|
37
|
-
const animation = element.animate([
|
|
38
|
-
{ opacity: 0, transform: 'translateY(3px) scale(0.72)' },
|
|
39
|
-
{ opacity: 1, transform: 'translateY(0) scale(1)' },
|
|
40
|
-
], {
|
|
41
|
-
duration: 260,
|
|
42
|
-
delay,
|
|
43
|
-
easing: 'cubic-bezier(0.2, 0.7, 0.2, 1)',
|
|
44
|
-
// Hold the invisible first frame only during the stagger. Afterwards
|
|
45
|
-
// ordinary CSS owns the resting and hover/focus transforms again.
|
|
46
|
-
fill: 'backwards',
|
|
47
|
-
});
|
|
48
|
-
return () => { animation.cancel(); };
|
|
49
|
-
// Mount-only by design: a changed delay from a filter/data refresh must
|
|
50
|
-
// not replay an existing day. Mode changes remount the calendar instead.
|
|
51
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
-
}, []);
|
|
53
|
-
return (_jsx("span", { ref: ref, className: styles.brick, role: "img", tabIndex: 0, "aria-label": label, title: label, "data-level": cell.level }));
|
|
54
|
-
}
|
|
55
|
-
/** Render the filtered activity calendar, or the same empty hint as the line. */
|
|
56
|
-
export function TokenActivity({ rows, from, to, mode = 'daily', t }) {
|
|
57
|
-
const weeks = buildActivityGrid(rows, mode, from, to);
|
|
58
|
-
if (weeks.length === 0)
|
|
59
|
-
return _jsx("p", { className: styles.empty, children: t('chart.empty') });
|
|
60
|
-
const ariaKey = mode === 'weekly'
|
|
61
|
-
? 'activity.ariaWeekly'
|
|
62
|
-
: mode === 'cumulative' ? 'activity.ariaCumulative' : 'activity.ariaDaily';
|
|
63
|
-
return (_jsx("div", { className: styles.scroll, children: _jsx("div", { className: styles.calendar, role: "group", "aria-label": t(ariaKey), children: weeks.map((week, weekIndex) => (_jsxs(Fragment, { children: [_jsx("span", { className: styles.month, "aria-hidden": "true", children: week.month === undefined ? '' : t('activity.month', { month: String(week.month) }) }), week.cells.map((cell, weekday) => {
|
|
64
|
-
if (cell === null) {
|
|
65
|
-
return _jsx("span", { className: styles.placeholder, "aria-hidden": "true" }, `${week.key}:${String(weekday)}`);
|
|
66
|
-
}
|
|
67
|
-
const delay = Math.min((weekIndex * 7 + weekday) * STAGGER_MS, MAX_DELAY_MS);
|
|
68
|
-
return (_jsx(ActivityBrick, { cell: cell, mode: mode, delay: delay, t: t }, `${mode}:${cell.day}`));
|
|
69
|
-
})] }, week.key))) }, mode) }));
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=TokenActivity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TokenActivity.js","sourceRoot":"","sources":["../../src/client/TokenActivity.tsx"],"names":[],"mappings":";AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAKnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA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|
3
|
-
* default and adds a Codex-style activity calendar. View and activity-mode
|
|
4
|
-
* switches are pure client state over the same already-filtered summary —
|
|
5
|
-
* neither changes the date/model filters nor triggers another request.
|
|
6
|
-
*
|
|
7
|
-
* @module token-usage/client/UsageChart
|
|
8
|
-
*/
|
|
9
|
-
import type { ReactNode } from 'react';
|
|
10
|
-
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
|
|
11
|
-
import type { UsageDayRow, UsageHourRow } from '../wire.ts';
|
|
12
|
-
/** Render the switchable token line/activity chart over filtered day rows. */
|
|
13
|
-
export declare function UsageChart({ rows, hours, from, to, t }: {
|
|
14
|
-
rows: readonly UsageDayRow[];
|
|
15
|
-
hours?: readonly UsageHourRow[];
|
|
16
|
-
from?: string;
|
|
17
|
-
to?: string;
|
|
18
|
-
t: TranslateNS<'token-usage'>;
|
|
19
|
-
}): ReactNode;
|
|
20
|
-
//# sourceMappingURL=UsageChart.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UsageChart.d.ts","sourceRoot":"","sources":["../../src/client/UsageChart.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA0B3D,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;IACvD,IAAI,EAAE,SAAS,WAAW,EAAE,CAAA;IAC5B,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;CAC9B,GAAG,SAAS,CA2CZ"}
|
package/lib/client/UsageChart.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* Settings-page chart composer: preserves the existing line chart as the
|
|
4
|
-
* default and adds a Codex-style activity calendar. View and activity-mode
|
|
5
|
-
* switches are pure client state over the same already-filtered summary —
|
|
6
|
-
* neither changes the date/model filters nor triggers another request.
|
|
7
|
-
*
|
|
8
|
-
* @module token-usage/client/UsageChart
|
|
9
|
-
*/
|
|
10
|
-
import { useState } from 'react';
|
|
11
|
-
import { TokenActivity } from "./TokenActivity.js";
|
|
12
|
-
import { TrendChart } from "./TrendChart.js";
|
|
13
|
-
import styles from './UsageChart.module.css';
|
|
14
|
-
/** One segment button with the same aria-pressed contract as existing tabs. */
|
|
15
|
-
function Segment({ active, label, onClick }) {
|
|
16
|
-
return (_jsx("button", { type: "button", className: active ? `${styles.button} ${styles.active}` : styles.button, "aria-pressed": active, onClick: onClick, children: label }));
|
|
17
|
-
}
|
|
18
|
-
/** Render the switchable token line/activity chart over filtered day rows. */
|
|
19
|
-
export function UsageChart({ rows, hours, from, to, t }) {
|
|
20
|
-
const [view, setView] = useState('line');
|
|
21
|
-
const [activityMode, setActivityMode] = useState('daily');
|
|
22
|
-
return (_jsxs("section", { className: styles.section, children: [_jsxs("div", { className: styles.head, children: [_jsx("h3", { className: styles.title, children: t('chart.title') }), _jsxs("div", { className: styles.controls, children: [view === 'activity' ? (_jsxs("div", { className: styles.segmented, role: "group", "aria-label": t('activity.mode.label'), children: [_jsx(Segment, { active: activityMode === 'daily', label: t('activity.mode.daily'), onClick: () => setActivityMode('daily') }), _jsx(Segment, { active: activityMode === 'weekly', label: t('activity.mode.weekly'), onClick: () => setActivityMode('weekly') }), _jsx(Segment, { active: activityMode === 'cumulative', label: t('activity.mode.cumulative'), onClick: () => setActivityMode('cumulative') })] })) : null, _jsxs("div", { className: styles.segmented, role: "group", "aria-label": t('chart.view.label'), children: [_jsx(Segment, { active: view === 'line', label: t('chart.view.line'), onClick: () => setView('line') }), _jsx(Segment, { active: view === 'activity', label: t('chart.view.activity'), onClick: () => setView('activity') })] })] })] }), view === 'line'
|
|
23
|
-
? (_jsx(TrendChart, { rows: rows, t: t, ...hours !== undefined ? { hours } : {}, ...from !== undefined ? { from } : {}, ...to !== undefined ? { to } : {} }))
|
|
24
|
-
: (_jsx(TokenActivity, { rows: rows, mode: activityMode, t: t, ...from !== undefined ? { from } : {}, ...to !== undefined ? { to } : {} }))] }));
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=UsageChart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UsageChart.js","sourceRoot":"","sources":["../../src/client/UsageChart.tsx"],"names":[],"mappings":";AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKhC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAqB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAkB,CAAA;AAC7C,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAI5C,+EAA+E;AAC/E,SAAS,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAIxC;IACC,OAAO,CACL,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,kBACzD,MAAM,EACpB,OAAO,EAAE,OAAO,YAEf,KAAK,GACC,CACV,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAMpD;IACC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAY,M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CAAC,MAAM,CAAC,GAAI,EACjG,KAAC,OAAO,IAAC,MAAM,EAAE,IAAI,KAAK,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,GAAI,IACzG,IACF,IACF,EACL,IAAI,KAAK,MAAM;gBACd,CAAC,CAAC,CACA,KAAC,UAAU,IACT,IAAI,EAAE,IAAI,EACV,CAAC,EAAE,CAAC,KACA,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KACpC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,KAClC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAClC,CACH;gBACD,CAAC,CAAC,CACA,KAAC,aAAa,IACZ,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,YAAY,EAClB,CAAC,EAAE,CAAC,KACA,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,KAClC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAClC,CACH,IACK,CACX,CAAA;AACH,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calendar-grid projection of the filtered daily token rows. The grid is
|
|
3
|
-
* Monday-first, seven rows per week, and zero-fills the same inclusive range
|
|
4
|
-
* as the line chart. Daily, whole-week, and running-total readings share the
|
|
5
|
-
* exact same cells so switching modes never changes the calendar geometry.
|
|
6
|
-
*
|
|
7
|
-
* @module token-usage/client/activity-grid
|
|
8
|
-
*/
|
|
9
|
-
import type { UsageDayRow } from '../wire.ts';
|
|
10
|
-
/** The three readings exposed by the activity view. */
|
|
11
|
-
export type ActivityMode = 'daily' | 'weekly' | 'cumulative';
|
|
12
|
-
/** One real day in the activity grid. */
|
|
13
|
-
export interface ActivityCell {
|
|
14
|
-
day: string;
|
|
15
|
-
/** This day's own total, retained for daily tooltips and tests. */
|
|
16
|
-
tokens: number;
|
|
17
|
-
/** The active reading: day total, containing-week total, or running total. */
|
|
18
|
-
value: number;
|
|
19
|
-
/** First/last included day of this cell's week (clamped to the filter). */
|
|
20
|
-
weekFrom: string;
|
|
21
|
-
weekTo: string;
|
|
22
|
-
/** Five theme-driven color stops: zero plus four non-zero intensities. */
|
|
23
|
-
level: 0 | 1 | 2 | 3 | 4;
|
|
24
|
-
}
|
|
25
|
-
/** One calendar week column; null cells align partial first/last weeks. */
|
|
26
|
-
export interface ActivityWeek {
|
|
27
|
-
/** Monday's local day key, also the React key. */
|
|
28
|
-
key: string;
|
|
29
|
-
/** One-based month label shown on the first week and at each month start. */
|
|
30
|
-
month?: number;
|
|
31
|
-
cells: Array<ActivityCell | null>;
|
|
32
|
-
}
|
|
33
|
-
/** Quantize a non-negative value against the grid maximum into five stops. */
|
|
34
|
-
export declare function activityLevel(value: number, maximum: number): ActivityCell['level'];
|
|
35
|
-
/**
|
|
36
|
-
* Build the activity calendar over the filtered rows/range. Weekly mode is a
|
|
37
|
-
* whole-week reading of the included days, repeated across that week's cells
|
|
38
|
-
* (a partial week at either filter boundary includes only the filtered days).
|
|
39
|
-
* Cumulative mode is the running total in chronological order.
|
|
40
|
-
*/
|
|
41
|
-
export declare function buildActivityGrid(rows: readonly UsageDayRow[], mode?: ActivityMode, from?: string, to?: string): ActivityWeek[];
|
|
42
|
-
//# sourceMappingURL=activity-grid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"activity-grid.d.ts","sourceRoot":"","sources":["../../src/client/activity-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAG7C,uDAAuD;AACvD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAA;AAE5D,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAA;IACd,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAA;IACb,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,0EAA0E;IAC1E,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CACzB;AAED,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAA;IACX,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAA;CAClC;AAyBD,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAGnF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,IAAI,GAAE,YAAsB,EAC5B,IAAI,CAAC,EAAE,MAAM,EACb,EAAE,CAAC,EAAE,MAAM,GACV,YAAY,EAAE,CAkDhB"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calendar-grid projection of the filtered daily token rows. The grid is
|
|
3
|
-
* Monday-first, seven rows per week, and zero-fills the same inclusive range
|
|
4
|
-
* as the line chart. Daily, whole-week, and running-total readings share the
|
|
5
|
-
* exact same cells so switching modes never changes the calendar geometry.
|
|
6
|
-
*
|
|
7
|
-
* @module token-usage/client/activity-grid
|
|
8
|
-
*/
|
|
9
|
-
import { dayKeyOf, daySeries } from "./day.js";
|
|
10
|
-
/** Local date of a day key; string parsing is avoided everywhere else. */
|
|
11
|
-
function dateOf(day) {
|
|
12
|
-
return new Date(`${day}T00:00:00`);
|
|
13
|
-
}
|
|
14
|
-
/** Monday-first weekday index (Monday 0 … Sunday 6). */
|
|
15
|
-
function weekdayOf(day) {
|
|
16
|
-
return (dateOf(day).getDay() + 6) % 7;
|
|
17
|
-
}
|
|
18
|
-
/** Monday key of the week containing one local day. */
|
|
19
|
-
function weekKeyOf(day) {
|
|
20
|
-
const cursor = dateOf(day);
|
|
21
|
-
cursor.setDate(cursor.getDate() - weekdayOf(day));
|
|
22
|
-
return dayKeyOf(cursor);
|
|
23
|
-
}
|
|
24
|
-
/** Quantize a non-negative value against the grid maximum into five stops. */
|
|
25
|
-
export function activityLevel(value, maximum) {
|
|
26
|
-
if (value <= 0 || maximum <= 0)
|
|
27
|
-
return 0;
|
|
28
|
-
return Math.max(1, Math.min(4, Math.ceil((value / maximum) * 4)));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Build the activity calendar over the filtered rows/range. Weekly mode is a
|
|
32
|
-
* whole-week reading of the included days, repeated across that week's cells
|
|
33
|
-
* (a partial week at either filter boundary includes only the filtered days).
|
|
34
|
-
* Cumulative mode is the running total in chronological order.
|
|
35
|
-
*/
|
|
36
|
-
export function buildActivityGrid(rows, mode = 'daily', from, to) {
|
|
37
|
-
const points = daySeries(rows, from, to);
|
|
38
|
-
if (points.length === 0)
|
|
39
|
-
return [];
|
|
40
|
-
const totals = new Map();
|
|
41
|
-
for (const point of points) {
|
|
42
|
-
const key = weekKeyOf(point.day);
|
|
43
|
-
const current = totals.get(key);
|
|
44
|
-
if (current === undefined)
|
|
45
|
-
totals.set(key, { from: point.day, to: point.day, tokens: point.tokens });
|
|
46
|
-
else {
|
|
47
|
-
current.to = point.day;
|
|
48
|
-
current.tokens += point.tokens;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
let cumulative = 0;
|
|
52
|
-
const valued = points.map(point => {
|
|
53
|
-
cumulative += point.tokens;
|
|
54
|
-
const key = weekKeyOf(point.day);
|
|
55
|
-
const week = totals.get(key);
|
|
56
|
-
const value = mode === 'weekly' ? week.tokens : mode === 'cumulative' ? cumulative : point.tokens;
|
|
57
|
-
return { ...point, key, value, weekFrom: week.from, weekTo: week.to };
|
|
58
|
-
});
|
|
59
|
-
const maximum = Math.max(...valued.map(point => point.value));
|
|
60
|
-
const weeks = [];
|
|
61
|
-
const byKey = new Map();
|
|
62
|
-
for (const point of valued) {
|
|
63
|
-
let week = byKey.get(point.key);
|
|
64
|
-
if (week === undefined) {
|
|
65
|
-
week = { key: point.key, cells: Array(7).fill(null) };
|
|
66
|
-
byKey.set(point.key, week);
|
|
67
|
-
weeks.push(week);
|
|
68
|
-
}
|
|
69
|
-
const weekday = weekdayOf(point.day);
|
|
70
|
-
week.cells[weekday] = {
|
|
71
|
-
day: point.day,
|
|
72
|
-
tokens: point.tokens,
|
|
73
|
-
value: point.value,
|
|
74
|
-
weekFrom: point.weekFrom,
|
|
75
|
-
weekTo: point.weekTo,
|
|
76
|
-
level: activityLevel(point.value, maximum),
|
|
77
|
-
};
|
|
78
|
-
// The first visible column names its month even when the filter starts
|
|
79
|
-
// mid-month; subsequent labels appear at the week containing day 1.
|
|
80
|
-
if (weeks.length === 1 || point.day.endsWith('-01')) {
|
|
81
|
-
week.month = dateOf(point.day).getMonth() + 1;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return weeks;
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=activity-grid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"activity-grid.js","sourceRoot":"","sources":["../../src/client/activity-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAkC9C,0EAA0E;AAC1E,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,IAAI,IA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AAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;YAC1E,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;YAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC;QACD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG;YACpB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC;SAC3C,CAAA;QACD,uEAAuE;QACvE,oEAAoE;QACpE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side cost split for the row tooltips (browser half): the wire
|
|
3
|
-
* carries one authoritative row-level cost plus the four token buckets,
|
|
4
|
-
* never per-bucket costs — so the hover table's 费用 row apportions the
|
|
5
|
-
* row's own cost across the buckets instead of inventing new figures.
|
|
6
|
-
*
|
|
7
|
-
* @module token-usage/client/cost-split
|
|
8
|
-
*/
|
|
9
|
-
import type { ModelPricing, UsageTotals } from '../wire.ts';
|
|
10
|
-
/**
|
|
11
|
-
* Apportion one row's authoritative cost across the four token buckets,
|
|
12
|
-
* weighted by `tokens × rate` (an absent cache rate falls back to the
|
|
13
|
-
* input rate — the same default the server's billed-rates rule uses).
|
|
14
|
-
* The split is *anchored*: the first three shares are the weighted
|
|
15
|
-
* fractions and the write share takes the remainder, so the four cells
|
|
16
|
-
* always sum to exactly `cost` (the number the row itself displays).
|
|
17
|
-
* @param cost - the row's billed cost (¥), as displayed on the row.
|
|
18
|
-
* @param totals - the row's token buckets.
|
|
19
|
-
* @param rates - the model's base per-million rates; omitted weights by
|
|
20
|
-
* bare token counts (callers with no pricing on file hide the row
|
|
21
|
-
* instead, so this branch exists for completeness and tests).
|
|
22
|
-
* @returns the four shares `[input, output, cacheRead, cacheWrite]` in ¥,
|
|
23
|
-
* or null when no positive weight exists (all buckets empty).
|
|
24
|
-
*/
|
|
25
|
-
export declare function allocateCost(cost: number, totals: UsageTotals, rates?: ModelPricing): readonly [number, number, number, number] | null;
|
|
26
|
-
//# sourceMappingURL=cost-split.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-split.d.ts","sourceRoot":"","sources":["../../src/client/cost-split.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,KAAK,CAAC,EAAE,YAAY,GACnB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAWlD"}
|
package/lib/client/cost-split.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side cost split for the row tooltips (browser half): the wire
|
|
3
|
-
* carries one authoritative row-level cost plus the four token buckets,
|
|
4
|
-
* never per-bucket costs — so the hover table's 费用 row apportions the
|
|
5
|
-
* row's own cost across the buckets instead of inventing new figures.
|
|
6
|
-
*
|
|
7
|
-
* @module token-usage/client/cost-split
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Apportion one row's authoritative cost across the four token buckets,
|
|
11
|
-
* weighted by `tokens × rate` (an absent cache rate falls back to the
|
|
12
|
-
* input rate — the same default the server's billed-rates rule uses).
|
|
13
|
-
* The split is *anchored*: the first three shares are the weighted
|
|
14
|
-
* fractions and the write share takes the remainder, so the four cells
|
|
15
|
-
* always sum to exactly `cost` (the number the row itself displays).
|
|
16
|
-
* @param cost - the row's billed cost (¥), as displayed on the row.
|
|
17
|
-
* @param totals - the row's token buckets.
|
|
18
|
-
* @param rates - the model's base per-million rates; omitted weights by
|
|
19
|
-
* bare token counts (callers with no pricing on file hide the row
|
|
20
|
-
* instead, so this branch exists for completeness and tests).
|
|
21
|
-
* @returns the four shares `[input, output, cacheRead, cacheWrite]` in ¥,
|
|
22
|
-
* or null when no positive weight exists (all buckets empty).
|
|
23
|
-
*/
|
|
24
|
-
export function allocateCost(cost, totals, rates) {
|
|
25
|
-
const wInput = totals.inputTokens * (rates?.inputPerMillion ?? 1);
|
|
26
|
-
const wOutput = totals.outputTokens * (rates?.outputPerMillion ?? 1);
|
|
27
|
-
const wCacheRead = totals.cacheReadTokens * (rates?.cacheReadPerMillion ?? rates?.inputPerMillion ?? 1);
|
|
28
|
-
const wCacheWrite = totals.cacheWriteTokens * (rates?.cacheWritePerMillion ?? rates?.inputPerMillion ?? 1);
|
|
29
|
-
const sum = wInput + wOutput + wCacheRead + wCacheWrite;
|
|
30
|
-
if (!(sum > 0))
|
|
31
|
-
return null;
|
|
32
|
-
const input = cost * (wInput / sum);
|
|
33
|
-
const output = cost * (wOutput / sum);
|
|
34
|
-
const cacheRead = cost * (wCacheRead / sum);
|
|
35
|
-
return [input, output, cacheRead, cost - input - output - cacheRead];
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=cost-split.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-split.js","sourceRoot":"","sources":["../../src/client/cost-split.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,MAAmB,EACnB,KAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC,KAAK,EAAE,eAAe,IAAI,CAAC,CAAC,CAAA;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,GAAG,CAAC,KAAK,EAAE,gBAAgB,IAAI,CAAC,CAAC,CAAA;IACpE,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,GAAG,CAAC,KAAK,EAAE,mBAAmB,IAAI,KAAK,EAAE,eAAe,IAAI,CAAC,CAAC,CAAA;IACvG,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,GAAG,CAAC,KAAK,EAAE,oBAAoB,IAAI,KAAK,EAAE,eAAe,IAAI,CAAC,CAAC,CAAA;IAC1G,MAAM,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAA;IACvD,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;IACnC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,CAAA;IAC3C,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;AACtE,CAAC"}
|