@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,346 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Input-bar quota button (browser half): a 28×28 round trigger registered
|
|
4
|
+
* into the `conversation.input.right` slot (it renders left of the model
|
|
5
|
+
* chip — the host's fixed tool-row order). The glyph is a remaining-share
|
|
6
|
+
* ring (ContextMeter family) colored by the finest window. Clicking opens a
|
|
7
|
+
* width-tiered popup (amount-only 200px / one progress bar 232px / two
|
|
8
|
+
* bars 320px) centered on the button with the current provider's quota
|
|
9
|
+
* windows: progress columns (5 小时 / 每周) for coding-plan providers, an
|
|
10
|
+
* amount row for balance providers.
|
|
11
|
+
*
|
|
12
|
+
* The provider follows the model CHIP's live selection (the shell's
|
|
13
|
+
* model-selection service reports the host's next selection before any
|
|
14
|
+
* request is sent); without that service the host falls back to the last
|
|
15
|
+
* request's provider, else the default selection.
|
|
16
|
+
*
|
|
17
|
+
* The button SELF-GATES: it renders nothing while the host cannot
|
|
18
|
+
* determine a provider (`no-provider`), the provider has no quota adapter
|
|
19
|
+
* (`unsupported`), or the feature is off (`disabled`) — switching
|
|
20
|
+
* providers makes it appear again. A supported provider whose query fails
|
|
21
|
+
* KEEPS the button and shows the error with a retry inside the panel.
|
|
22
|
+
*
|
|
23
|
+
* The hover tooltip reads provider name + the finest window's exact
|
|
24
|
+
* remaining figure (percent, or the amount when no ratio exists).
|
|
25
|
+
*
|
|
26
|
+
* The interaction copies ContextMeter verbatim (click toggles, document
|
|
27
|
+
* pointerdown outside closes, Escape closes); mutual exclusion with the
|
|
28
|
+
* ContextMeter panel falls out of both components' outside-close
|
|
29
|
+
* handlers — opening one closes the other on its next pointerdown.
|
|
30
|
+
*
|
|
31
|
+
* @module token-usage/client/QuotaButton
|
|
32
|
+
*/
|
|
33
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
34
|
+
import { Tooltip } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
35
|
+
import { QUOTA_PATH } from "../wire.js";
|
|
36
|
+
import { useAsyncResource } from "./async-resource.js";
|
|
37
|
+
import { finestQuotaWindow, formatQuotaClock, formatQuotaMoney, formatQuotaPercent, formatResetCountdown, quotaIconFillShare, quotaRemainingPercent, quotaSeverityOf, quotaTriggerFigure, quotaUsedPercent, } from "./quota-format.js";
|
|
38
|
+
import { useColorSchemeMirror } from "./use-color-scheme.js";
|
|
39
|
+
import styles from './QuotaButton.module.css';
|
|
40
|
+
/** The poll cadence fallback (seconds) while no payload has named one. */
|
|
41
|
+
const DEFAULT_POLL_SEC = 60;
|
|
42
|
+
/** Panel width tiers (px), by how much the windows paint: a lone amount
|
|
43
|
+
* reads at a glance, one progress bar needs breathing room, two bars (the
|
|
44
|
+
* 5-hour + weekly coding plans, or a long error body) the full plate. Kept
|
|
45
|
+
* in sync with the CSS max-width clamp. */
|
|
46
|
+
const PANEL_WIDTH_BALANCE = 200;
|
|
47
|
+
const PANEL_WIDTH_SINGLE = 232;
|
|
48
|
+
const PANEL_WIDTH_FULL = 320;
|
|
49
|
+
const PANEL_VIEWPORT_MARGIN = 16;
|
|
50
|
+
/** Tier → label key; the locale dictionaries carry both languages. */
|
|
51
|
+
const TIER_LABEL_KEYS = {
|
|
52
|
+
five_hour: 'quota.tier.fiveHour',
|
|
53
|
+
weekly: 'quota.tier.weekly',
|
|
54
|
+
monthly: 'quota.tier.monthly',
|
|
55
|
+
balance: 'quota.tier.balance',
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Render the input-bar quota button for the active session's provider.
|
|
59
|
+
* @param props - the framework session id, the locale seat, and the
|
|
60
|
+
* optional model-directory holder (the chip's live selection).
|
|
61
|
+
* @returns the trigger + panel, or null while hidden (see the module note).
|
|
62
|
+
*/
|
|
63
|
+
export function QuotaButton({ sessionId, t, modelDirectory }) {
|
|
64
|
+
const rootRef = useRef(null);
|
|
65
|
+
useColorSchemeMirror(rootRef);
|
|
66
|
+
const [open, setOpen] = useState(false);
|
|
67
|
+
// The panel centers on the button rather than corner-anchoring to it:
|
|
68
|
+
// the harness's own popups sit flush right because their triggers own the
|
|
69
|
+
// row's right end, but this one renders left of the model chip, where a
|
|
70
|
+
// right-aligned panel would skew up-left. The slot exposes no positioned
|
|
71
|
+
// ancestor to lean on, so the offset is measured from the wrapper (whose
|
|
72
|
+
// position: relative hosts the panel) — panel center on button center,
|
|
73
|
+
// nudged to stay inside the viewport's 16px margins (the button sits in
|
|
74
|
+
// the right cluster, where a bare centering could push the panel
|
|
75
|
+
// off-screen on narrow windows). Set at open time, refreshed on resize
|
|
76
|
+
// and any ancestor scroll while open.
|
|
77
|
+
const [panelLeft, setPanelLeft] = useState(undefined);
|
|
78
|
+
const measurePanelLeft = useCallback((width) => {
|
|
79
|
+
const wrapper = rootRef.current;
|
|
80
|
+
if (wrapper === null)
|
|
81
|
+
return;
|
|
82
|
+
const { left: wrapperLeft, width: wrapperWidth } = wrapper.getBoundingClientRect();
|
|
83
|
+
const panelWidth = Math.min(width, window.innerWidth - 2 * PANEL_VIEWPORT_MARGIN);
|
|
84
|
+
const desired = (wrapperWidth - panelWidth) / 2;
|
|
85
|
+
const minLeft = PANEL_VIEWPORT_MARGIN - wrapperLeft;
|
|
86
|
+
const maxLeft = window.innerWidth - PANEL_VIEWPORT_MARGIN - panelWidth - wrapperLeft;
|
|
87
|
+
setPanelLeft(Math.min(Math.max(desired, minLeft), Math.max(minLeft, maxLeft)));
|
|
88
|
+
}, []);
|
|
89
|
+
// The provider the model chip currently selects — the host-reported NEXT
|
|
90
|
+
// selection, live before any request is sent. Seeded synchronously (the
|
|
91
|
+
// chip's directory has usually loaded by the time this button mounts),
|
|
92
|
+
// then kept live through the store subscription; absent when the shell's
|
|
93
|
+
// model-selection service is unavailable or has not loaded yet, in which
|
|
94
|
+
// case the host falls back to its own resolution (last request's
|
|
95
|
+
// provider, else the default model selection).
|
|
96
|
+
const modelService = modelDirectory?.service;
|
|
97
|
+
const readChipProvider = () => {
|
|
98
|
+
if (sessionId === '' || modelService === undefined)
|
|
99
|
+
return undefined;
|
|
100
|
+
try {
|
|
101
|
+
return modelService.directoryFor(sessionId).store.getSnapshot().current?.provider ?? undefined;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// An unresolvable session scope (e.g. a transient subagent address)
|
|
105
|
+
// simply contributes no hint.
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const [chipProvider, setChipProvider] = useState(readChipProvider);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
// Re-seed on session/service change, then subscribe for chip switches.
|
|
112
|
+
setChipProvider(readChipProvider());
|
|
113
|
+
if (sessionId === '' || modelService === undefined)
|
|
114
|
+
return;
|
|
115
|
+
let directory;
|
|
116
|
+
try {
|
|
117
|
+
directory = modelService.directoryFor(sessionId);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return directory.store.subscribe(() => { setChipProvider(readChipProvider()); });
|
|
123
|
+
// The synchronous reader is intentionally not a dep: it closes over the
|
|
124
|
+
// two deps below and would re-run the effect on every render.
|
|
125
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
126
|
+
}, [sessionId, modelService]);
|
|
127
|
+
const [resource, retry] = useAsyncResource(signal => fetchQuotaPayload(sessionId, chipProvider, signal), [sessionId, chipProvider], { silentAfterFirst: true, retryToken: 0 });
|
|
128
|
+
const payload = resource.status === 'ready' ? resource.value : null;
|
|
129
|
+
// The width tier follows what the windows paint (amount-only / one bar /
|
|
130
|
+
// two bars — see {@link panelWidthOf}); errors read the full plate.
|
|
131
|
+
const panelWidth = panelWidthOf(payload);
|
|
132
|
+
// The cadence follows the host's config (stamped on every payload); the
|
|
133
|
+
// fallback only covers the very first polls.
|
|
134
|
+
const pollMs = (payload?.intervalSec ?? DEFAULT_POLL_SEC) * 1000;
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const timer = setInterval(retry, pollMs);
|
|
137
|
+
return () => { clearInterval(timer); };
|
|
138
|
+
}, [pollMs, retry]);
|
|
139
|
+
// Visible only for a determinable, adapter-backed provider; errors keep
|
|
140
|
+
// the button (the panel carries them).
|
|
141
|
+
const visible = payload !== null && (payload.status === 'ok' || payload.status === 'error');
|
|
142
|
+
// A provider switch (or a turn to unsupported) mid-panel closes it.
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (!visible && open)
|
|
145
|
+
setOpen(false);
|
|
146
|
+
}, [visible, open]);
|
|
147
|
+
// Outside click / Escape close — ContextMeter's pattern, one document
|
|
148
|
+
// listener pair while open.
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!open)
|
|
151
|
+
return;
|
|
152
|
+
const onPointerDown = (event) => {
|
|
153
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true)
|
|
154
|
+
return;
|
|
155
|
+
setOpen(false);
|
|
156
|
+
};
|
|
157
|
+
const onKeyDown = (event) => {
|
|
158
|
+
if (event.key === 'Escape')
|
|
159
|
+
setOpen(false);
|
|
160
|
+
};
|
|
161
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
162
|
+
document.addEventListener('keydown', onKeyDown);
|
|
163
|
+
return () => {
|
|
164
|
+
document.removeEventListener('pointerdown', onPointerDown);
|
|
165
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
166
|
+
};
|
|
167
|
+
}, [open]);
|
|
168
|
+
// While open, a viewport resize or any ancestor scroll moves the button
|
|
169
|
+
// — re-measure so the panel keeps following its center. Re-running on a
|
|
170
|
+
// width-tier change (a provider switch mid-panel) re-centers too.
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (!open)
|
|
173
|
+
return;
|
|
174
|
+
const onViewportChange = () => { measurePanelLeft(panelWidth); };
|
|
175
|
+
measurePanelLeft(panelWidth);
|
|
176
|
+
window.addEventListener('resize', onViewportChange);
|
|
177
|
+
window.addEventListener('scroll', onViewportChange, true);
|
|
178
|
+
return () => {
|
|
179
|
+
window.removeEventListener('resize', onViewportChange);
|
|
180
|
+
window.removeEventListener('scroll', onViewportChange, true);
|
|
181
|
+
};
|
|
182
|
+
}, [open, panelWidth, measurePanelLeft]);
|
|
183
|
+
if (!visible || payload === null)
|
|
184
|
+
return null;
|
|
185
|
+
const windows = payload.status === 'ok' ? payload.windows : [];
|
|
186
|
+
// The icon reads the FINEST-granularity window (5-hour over weekly over
|
|
187
|
+
// balance), not the worst across them — the finest unit is the constraint
|
|
188
|
+
// the session currently acts inside.
|
|
189
|
+
const finest = finestQuotaWindow(windows);
|
|
190
|
+
const severity = finest === undefined ? 'ok' : quotaSeverityOf(finest);
|
|
191
|
+
const triggerClass = [styles.trigger];
|
|
192
|
+
if (severity === 'warn')
|
|
193
|
+
triggerClass.push(styles['icon-warn']);
|
|
194
|
+
else if (severity === 'exhausted')
|
|
195
|
+
triggerClass.push(styles['icon-exhausted']);
|
|
196
|
+
else if (finest !== undefined && quotaRemainingPercent(finest) !== undefined) {
|
|
197
|
+
// A healthy ratio window (or an amount WITH a total, ratio-colored the
|
|
198
|
+
// same way) reads green, completing the traffic light; an absolute
|
|
199
|
+
// amount without a total stays neutral — it colors only at ≤ 0 (red).
|
|
200
|
+
triggerClass.push(styles['icon-ok']);
|
|
201
|
+
}
|
|
202
|
+
const triggerClassName = triggerClass.join(' ').trim();
|
|
203
|
+
// The hover tooltip carries the exact figure the ring approximates:
|
|
204
|
+
// provider name + the finest window's remaining share (its amount when
|
|
205
|
+
// no ratio exists); errors and window-less payloads keep the plain
|
|
206
|
+
// label.
|
|
207
|
+
const figure = quotaTriggerFigure(finest);
|
|
208
|
+
const triggerTip = figure === undefined
|
|
209
|
+
? t('quota.trigger')
|
|
210
|
+
: t('quota.triggerSummary', { name: payload.providerName ?? payload.provider, figure });
|
|
211
|
+
return (_jsxs("span", { ref: rootRef, className: styles.root, children: [_jsx(Tooltip, { label: triggerTip, side: "top", delayMs: 200, disabled: open, children: _jsx("button", { type: "button", className: triggerClassName, "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": t('quota.trigger'),
|
|
212
|
+
// Opening refreshes (the host's TTL cache keeps it cheap) and
|
|
213
|
+
// measures the centered placement before the panel's first paint;
|
|
214
|
+
// closing does neither — the poll cadence covers the data.
|
|
215
|
+
onClick: () => { if (!open) {
|
|
216
|
+
retry();
|
|
217
|
+
measurePanelLeft(panelWidth);
|
|
218
|
+
} setOpen(!open); }, children: _jsx(QuotaGlyph, { share: quotaIconFillShare(finest) }) }) }), open && (_jsxs("div", { className: styles.panel, role: "dialog", "aria-label": t('quota.panel'), style: {
|
|
219
|
+
width: `${String(panelWidth)}px`,
|
|
220
|
+
...(panelLeft === undefined ? {} : { left: `${String(panelLeft)}px` }),
|
|
221
|
+
}, children: [_jsxs("div", { className: styles.header, children: [_jsxs("span", { className: styles.title, children: [payload.providerName ?? payload.provider, payload.status === 'ok' && payload.planTier !== undefined
|
|
222
|
+
? _jsxs("span", { className: styles.plan, children: [" \u00B7 ", payload.planTier] })
|
|
223
|
+
: null] }), _jsx("span", { className: styles.updated, children: t('quota.updatedAt', { time: formatQuotaClock(payload.fetchedAt) }) })] }), payload.status === 'error'
|
|
224
|
+
? (_jsxs("div", { className: styles.error, children: [_jsx("span", { className: styles.errorText, children: errorText(payload.error, t) }), _jsx("button", { type: "button", className: styles.retry, onClick: retry, children: t('quota.retry') })] }))
|
|
225
|
+
: (_jsx("div", { className: styles.grid, style: { '--cols': String(Math.min(payload.windows.length, 3)) }, children: payload.windows.map((window, index) => _jsx(QuotaColumn, { window: window, t: t }, `${window.tier}:${String(index)}`)) }))] }))] }));
|
|
226
|
+
}
|
|
227
|
+
/** Ring geometry matches ContextMeter: 14px viewBox, r 5.5, 2px stroke.
|
|
228
|
+
* Circumference feeds the remaining-share dasharray, starting at 12
|
|
229
|
+
* o'clock. A 0 share omits the fill stroke — a round cap at 0 would still
|
|
230
|
+
* paint a dot. */
|
|
231
|
+
const RING_R = 5.5;
|
|
232
|
+
const RING_C = 2 * Math.PI * RING_R;
|
|
233
|
+
/** Round caps paint half a stroke width beyond each dash end; their
|
|
234
|
+
* combined reach is what the dash compensation subtracts, so the painted
|
|
235
|
+
* arc (dash + caps) equals the nominal share and the caps cannot seal the
|
|
236
|
+
* 12-o'clock gap. */
|
|
237
|
+
const RING_CAP_REACH = 2;
|
|
238
|
+
/** The trigger glyph: a ContextMeter-family donut whose fill arc is the
|
|
239
|
+
* remaining share of the finest window. Color comes from the button's
|
|
240
|
+
* severity class (`currentColor`); this only draws the arc. */
|
|
241
|
+
function QuotaGlyph({ share }) {
|
|
242
|
+
const clamped = Math.min(1, Math.max(0, share));
|
|
243
|
+
// Cap compensation: round caps extend the painted arc by RING_CAP_REACH,
|
|
244
|
+
// which sealed any gap under ~5.8% of the ring (a 1% gap rendered
|
|
245
|
+
// pixel-identical to a full one). Shortening the dash keeps the gap open
|
|
246
|
+
// at the ring's rims — any nonzero usage stays visible — while the
|
|
247
|
+
// centerline gap stays linear in the remaining share. A full share keeps
|
|
248
|
+
// the entire circumference (compensated caps would only touch at one
|
|
249
|
+
// point, leaving a rim notch that reads as ~98%); an arc no longer than
|
|
250
|
+
// the cap reach skips the compensation (a dash ≤ 0 paints nothing and
|
|
251
|
+
// would drop the nub).
|
|
252
|
+
const nominal = clamped * RING_C;
|
|
253
|
+
const dashLen = clamped >= 1 ? RING_C
|
|
254
|
+
: nominal <= RING_CAP_REACH ? nominal
|
|
255
|
+
: nominal - RING_CAP_REACH;
|
|
256
|
+
return (_jsxs("svg", { viewBox: "0 0 14 14", width: "14", height: "14", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: RING_R, fill: "none", stroke: "currentColor", strokeWidth: "2", opacity: "0.22" }), clamped > 0
|
|
257
|
+
? (_jsx("circle", { cx: "7", cy: "7", r: RING_R, fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: clamped < 1 ? 'round' : 'butt', strokeDasharray: `${dashLen.toFixed(3)} ${RING_C.toFixed(3)}`, transform: "rotate(-90 7 7)" }))
|
|
258
|
+
: null] }));
|
|
259
|
+
}
|
|
260
|
+
/** One progress column: label / value / bar / aux. The value and the bar
|
|
261
|
+
* both carry the REMAINING share (the traffic-light standard reads what is
|
|
262
|
+
* left), colored by severity. */
|
|
263
|
+
function QuotaColumn({ window, t }) {
|
|
264
|
+
const remaining = quotaRemainingPercent(window);
|
|
265
|
+
const severity = quotaSeverityOf(window);
|
|
266
|
+
const label = t(TIER_LABEL_KEYS[window.tier]);
|
|
267
|
+
// Balance windows lead with the amount (the figure the user manages
|
|
268
|
+
// against); ratio windows with the remaining share. The `meta` suffix
|
|
269
|
+
// carries the balance's total.
|
|
270
|
+
let value;
|
|
271
|
+
let meta;
|
|
272
|
+
if (window.tier === 'balance' && window.remainingValue !== undefined) {
|
|
273
|
+
const unit = window.unit ?? 'cny';
|
|
274
|
+
value = formatQuotaMoney(window.remainingValue, unit);
|
|
275
|
+
if (window.maxValue !== undefined)
|
|
276
|
+
meta = `/ ${formatQuotaMoney(window.maxValue, unit)}`;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
value = remaining !== undefined ? formatQuotaPercent(remaining) : '—';
|
|
280
|
+
}
|
|
281
|
+
const aux = window.resetAt !== undefined
|
|
282
|
+
? t('quota.resetIn', { time: formatResetCountdown(window.resetAt, Date.now()) })
|
|
283
|
+
: undefined;
|
|
284
|
+
return (_jsxs("div", { className: styles.col, children: [_jsx("div", { className: styles.label, children: label }), _jsxs("div", { className: styles.value, children: [value, meta !== undefined ? _jsxs("span", { className: styles.meta, children: [" ", meta] }) : null] }), remaining !== undefined && (_jsx("div", { className: styles.bar, children: _jsx("div", { className: `${styles.fill} ${styles[severity]}`, style: { width: `${String(Math.round(remaining))}%` } }) })), aux !== undefined && (_jsxs("div", { className: styles.aux, children: [_jsx("span", { className: `${styles.dot} ${styles[severity]}` }), aux] }))] }));
|
|
285
|
+
}
|
|
286
|
+
/** The panel's width tier for one payload: what the windows PAINT decides —
|
|
287
|
+
* a lone amount (no computable bar, the DeepSeek shape) reads at the
|
|
288
|
+
* minimal plate, one bar (a weekly-only plan, or a balance with a spend
|
|
289
|
+
* total like OpenRouter) the middle one, two or more bars the full plate.
|
|
290
|
+
* Errors and payloads without windows read the full plate (their copy
|
|
291
|
+
* runs long). */
|
|
292
|
+
function panelWidthOf(payload) {
|
|
293
|
+
if (payload === null || payload.status !== 'ok')
|
|
294
|
+
return PANEL_WIDTH_FULL;
|
|
295
|
+
const bars = payload.windows.filter(window => quotaUsedPercent(window) !== undefined).length;
|
|
296
|
+
if (bars === 0)
|
|
297
|
+
return payload.windows.length > 0 ? PANEL_WIDTH_BALANCE : PANEL_WIDTH_FULL;
|
|
298
|
+
return bars === 1 ? PANEL_WIDTH_SINGLE : PANEL_WIDTH_FULL;
|
|
299
|
+
}
|
|
300
|
+
/** Friendly locale copy for one normalized query error. */
|
|
301
|
+
function errorText(error, t) {
|
|
302
|
+
switch (error.kind) {
|
|
303
|
+
case 'auth':
|
|
304
|
+
return t('quota.error.auth', { message: error.message });
|
|
305
|
+
case 'no-credential':
|
|
306
|
+
return t('quota.error.noCredential', { ref: error.message });
|
|
307
|
+
case 'http':
|
|
308
|
+
return t('quota.error.http', { message: error.message });
|
|
309
|
+
case 'network':
|
|
310
|
+
return t('quota.error.network', { message: error.message });
|
|
311
|
+
case 'parse':
|
|
312
|
+
return t('quota.error.parse', { message: error.message });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** Defensive shape check: a misrouted response must not paint the button. */
|
|
316
|
+
function looksLikeQuotaPayload(value) {
|
|
317
|
+
return typeof value === 'object' && value !== null
|
|
318
|
+
&& typeof value.status === 'string'
|
|
319
|
+
&& typeof value.intervalSec === 'number';
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Fetch the quota payload for the active session, naming the chip-selected
|
|
323
|
+
* provider when one is known. Throws on transport failure or a payload that
|
|
324
|
+
* does not look like one, so the hook can keep the previous render
|
|
325
|
+
* (silentAfterFirst) or stay hidden (first failure).
|
|
326
|
+
*/
|
|
327
|
+
async function fetchQuotaPayload(sessionId, provider, signal) {
|
|
328
|
+
const params = new URLSearchParams();
|
|
329
|
+
if (sessionId !== '')
|
|
330
|
+
params.set('session', sessionId);
|
|
331
|
+
if (provider !== undefined && provider !== '')
|
|
332
|
+
params.set('provider', provider);
|
|
333
|
+
const encoded = params.toString();
|
|
334
|
+
const query = encoded === '' ? '' : `?${encoded}`;
|
|
335
|
+
const response = await fetch(QUOTA_PATH + query, {
|
|
336
|
+
headers: { accept: 'application/json' },
|
|
337
|
+
signal,
|
|
338
|
+
});
|
|
339
|
+
if (!response.ok)
|
|
340
|
+
throw new Error(`HTTP ${String(response.status)}`);
|
|
341
|
+
const value = await response.json();
|
|
342
|
+
if (!looksLikeQuotaPayload(value))
|
|
343
|
+
throw new Error('unexpected quota response');
|
|
344
|
+
return value;
|
|
345
|
+
}
|
|
346
|
+
//# sourceMappingURL=QuotaButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuotaButton.js","sourceRoot":"","sources":["../../src/client/QuotaButton.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAA;AAQ/D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EACL,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAC/F,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,GACjG,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAE7C,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAE3B;;;2CAG2C;AAC3C,MAAM,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
* into the `conversation.session.header.utilities` slot — three sub-chips
|
|
4
|
+
* (total tokens / cache hit rate / session cost) beside the Session log
|
|
5
|
+
* button. Data comes from `/token-usage/stats?fields=chip` scoped to the
|
|
6
|
+
* active session and its subagent subtree (the Usage tab's "with
|
|
7
|
+
* subagents" range), so a parent that spawned children shows the same
|
|
8
|
+
* folded numbers the header is meant to summarise. Numbers refresh at
|
|
9
|
+
* REQUEST granularity (same cadence as the Usage tab): `sessionStats`
|
|
10
|
+
* projection churn (plus mirror `updatedAt` when present) is debounced
|
|
11
|
+
* into one fetch, so idle sessions do not poll and a finished request
|
|
12
|
+
* updates the header within ~250 ms. When cost
|
|
13
|
+
* rises on a new request, the cost cell plays `costPop` (scale bounce) and
|
|
14
|
+
* `deltaRise` (+Δ fly); reduced-motion users get silent figure updates
|
|
15
|
+
* instead. A failed FIRST fetch retries itself on a 3 s cadence — the old
|
|
16
|
+
* poll's safety net — so an idle-but-used session still gets its chip.
|
|
17
|
+
*
|
|
18
|
+
* Visibility contract: a session with no recorded requests renders nothing
|
|
19
|
+
* (an empty header strip is worse than no strip; the chip never blanks to
|
|
20
|
+
* "—"). Hit-rate colour is the four-bucket mapping in `format.hitRateDisplay`:
|
|
21
|
+
* ≥95% healthy (green), 80–95% lime, 60–80% amber, below 60% critical (red).
|
|
22
|
+
* Amber/lime fill the warm→cool gap so the four stops read as one progression.
|
|
23
|
+
*
|
|
24
|
+
* @module token-usage/client/SessionStatsChip
|
|
25
|
+
*/
|
|
26
|
+
import type { ReactNode } from 'react';
|
|
27
|
+
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
28
|
+
/** Self-heal cadence after a failed first fetch. With the poll gone, this
|
|
29
|
+
* retry is the only thing that recovers an idle session's chip: refresh
|
|
30
|
+
* failures after the first land keep the prior figures (silent mode) and
|
|
31
|
+
* self-heal on the next request churn, so they never reach the error state. */
|
|
32
|
+
export declare const FETCH_FAILURE_RETRY_MS = 3000;
|
|
33
|
+
/** Props the chip binds for the conversation-session header utilities slot:
|
|
34
|
+
* the framework's session kit (`sessionId` + the global `useSessions`
|
|
35
|
+
* mirror used to walk the subagent tree) plus the locale seat from the
|
|
36
|
+
* registration's `locale:` declaration. */
|
|
37
|
+
export type SessionStatsChipProps = PropsRuntime<'conversation.session.header.utilities'> & PropsLocale<'token-usage'>;
|
|
38
|
+
/**
|
|
39
|
+
* Render the session-header stats chip for the active session. Renders
|
|
40
|
+
* nothing when the session has no recorded usage, when the fetch fails, or
|
|
41
|
+
* while the first fetch is in flight — the spec's "data has no value, the
|
|
42
|
+
* block does not render" rule.
|
|
43
|
+
* @param props - framework session id, the session-list mirror, and the locale seat.
|
|
44
|
+
* @returns the chip strip, or null when the data is empty/unavailable.
|
|
45
|
+
*/
|
|
46
|
+
export declare function SessionStatsChip({ sessionId, useSessions, useProjection, t }: SessionStatsChipProps): ReactNode | null;
|
|
47
|
+
//# sourceMappingURL=SessionStatsChip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionStatsChip.d.ts","sourceRoot":"","sources":["../../src/client/SessionStatsChip.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAyBjF;;;+EAG+E;AAC/E,eAAO,MAAM,sBAAsB,OAAQ,CAAA;AAE3C;;;2CAG2C;AAC3C,MAAM,MAAM,qBAAqB,GAC/B,YAAY,CAAC,uCAAuC,CAAC,GACnD,WAAW,CAAC,aAAa,CAAC,CAAA;AAE9B;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI,CAyGtH"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Session-header stats chip (browser half): a one-line compact strip rendered
|
|
4
|
+
* into the `conversation.session.header.utilities` slot — three sub-chips
|
|
5
|
+
* (total tokens / cache hit rate / session cost) beside the Session log
|
|
6
|
+
* button. Data comes from `/token-usage/stats?fields=chip` scoped to the
|
|
7
|
+
* active session and its subagent subtree (the Usage tab's "with
|
|
8
|
+
* subagents" range), so a parent that spawned children shows the same
|
|
9
|
+
* folded numbers the header is meant to summarise. Numbers refresh at
|
|
10
|
+
* REQUEST granularity (same cadence as the Usage tab): `sessionStats`
|
|
11
|
+
* projection churn (plus mirror `updatedAt` when present) is debounced
|
|
12
|
+
* into one fetch, so idle sessions do not poll and a finished request
|
|
13
|
+
* updates the header within ~250 ms. When cost
|
|
14
|
+
* rises on a new request, the cost cell plays `costPop` (scale bounce) and
|
|
15
|
+
* `deltaRise` (+Δ fly); reduced-motion users get silent figure updates
|
|
16
|
+
* instead. A failed FIRST fetch retries itself on a 3 s cadence — the old
|
|
17
|
+
* poll's safety net — so an idle-but-used session still gets its chip.
|
|
18
|
+
*
|
|
19
|
+
* Visibility contract: a session with no recorded requests renders nothing
|
|
20
|
+
* (an empty header strip is worse than no strip; the chip never blanks to
|
|
21
|
+
* "—"). Hit-rate colour is the four-bucket mapping in `format.hitRateDisplay`:
|
|
22
|
+
* ≥95% healthy (green), 80–95% lime, 60–80% amber, below 60% critical (red).
|
|
23
|
+
* Amber/lime fill the warm→cool gap so the four stops read as one progression.
|
|
24
|
+
*
|
|
25
|
+
* @module token-usage/client/SessionStatsChip
|
|
26
|
+
*/
|
|
27
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
28
|
+
import { encodeStatsQuery, STATS_PATH } from "../wire.js";
|
|
29
|
+
import { useAsyncResource, useDebouncedValue } from "./async-resource.js";
|
|
30
|
+
import { totalTokens } from "./day.js";
|
|
31
|
+
import { currencyViewOf, formatCost, formatTokens, hitRateDisplay } from "./format.js";
|
|
32
|
+
import { HitRateText } from "./HitRateText.js";
|
|
33
|
+
import { buildChildIndex, buildStatsFreshnessKey, subtreeIds } from "./session-stats.js";
|
|
34
|
+
import { useColorSchemeMirror } from "./use-color-scheme.js";
|
|
35
|
+
import { CostDeltaFlyLabel } from "./CostDeltaFlyLabel.js";
|
|
36
|
+
import { useCostInflate } from "./use-cost-inflate.js";
|
|
37
|
+
import styles from './SessionStatsChip.module.css';
|
|
38
|
+
/** Refresh debounce: bursts of session-mirror updates (one request's events)
|
|
39
|
+
* collapse into a single fetch, matching the Usage tab's request-scale
|
|
40
|
+
* cadence instead of a steady poll. */
|
|
41
|
+
const REFRESH_DEBOUNCE_MS = 250;
|
|
42
|
+
/** Self-heal cadence after a failed first fetch. With the poll gone, this
|
|
43
|
+
* retry is the only thing that recovers an idle session's chip: refresh
|
|
44
|
+
* failures after the first land keep the prior figures (silent mode) and
|
|
45
|
+
* self-heal on the next request churn, so they never reach the error state. */
|
|
46
|
+
export const FETCH_FAILURE_RETRY_MS = 3_000;
|
|
47
|
+
/**
|
|
48
|
+
* Render the session-header stats chip for the active session. Renders
|
|
49
|
+
* nothing when the session has no recorded usage, when the fetch fails, or
|
|
50
|
+
* while the first fetch is in flight — the spec's "data has no value, the
|
|
51
|
+
* block does not render" rule.
|
|
52
|
+
* @param props - framework session id, the session-list mirror, and the locale seat.
|
|
53
|
+
* @returns the chip strip, or null when the data is empty/unavailable.
|
|
54
|
+
*/
|
|
55
|
+
export function SessionStatsChip({ sessionId, useSessions, useProjection, t }) {
|
|
56
|
+
const rootRef = useRef(null);
|
|
57
|
+
const costRef = useRef(null);
|
|
58
|
+
useColorSchemeMirror(rootRef);
|
|
59
|
+
const byId = useSessions(state => state.byId);
|
|
60
|
+
const childIndex = useMemo(() => buildChildIndex(byId), [byId]);
|
|
61
|
+
// Same membership as the Usage tab's "with subagents" scope: the active
|
|
62
|
+
// session plus every origin=subagent descendant. An ordinary fork is not
|
|
63
|
+
// a subagent and does not join the fold.
|
|
64
|
+
const scopeIds = useMemo(() => (sessionId === '' ? [] : subtreeIds(byId, sessionId, childIndex)), [byId, sessionId, childIndex]);
|
|
65
|
+
const liveStats = useProjection('sessionStats');
|
|
66
|
+
// Debounce on scope membership + sessionStats churn (and updatedAt when
|
|
67
|
+
// present). sessionStats bumps every finished request; updatedAt alone
|
|
68
|
+
// does not — same fix as the Usage tab's token/cost refresh.
|
|
69
|
+
const freshnessKey = buildStatsFreshnessKey(scopeIds, {
|
|
70
|
+
activeSessionId: sessionId,
|
|
71
|
+
rows: byId,
|
|
72
|
+
liveSessionStats: liveStats,
|
|
73
|
+
});
|
|
74
|
+
const requestKey = `${scopeIds.join('\n')}\n\t${freshnessKey}`;
|
|
75
|
+
const debouncedKey = useDebouncedValue(requestKey, REFRESH_DEBOUNCE_MS);
|
|
76
|
+
const scopeResetKey = scopeIds.join('\n');
|
|
77
|
+
const { flies, flyOverflow, onSummary, } = useCostInflate(scopeResetKey, costRef);
|
|
78
|
+
const [resource, retry] = useAsyncResource(signal => {
|
|
79
|
+
const [idsPart] = debouncedKey.split('\n\t');
|
|
80
|
+
const sessionIds = (idsPart ?? '').split('\n').filter(id => id !== '');
|
|
81
|
+
return fetchSessionSummary(sessionIds, signal);
|
|
82
|
+
}, [debouncedKey], { silentAfterFirst: true, retryToken: 0 });
|
|
83
|
+
// The spec's empty rule: a session with no fetched summary, with zero
|
|
84
|
+
// requests, or still on the first attempt renders nothing.
|
|
85
|
+
const summary = resource.status === 'ready' ? resource.value : null;
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (summary !== null)
|
|
88
|
+
onSummary(summary);
|
|
89
|
+
}, [summary, onSummary]);
|
|
90
|
+
// A failed first fetch renders nothing and, unlike the old poll, no later
|
|
91
|
+
// tick re-triggers it — schedule the resource hook's retry until data
|
|
92
|
+
// lands. Keyed on the resource object: each fresh error reschedules.
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (resource.status !== 'error')
|
|
95
|
+
return;
|
|
96
|
+
const timer = window.setTimeout(retry, FETCH_FAILURE_RETRY_MS);
|
|
97
|
+
return () => { window.clearTimeout(timer); };
|
|
98
|
+
}, [resource, retry]);
|
|
99
|
+
if (summary === null || summary.total.requests === 0)
|
|
100
|
+
return null;
|
|
101
|
+
const view = currencyViewOf(summary);
|
|
102
|
+
const { total } = summary;
|
|
103
|
+
const tokensText = formatTokens(totalTokens(total));
|
|
104
|
+
const hitText = hitRateDisplay(total).text;
|
|
105
|
+
const costText = formatCost(summary.totalCost, view);
|
|
106
|
+
return (_jsxs("div", { ref: rootRef, className: `${styles['strip']}${flyOverflow ? ` ${styles['stripFlyOverflow']}` : ''}`, role: "group", "aria-label": t('view.usage'), children: [_jsx("span", { className: styles['cell'], "aria-label": t('chip.tokens', { value: tokensText }), children: tokensText }), _jsx("span", { className: `${styles['cell']} ${styles['cellHit']}`, "aria-label": t('chip.hitRate', { value: hitText }), children: _jsx(HitRateText, { totals: total }) }), _jsxs("span", { className: `${styles['cell']} ${styles['costCell']}`, "aria-label": t('chip.cost', { value: costText }), children: [_jsx("span", { ref: costRef, className: styles['costInner'], children: costText }), _jsx("span", { className: styles['deltaLayer'], "aria-hidden": "true", children: flies.map(fly => (_jsx(CostDeltaFlyLabel, { text: fly.text, vars: fly.vars }, fly.id))) })] })] }));
|
|
107
|
+
}
|
|
108
|
+
/** Defensive shape check: an older host build or a misrouted response
|
|
109
|
+
* would otherwise paint the header chip with garbage. */
|
|
110
|
+
function looksLikeUsageSummary(value) {
|
|
111
|
+
return typeof value === 'object' && value !== null
|
|
112
|
+
&& typeof value.total === 'object'
|
|
113
|
+
&& value.total !== null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Fetch the summary scoped to one session and its subagent subtree. Throws
|
|
117
|
+
* on transport failure (network, abort, non-2xx response, or a payload
|
|
118
|
+
* that doesn't look like a stats summary) so the hook can keep the
|
|
119
|
+
* previous render in place — a transient miss never blanks the chip. The
|
|
120
|
+
* hook's `silentAfterFirst` flag is what suppresses the resulting error
|
|
121
|
+
* state.
|
|
122
|
+
* @param sessionIds - the active session plus its subagent descendants;
|
|
123
|
+
* an empty list skips the fetch (returning null rather than throwing, so
|
|
124
|
+
* the hook's first-load gate stays at "loading").
|
|
125
|
+
* @param signal - the cancellation signal from the hook.
|
|
126
|
+
*/
|
|
127
|
+
async function fetchSessionSummary(sessionIds, signal) {
|
|
128
|
+
if (sessionIds.length === 0)
|
|
129
|
+
return null;
|
|
130
|
+
const response = await fetch(STATS_PATH + encodeStatsQuery({ sessionIds, fields: 'chip' }), {
|
|
131
|
+
headers: { accept: 'application/json' },
|
|
132
|
+
signal,
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok)
|
|
135
|
+
throw new Error(`HTTP ${String(response.status)}`);
|
|
136
|
+
const value = await response.json();
|
|
137
|
+
if (!looksLikeUsageSummary(value))
|
|
138
|
+
throw new Error('unexpected stats response');
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=SessionStatsChip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionStatsChip.js","sourceRoot":"","sources":["../../src/client/SessionStatsChip.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAWlD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,sBAAs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KACP,CAAC,CAAA;IACF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACpE,MAAM,KAAK,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC5C,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC/E,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared "stat card" primitive: label on top, value underneath. Used by the
|
|
3
|
+
* settings section (four primary cards + four token-bucket cards) and the
|
|
4
|
+
* Usage view tab (six cards: requests / cost / total tokens / hit rate /
|
|
5
|
+
* TTFT / token speed). Centralising the markup + styling means the two
|
|
6
|
+
* surfaces read as one family without each one carrying its own copy of the
|
|
7
|
+
* label-on-top / value-below rule.
|
|
8
|
+
*
|
|
9
|
+
* @module token-usage/client/StatCard
|
|
10
|
+
*/
|
|
11
|
+
import type { ReactNode } from 'react';
|
|
12
|
+
/** One labelled figure inside a card. */
|
|
13
|
+
export interface StatCardProps {
|
|
14
|
+
/** The small secondary line ("token cost", "hit rate", "总 token"). */
|
|
15
|
+
label: string;
|
|
16
|
+
/** The bold tabular-numeric value (`1.5M`, `¥12.34`, `0.5s`). A
|
|
17
|
+
* node is accepted so the hit-rate card can wrap {@link HitRateText}
|
|
18
|
+
* and inherit the four-bucket colour without a second card variant. */
|
|
19
|
+
value: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Render one stat card. The value uses the standard label-primary color.
|
|
23
|
+
* The label clamps to one line and ellipsizes if the column is squeezed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function StatCard({ label, value }: StatCardProps): ReactNode;
|
|
26
|
+
//# sourceMappingURL=StatCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatCard.d.ts","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb;;2EAEuE;IACvE,KAAK,EAAE,SAAS,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,SAAS,CAOnE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styles from './StatCard.module.css';
|
|
3
|
+
/**
|
|
4
|
+
* Render one stat card. The value uses the standard label-primary color.
|
|
5
|
+
* The label clamps to one line and ellipsizes if the column is squeezed.
|
|
6
|
+
*/
|
|
7
|
+
export function StatCard({ label, value }) {
|
|
8
|
+
return (_jsxs("div", { className: styles['card'], children: [_jsx("span", { className: styles['cardLabel'], children: label }), _jsx("span", { className: styles['cardValue'], children: value })] }));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=StatCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatCard.js","sourceRoot":"","sources":["../../src/client/StatCard.tsx"],"names":[],"mappings":";AAYA,OAAO,MAAM,MAAM,uBAAuB,CAAA;AAY1C;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAiB;IACtD,OAAO,CACL,eAAK,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,aAC5B,eAAM,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,YAAG,KAAK,GAAQ,EACpD,eAAM,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,YAAG,KAAK,GAAQ,IAChD,CACP,CAAA;AACH,CAAC"}
|