@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,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure session-scope helpers of the conversation view tab (browser half):
|
|
3
|
+
* subagent-tree traversal over the runtime's session-list mirror
|
|
4
|
+
* (parentId + origin), the whole-subtree projection aggregation for TTFT
|
|
5
|
+
* and decode throughput, and the parent lookup the back control uses.
|
|
6
|
+
* No runtime imports beyond types, so the view tab and its tests share one
|
|
7
|
+
* implementation.
|
|
8
|
+
*
|
|
9
|
+
* @module token-usage/client/session-stats
|
|
10
|
+
*/
|
|
11
|
+
import type { SessionStatsProjection } from '@deepseek-ai/dsh-session-stats/client';
|
|
12
|
+
/** The session-summary shape this module reads (a structural slice of the
|
|
13
|
+
* runtime's `SessionSummary` — parent linkage, origin, and the retained
|
|
14
|
+
* host-projection values). */
|
|
15
|
+
export interface SessionRowLike {
|
|
16
|
+
parentId?: string | undefined;
|
|
17
|
+
origin?: 'subagent' | undefined;
|
|
18
|
+
updatedAt?: number | undefined;
|
|
19
|
+
projectionValues?: Readonly<Partial<{
|
|
20
|
+
sessionStats?: SessionStatsProjection;
|
|
21
|
+
}>> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The session-summary map this module reads (keyed by session id). */
|
|
24
|
+
export type SessionRows = Readonly<Record<string, SessionRowLike>>;
|
|
25
|
+
/** A parent → direct-subagent-children index, one O(n) build over {@link
|
|
26
|
+
* SessionRows}. An absent key means "no subagent children under that id";
|
|
27
|
+
* an ordinary fork does not contribute to its parent. */
|
|
28
|
+
export type ChildIndex = ReadonlyMap<string, readonly string[]>;
|
|
29
|
+
/** Build a session-parent → direct-subagent-children index in one O(n) pass:
|
|
30
|
+
* every session whose `origin === 'subagent'` lands in its `parentId`'s
|
|
31
|
+
* bucket, in iteration order (so the result matches {@link directSubagentIds}).
|
|
32
|
+
* @param rows - the retained session-summary mirror.
|
|
33
|
+
* @returns the immutable child index.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildChildIndex(rows: SessionRows): ChildIndex;
|
|
36
|
+
/** Look up the direct subagent children of one session. Falls back to a
|
|
37
|
+
* fresh {@link buildChildIndex} when the caller has no cached index. */
|
|
38
|
+
export declare function directSubagentIds(rows: SessionRows, parentId: string, index?: ChildIndex): readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* The whole subagent subtree of one session, including the root itself,
|
|
41
|
+
* using the parent → children index for an O(n) walk regardless of depth.
|
|
42
|
+
* Cycles are bounded by a `seen` set (a depth-first traversal visits each
|
|
43
|
+
* id once), so a self-referential or cyclic record set returns the root
|
|
44
|
+
* alone. Stacks are reversed after pushing so siblings come back out in
|
|
45
|
+
* insertion order, matching the runtime's lineage index.
|
|
46
|
+
* @param rows - the retained session-summary mirror (unused when the
|
|
47
|
+
* caller already built an index).
|
|
48
|
+
* @param rootId - the scope's root session id.
|
|
49
|
+
* @param index - optional precomputed index from {@link buildChildIndex}.
|
|
50
|
+
* @returns the root and its subagent descendants, depth-first.
|
|
51
|
+
*/
|
|
52
|
+
export declare function subtreeIds(rows: SessionRows, rootId: string, index?: ChildIndex): string[];
|
|
53
|
+
/**
|
|
54
|
+
* The immediate subagent parent of one session, when the record names one.
|
|
55
|
+
* The check is on `parentId` rather than `origin` so a mirrored summary that
|
|
56
|
+
* lost its origin tag still answers its lineage — the index is built once
|
|
57
|
+
* per render and shared across all three helpers via {@link ChildIndex}.
|
|
58
|
+
* @param rows - the retained session-summary mirror.
|
|
59
|
+
* @param id - the current focus session id.
|
|
60
|
+
* @returns the parent session id, or undefined when the record has no
|
|
61
|
+
* parent link (a top-level session or an ordinary fork).
|
|
62
|
+
*/
|
|
63
|
+
export declare function subagentParentOf(rows: SessionRows, id: string): string | undefined;
|
|
64
|
+
/** The session-stats fold the view renders (summed wall-time buckets). */
|
|
65
|
+
export interface StatsAggregate {
|
|
66
|
+
/** Summed first-token latency over `ttftSteps`. */
|
|
67
|
+
ttftMs: number;
|
|
68
|
+
/** Steps carrying a recorded first token. */
|
|
69
|
+
ttftSteps: number;
|
|
70
|
+
/** Summed decode wall time (first token → message) over decode-timed steps. */
|
|
71
|
+
decodeMs: number;
|
|
72
|
+
/** Summed provider output tokens over the same decode-timed steps. */
|
|
73
|
+
decodeTokens: number;
|
|
74
|
+
/** Number of scoped sessions that contributed a `sessionStats` projection
|
|
75
|
+
* value; the rest had no retained projection. Lets the view distinguish
|
|
76
|
+
* "scope had no recorded projections" from "scope is empty". */
|
|
77
|
+
contributing: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sum one or more `SessionStatsProjection` values over a scope. A scope with
|
|
81
|
+
* no value at all yields `undefined` — the view renders an em-dash for an
|
|
82
|
+
* absent capability. The `contributing` count lets the caller tell
|
|
83
|
+
* "every scope session was empty" apart from "the scope itself was empty".
|
|
84
|
+
* @param values - the per-session projection values (typically drawn from
|
|
85
|
+
* the mirror + the live hook).
|
|
86
|
+
* @returns the summed buckets plus the contributing count, or undefined
|
|
87
|
+
* when no projection was present.
|
|
88
|
+
*/
|
|
89
|
+
export declare function aggregateProjections(values: Iterable<SessionStatsProjection | undefined>): StatsAggregate | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Compact fingerprint of one session's retained stats projection — bumps on
|
|
92
|
+
* every finished request step (same signal that drives TTFT / throughput).
|
|
93
|
+
*/
|
|
94
|
+
export declare function sessionStatsFingerprint(stats: SessionStatsProjection | undefined): string;
|
|
95
|
+
/**
|
|
96
|
+
* Build a debounce key from mirror `updatedAt` plus `sessionStats` churn.
|
|
97
|
+
* The active session reads live projection values from `useProjection`; every
|
|
98
|
+
* other scoped id reads the mirror copy.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildStatsFreshnessKey(ids: readonly string[], options: {
|
|
101
|
+
activeSessionId: string;
|
|
102
|
+
rows: SessionRows;
|
|
103
|
+
liveSessionStats?: SessionStatsProjection | undefined;
|
|
104
|
+
}): string;
|
|
105
|
+
//# sourceMappingURL=session-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stats.d.ts","sourceRoot":"","sources":["../../src/client/session-stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,sBA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sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB;;oEAEgE;IAChE,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,CAAC,sBAAsB,GAAG,SAAS,CAAC,GACnD,cAAc,GAAG,SAAS,CAgB5B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,GAAG,MAAM,CAQzF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,OAAO,EAAE;IACP,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,gBAAgB,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAA;CACtD,GACA,MAAM,CAQR"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure session-scope helpers of the conversation view tab (browser half):
|
|
3
|
+
* subagent-tree traversal over the runtime's session-list mirror
|
|
4
|
+
* (parentId + origin), the whole-subtree projection aggregation for TTFT
|
|
5
|
+
* and decode throughput, and the parent lookup the back control uses.
|
|
6
|
+
* No runtime imports beyond types, so the view tab and its tests share one
|
|
7
|
+
* implementation.
|
|
8
|
+
*
|
|
9
|
+
* @module token-usage/client/session-stats
|
|
10
|
+
*/
|
|
11
|
+
/** Build a session-parent → direct-subagent-children index in one O(n) pass:
|
|
12
|
+
* every session whose `origin === 'subagent'` lands in its `parentId`'s
|
|
13
|
+
* bucket, in iteration order (so the result matches {@link directSubagentIds}).
|
|
14
|
+
* @param rows - the retained session-summary mirror.
|
|
15
|
+
* @returns the immutable child index.
|
|
16
|
+
*/
|
|
17
|
+
export function buildChildIndex(rows) {
|
|
18
|
+
const index = new Map();
|
|
19
|
+
for (const [id, summary] of Object.entries(rows)) {
|
|
20
|
+
if (summary.origin !== 'subagent' || summary.parentId === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
const bucket = index.get(summary.parentId);
|
|
23
|
+
if (bucket === undefined)
|
|
24
|
+
index.set(summary.parentId, [id]);
|
|
25
|
+
else
|
|
26
|
+
bucket.push(id);
|
|
27
|
+
}
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
/** Look up the direct subagent children of one session. Falls back to a
|
|
31
|
+
* fresh {@link buildChildIndex} when the caller has no cached index. */
|
|
32
|
+
export function directSubagentIds(rows, parentId, index) {
|
|
33
|
+
if (index !== undefined)
|
|
34
|
+
return index.get(parentId) ?? [];
|
|
35
|
+
return buildChildIndex(rows).get(parentId) ?? [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The whole subagent subtree of one session, including the root itself,
|
|
39
|
+
* using the parent → children index for an O(n) walk regardless of depth.
|
|
40
|
+
* Cycles are bounded by a `seen` set (a depth-first traversal visits each
|
|
41
|
+
* id once), so a self-referential or cyclic record set returns the root
|
|
42
|
+
* alone. Stacks are reversed after pushing so siblings come back out in
|
|
43
|
+
* insertion order, matching the runtime's lineage index.
|
|
44
|
+
* @param rows - the retained session-summary mirror (unused when the
|
|
45
|
+
* caller already built an index).
|
|
46
|
+
* @param rootId - the scope's root session id.
|
|
47
|
+
* @param index - optional precomputed index from {@link buildChildIndex}.
|
|
48
|
+
* @returns the root and its subagent descendants, depth-first.
|
|
49
|
+
*/
|
|
50
|
+
export function subtreeIds(rows, rootId, index = buildChildIndex(rows)) {
|
|
51
|
+
const out = [rootId];
|
|
52
|
+
if (!index.has(rootId) && rows[rootId] === undefined)
|
|
53
|
+
return out;
|
|
54
|
+
const seen = new Set([rootId]);
|
|
55
|
+
const stack = [];
|
|
56
|
+
const seedChildren = index.get(rootId) ?? [];
|
|
57
|
+
for (let i = seedChildren.length - 1; i >= 0; i -= 1)
|
|
58
|
+
stack.push(seedChildren[i]);
|
|
59
|
+
while (stack.length > 0) {
|
|
60
|
+
const current = stack.pop();
|
|
61
|
+
if (seen.has(current))
|
|
62
|
+
continue;
|
|
63
|
+
seen.add(current);
|
|
64
|
+
out.push(current);
|
|
65
|
+
const children = index.get(current) ?? [];
|
|
66
|
+
for (let i = children.length - 1; i >= 0; i -= 1)
|
|
67
|
+
stack.push(children[i]);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The immediate subagent parent of one session, when the record names one.
|
|
73
|
+
* The check is on `parentId` rather than `origin` so a mirrored summary that
|
|
74
|
+
* lost its origin tag still answers its lineage — the index is built once
|
|
75
|
+
* per render and shared across all three helpers via {@link ChildIndex}.
|
|
76
|
+
* @param rows - the retained session-summary mirror.
|
|
77
|
+
* @param id - the current focus session id.
|
|
78
|
+
* @returns the parent session id, or undefined when the record has no
|
|
79
|
+
* parent link (a top-level session or an ordinary fork).
|
|
80
|
+
*/
|
|
81
|
+
export function subagentParentOf(rows, id) {
|
|
82
|
+
const parent = rows[id]?.parentId;
|
|
83
|
+
return parent === undefined || parent === id ? undefined : parent;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sum one or more `SessionStatsProjection` values over a scope. A scope with
|
|
87
|
+
* no value at all yields `undefined` — the view renders an em-dash for an
|
|
88
|
+
* absent capability. The `contributing` count lets the caller tell
|
|
89
|
+
* "every scope session was empty" apart from "the scope itself was empty".
|
|
90
|
+
* @param values - the per-session projection values (typically drawn from
|
|
91
|
+
* the mirror + the live hook).
|
|
92
|
+
* @returns the summed buckets plus the contributing count, or undefined
|
|
93
|
+
* when no projection was present.
|
|
94
|
+
*/
|
|
95
|
+
export function aggregateProjections(values) {
|
|
96
|
+
let ttftMs = 0;
|
|
97
|
+
let ttftSteps = 0;
|
|
98
|
+
let decodeMs = 0;
|
|
99
|
+
let decodeTokens = 0;
|
|
100
|
+
let contributing = 0;
|
|
101
|
+
for (const stats of values) {
|
|
102
|
+
if (stats === undefined)
|
|
103
|
+
continue;
|
|
104
|
+
contributing += 1;
|
|
105
|
+
ttftMs += stats.ttftMs;
|
|
106
|
+
ttftSteps += stats.ttftSteps;
|
|
107
|
+
decodeMs += stats.decodeMs;
|
|
108
|
+
decodeTokens += stats.decodeTokens;
|
|
109
|
+
}
|
|
110
|
+
if (contributing === 0)
|
|
111
|
+
return undefined;
|
|
112
|
+
return { ttftMs, ttftSteps, decodeMs, decodeTokens, contributing };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Compact fingerprint of one session's retained stats projection — bumps on
|
|
116
|
+
* every finished request step (same signal that drives TTFT / throughput).
|
|
117
|
+
*/
|
|
118
|
+
export function sessionStatsFingerprint(stats) {
|
|
119
|
+
if (stats === undefined)
|
|
120
|
+
return '-';
|
|
121
|
+
return [
|
|
122
|
+
stats.steps,
|
|
123
|
+
stats.ttftSteps,
|
|
124
|
+
stats.decodeTokens,
|
|
125
|
+
stats.turns,
|
|
126
|
+
].join('.');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build a debounce key from mirror `updatedAt` plus `sessionStats` churn.
|
|
130
|
+
* The active session reads live projection values from `useProjection`; every
|
|
131
|
+
* other scoped id reads the mirror copy.
|
|
132
|
+
*/
|
|
133
|
+
export function buildStatsFreshnessKey(ids, options) {
|
|
134
|
+
return ids.map(id => {
|
|
135
|
+
const row = options.rows[id];
|
|
136
|
+
const stats = id === options.activeSessionId
|
|
137
|
+
? options.liveSessionStats ?? row?.projectionValues?.sessionStats
|
|
138
|
+
: row?.projectionValues?.sessionStats;
|
|
139
|
+
return `${id}:${String(row?.updatedAt ?? 0)}:${sessionStatsFingerprint(stats)}`;
|
|
140
|
+
}).join(',');
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=session-stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-stats.js","sourceRoot":"","sources":["../../src/client/session-stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsBH;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAiB;IAC/C,MAAM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,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAA;IACjF,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart axis helpers: the roundest step from 1/2/2.5/5 × 10ⁿ not
|
|
3
|
+
* below a rough target, and the y-axis tick values (one nice step apart,
|
|
4
|
+
* inclusive of the chart top). Pure functions, no React, no I/O.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/trend-chart/axis
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The roundest step from {1, 2, 2.5, 5, 10} × 10ⁿ not below `rough`.
|
|
10
|
+
* A `niceStep(0)` returns 1; a `niceStep(80)` returns 100 (the next nice
|
|
11
|
+
* step above 80 in the same decade).
|
|
12
|
+
* @param rough - the target value (positive).
|
|
13
|
+
* @returns the nice step.
|
|
14
|
+
*/
|
|
15
|
+
export declare function niceStep(rough: number): number;
|
|
16
|
+
/** The y-axis tick values from one step up to the chart top (inclusive). */
|
|
17
|
+
export declare function tickValues(max: number): {
|
|
18
|
+
top: number;
|
|
19
|
+
ticks: number[];
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=axis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../../src/client/trend-chart/axis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAQxE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart axis helpers: the roundest step from 1/2/2.5/5 × 10ⁿ not
|
|
3
|
+
* below a rough target, and the y-axis tick values (one nice step apart,
|
|
4
|
+
* inclusive of the chart top). Pure functions, no React, no I/O.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/trend-chart/axis
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The roundest step from {1, 2, 2.5, 5, 10} × 10ⁿ not below `rough`.
|
|
10
|
+
* A `niceStep(0)` returns 1; a `niceStep(80)` returns 100 (the next nice
|
|
11
|
+
* step above 80 in the same decade).
|
|
12
|
+
* @param rough - the target value (positive).
|
|
13
|
+
* @returns the nice step.
|
|
14
|
+
*/
|
|
15
|
+
export function niceStep(rough) {
|
|
16
|
+
const base = 10 ** Math.floor(Math.log10(rough));
|
|
17
|
+
const fraction = rough / base;
|
|
18
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
19
|
+
return nice * base;
|
|
20
|
+
}
|
|
21
|
+
/** The y-axis tick values from one step up to the chart top (inclusive). */
|
|
22
|
+
export function tickValues(max) {
|
|
23
|
+
if (max === 0)
|
|
24
|
+
return { top: 1, ticks: [] };
|
|
25
|
+
const step = niceStep(max / 4);
|
|
26
|
+
const top = Math.ceil(max / step) * step;
|
|
27
|
+
const ticks = [];
|
|
28
|
+
for (let value = step; value < top; value += step)
|
|
29
|
+
ticks.push(value);
|
|
30
|
+
ticks.push(top);
|
|
31
|
+
return { top, ticks };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=axis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axis.js","sourceRoot":"","sources":["../../../src/client/trend-chart/axis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,MAAM,IAAI,GAAG,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAChD,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAA;IAC7B,MAAM,IAAI,GAAG,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACnG,OAAO,IAAI,GAAG,IAAI,CAAA;AACpB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;IACxC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,GAAG,EAAE,KAAK,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACf,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AACvB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart bucket folding and temporal x scaling (browser half).
|
|
3
|
+
* Folding lives in the shared `trend-bucket` module so the host route can
|
|
4
|
+
* downsample the request series onto the wire; this file re-exports it and
|
|
5
|
+
* keeps the SVG-only `scaleToSpan`.
|
|
6
|
+
*
|
|
7
|
+
* @module token-usage/client/trend-chart/bucket
|
|
8
|
+
*/
|
|
9
|
+
export { MAX_BUCKETS, bucketSeries, bucketWidth, pointsOfBuckets } from '../../trend-bucket.ts';
|
|
10
|
+
export type { TrendBucket } from '../../trend-bucket.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Scale one wall time into an x offset across the series' actual span —
|
|
13
|
+
* the first and last points pin the axis ends, and everything in between
|
|
14
|
+
* lands at its real proportion of that span (a 55-request session
|
|
15
|
+
* spreads across the full width, a burst inside one minute bunches up).
|
|
16
|
+
* @param firstTime - the series' first record time.
|
|
17
|
+
* @param lastTime - the series' last record time.
|
|
18
|
+
* @param time - the record's wall time.
|
|
19
|
+
* @param innerWidth - the plottable width in pixels.
|
|
20
|
+
* @returns the x offset from the left edge; the center when every record
|
|
21
|
+
* shares one timestamp (a zero span cannot scale).
|
|
22
|
+
*/
|
|
23
|
+
export declare function scaleToSpan(firstTime: number, lastTime: number, time: number, innerWidth: number): number;
|
|
24
|
+
//# sourceMappingURL=bucket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket.d.ts","sourceRoot":"","sources":["../../../src/client/trend-chart/bucket.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC/F,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAIzG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart bucket folding and temporal x scaling (browser half).
|
|
3
|
+
* Folding lives in the shared `trend-bucket` module so the host route can
|
|
4
|
+
* downsample the request series onto the wire; this file re-exports it and
|
|
5
|
+
* keeps the SVG-only `scaleToSpan`.
|
|
6
|
+
*
|
|
7
|
+
* @module token-usage/client/trend-chart/bucket
|
|
8
|
+
*/
|
|
9
|
+
export { MAX_BUCKETS, bucketSeries, bucketWidth, pointsOfBuckets } from "../../trend-bucket.js";
|
|
10
|
+
/**
|
|
11
|
+
* Scale one wall time into an x offset across the series' actual span —
|
|
12
|
+
* the first and last points pin the axis ends, and everything in between
|
|
13
|
+
* lands at its real proportion of that span (a 55-request session
|
|
14
|
+
* spreads across the full width, a burst inside one minute bunches up).
|
|
15
|
+
* @param firstTime - the series' first record time.
|
|
16
|
+
* @param lastTime - the series' last record time.
|
|
17
|
+
* @param time - the record's wall time.
|
|
18
|
+
* @param innerWidth - the plottable width in pixels.
|
|
19
|
+
* @returns the x offset from the left edge; the center when every record
|
|
20
|
+
* shares one timestamp (a zero span cannot scale).
|
|
21
|
+
*/
|
|
22
|
+
export function scaleToSpan(firstTime, lastTime, time, innerWidth) {
|
|
23
|
+
const span = lastTime - firstTime;
|
|
24
|
+
if (span <= 0)
|
|
25
|
+
return innerWidth / 2;
|
|
26
|
+
return (time - firstTime) / span * innerWidth;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=bucket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket.js","sourceRoot":"","sources":["../../../src/client/trend-chart/bucket.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAG/F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,QAAgB,EAAE,IAAY,EAAE,UAAkB;IAC/F,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAA;IACjC,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,UAAU,GAAG,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,UAAU,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public re-exports of the trend-chart helpers, so the test suite and
|
|
3
|
+
* any future module can import them from a single barrel.
|
|
4
|
+
*/
|
|
5
|
+
export { MAX_BUCKETS, bucketSeries, bucketWidth, scaleToSpan } from './bucket.ts';
|
|
6
|
+
export type { TrendBucket } from './bucket.ts';
|
|
7
|
+
export { niceStep, tickValues } from './axis.ts';
|
|
8
|
+
export { buildChartPoints } from './points.ts';
|
|
9
|
+
export type { ChartSeries } from './points.ts';
|
|
10
|
+
export { dotRadius, labelIndices, scaleSeries } from './scale.ts';
|
|
11
|
+
export type { ScaleResult } from './scale.ts';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/trend-chart/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACjF,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACjE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public re-exports of the trend-chart helpers, so the test suite and
|
|
3
|
+
* any future module can import them from a single barrel.
|
|
4
|
+
*/
|
|
5
|
+
export { MAX_BUCKETS, bucketSeries, bucketWidth, scaleToSpan } from "./bucket.js";
|
|
6
|
+
export { niceStep, tickValues } from "./axis.js";
|
|
7
|
+
export { buildChartPoints } from "./points.js";
|
|
8
|
+
export { dotRadius, labelIndices, scaleSeries } from "./scale.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/trend-chart/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEjF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart point series: fold the three render-mode inputs (per-day
|
|
3
|
+
* rows, per-hour rows, per-request series) into one discriminated-union
|
|
4
|
+
* series with the mode decided at the top. Pure functions, no React.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/trend-chart/points
|
|
7
|
+
*/
|
|
8
|
+
import type { RequestPoint, UsageDayRow, UsageHourRow } from '../../wire.ts';
|
|
9
|
+
/**
|
|
10
|
+
* The chart series, normalised over the three render modes. Equidistant
|
|
11
|
+
* modes (days, hours) advance `index` one step per point; temporal mode
|
|
12
|
+
* (request buckets) attaches the wall time so the renderer scales each
|
|
13
|
+
* point at its real temporal proportion of the span.
|
|
14
|
+
*/
|
|
15
|
+
export type ChartSeries = {
|
|
16
|
+
mode: 'equidistant';
|
|
17
|
+
points: {
|
|
18
|
+
key: string;
|
|
19
|
+
label: string;
|
|
20
|
+
full: string;
|
|
21
|
+
tokens: number;
|
|
22
|
+
}[];
|
|
23
|
+
} | {
|
|
24
|
+
mode: 'temporal';
|
|
25
|
+
points: {
|
|
26
|
+
key: string;
|
|
27
|
+
label: string;
|
|
28
|
+
full: string;
|
|
29
|
+
tokens: number;
|
|
30
|
+
time: number;
|
|
31
|
+
count: number;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
interface BuildPointsInput {
|
|
35
|
+
rows: readonly UsageDayRow[];
|
|
36
|
+
hours?: readonly UsageHourRow[] | undefined;
|
|
37
|
+
requests?: readonly RequestPoint[] | undefined;
|
|
38
|
+
from?: string | undefined;
|
|
39
|
+
to?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** Render-mode priority: request buckets outrank per-hour, which
|
|
42
|
+
* outranks per-day. A session-scoped read passes `requests`; the settings
|
|
43
|
+
* page passes `hours` for a single-day range; everything else plots days. */
|
|
44
|
+
export declare function buildChartPoints(input: BuildPointsInput): ChartSeries | null;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=points.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"points.d.ts","sourceRoot":"","sources":["../../../src/client/trend-chart/points.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAM5E;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,GAC/F;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAA;AAE7H,UAAU,gBAAgB;IACxB,IAAI,EAAE,SAAS,WAAW,EAAE,CAAA;IAC5B,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;IAC3C,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;IAC9C,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACxB;AAED;;6EAE6E;AAC7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW,GAAG,IAAI,CA+B5E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart point series: fold the three render-mode inputs (per-day
|
|
3
|
+
* rows, per-hour rows, per-request series) into one discriminated-union
|
|
4
|
+
* series with the mode decided at the top. Pure functions, no React.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/trend-chart/points
|
|
7
|
+
*/
|
|
8
|
+
import { daySeries, hourSeries } from "../day.js";
|
|
9
|
+
import { bucketSeries } from "./bucket.js";
|
|
10
|
+
/** Render-mode priority: request buckets outrank per-hour, which
|
|
11
|
+
* outranks per-day. A session-scoped read passes `requests`; the settings
|
|
12
|
+
* page passes `hours` for a single-day range; everything else plots days. */
|
|
13
|
+
export function buildChartPoints(input) {
|
|
14
|
+
if (input.requests !== undefined && input.requests.length > 0) {
|
|
15
|
+
const buckets = bucketsOf(input.requests);
|
|
16
|
+
if (buckets.length > 0) {
|
|
17
|
+
const firstDate = new Date(buckets[0].start).toDateString();
|
|
18
|
+
const lastDate = new Date(buckets[buckets.length - 1].start).toDateString();
|
|
19
|
+
const crossDay = firstDate !== lastDate;
|
|
20
|
+
return {
|
|
21
|
+
mode: 'temporal',
|
|
22
|
+
points: buckets.map((bucket, index) => ({
|
|
23
|
+
key: `b${index}`,
|
|
24
|
+
label: bucketLabel(bucket.start, crossDay),
|
|
25
|
+
full: `${bucketLabel(bucket.start, crossDay)}–${bucketLabel(bucket.end, crossDay)}`,
|
|
26
|
+
tokens: bucket.tokens,
|
|
27
|
+
time: bucket.start,
|
|
28
|
+
count: bucket.count,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (input.hours !== undefined) {
|
|
34
|
+
const points = hourSeries(input.hours, input.from, input.to);
|
|
35
|
+
if (points.length > 0) {
|
|
36
|
+
return { mode: 'equidistant', points: points.map(hourToPoint) };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const points = daySeries(input.rows, input.from, input.to);
|
|
40
|
+
if (points.length > 0) {
|
|
41
|
+
return { mode: 'equidistant', points: points.map(dayToPoint) };
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/** A series that already carries `count` (the host's `fields=session`
|
|
46
|
+
* downsample) is plotted as-is; a raw per-request series is folded here. */
|
|
47
|
+
function bucketsOf(requests) {
|
|
48
|
+
if (requests[0]?.count !== undefined) {
|
|
49
|
+
return requests.map(point => ({
|
|
50
|
+
start: point.time,
|
|
51
|
+
end: point.end ?? point.time,
|
|
52
|
+
tokens: point.tokens,
|
|
53
|
+
count: point.count ?? 1,
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
return bucketSeries(requests);
|
|
57
|
+
}
|
|
58
|
+
function dayToPoint(point) {
|
|
59
|
+
return { key: point.day, label: point.day.slice(5), full: point.day, tokens: point.tokens };
|
|
60
|
+
}
|
|
61
|
+
function hourToPoint(point) {
|
|
62
|
+
return {
|
|
63
|
+
key: point.hour,
|
|
64
|
+
label: `${point.hour.slice(11)}:00`,
|
|
65
|
+
full: `${point.hour.slice(0, 10)} ${point.hour.slice(11)}:00`,
|
|
66
|
+
tokens: point.tokens,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Zero-padded HH:mm of one wall time, local-time. */
|
|
70
|
+
function clockOf(time) {
|
|
71
|
+
const d = new Date(time);
|
|
72
|
+
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
73
|
+
}
|
|
74
|
+
/** The x-axis label of one bucket start: HH:mm within one day,
|
|
75
|
+
* MM-DD HH:mm once the session crosses midnight. */
|
|
76
|
+
function bucketLabel(time, crossDay) {
|
|
77
|
+
if (!crossDay)
|
|
78
|
+
return clockOf(time);
|
|
79
|
+
const d = new Date(time);
|
|
80
|
+
return `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${clockOf(time)}`;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=points.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"points.js","sourceRoot":"","sources":["../../../src/client/trend-chart/points.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAqB1C;;6EAE6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACtD,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACzC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,CAAA;YAC5D,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,CAAA;YAC5E,MAAM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,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;AAC9F,CAAC;AAED;oDACoD;AACpD,SAAS,WAAW,CAAC,IAAY,EAAE,QAAiB;IAClD,IAAI,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;IACxB,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;AAChH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trend-chart x scaling: pick the right scale for a series mode and
|
|
3
|
+
* return the per-point offsets in one pass. Pure functions, no React.
|
|
4
|
+
*
|
|
5
|
+
* @module token-usage/client/trend-chart/scale
|
|
6
|
+
*/
|
|
7
|
+
import type { ChartSeries } from './points.ts';
|
|
8
|
+
/** A scale decision plus the per-point x offsets, expressed as **absolute
|
|
9
|
+
* SVG viewBox coordinates** (already offset by `leftEdge`). Returning
|
|
10
|
+
* absolute coords prevents the "renderer forgot to add `LEFT`" bug that
|
|
11
|
+
* shows up as a line hugging the very-left edge of the chart area. */
|
|
12
|
+
export interface ScaleResult {
|
|
13
|
+
/** The x offset of every point in SVG viewBox coordinates (range
|
|
14
|
+
* `[leftEdge, rightEdge]`). */
|
|
15
|
+
xs: number[];
|
|
16
|
+
/** The plottable width (rightEdge − leftEdge); the renderer can use it
|
|
17
|
+
* for hit-target extents and label clamps. */
|
|
18
|
+
innerWidth: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pick the right x scale for a {@link ChartSeries} and produce the
|
|
22
|
+
* per-point offsets in absolute viewBox coordinates. Equidistant modes
|
|
23
|
+
* lay points one stride apart across the `[leftEdge, rightEdge]` span;
|
|
24
|
+
* temporal mode uses each point's wall time against the series' own
|
|
25
|
+
* first-to-last span and adds `leftEdge` to the result. Single-point
|
|
26
|
+
* series pin to the centerline of the span (a zero stride would not
|
|
27
|
+
* scale, and temporal scale would divide by zero).
|
|
28
|
+
*
|
|
29
|
+
* @param series - the discriminated-union series from {@link buildChartPoints}.
|
|
30
|
+
* @param leftEdge - the absolute SVG x of the chart's left edge (the
|
|
31
|
+
* y-axis line in the renderer).
|
|
32
|
+
* @param rightEdge - the absolute SVG x of the chart's right edge
|
|
33
|
+
* (typically `viewBox.width − RIGHT.margin`).
|
|
34
|
+
* @returns the per-point x offsets plus `innerWidth = rightEdge − leftEdge`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function scaleSeries(series: ChartSeries, leftEdge: number, rightEdge: number): ScaleResult;
|
|
37
|
+
/**
|
|
38
|
+
* The x-axis label positions: first, middle, and last point for long
|
|
39
|
+
* ranges. Short ranges (≤3 points) label every point so a 1- or 2- day
|
|
40
|
+
* window does not skip the only "middle" data.
|
|
41
|
+
*/
|
|
42
|
+
export declare function labelIndices(length: number): number[];
|
|
43
|
+
/** Choose a dot radius that survives dense point clouds without
|
|
44
|
+
* overlapping but stays visible for sparse ones. Three tiers, picked by
|
|
45
|
+
* point count. */
|
|
46
|
+
export declare function dotRadius(pointCount: number): number;
|
|
47
|
+
//# sourceMappingURL=scale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/client/trend-chart/scale.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAG9C;;;sEAGsE;AACtE,MAAM,WAAW,WAAW;IAC1B;mCAC+B;IAC/B,EAAE,EAAE,MAAM,EAAE,CAAA;IACZ;kDAC8C;IAC9C,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAyBjG;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAIrD;AAED;;kBAEkB;AAClB,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIpD"}
|