@laoyuehanni/dsh-token-usage 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/README.zh.md +11 -4
- package/lib/aux-request.d.ts +4 -0
- package/lib/aux-request.d.ts.map +1 -1
- package/lib/aux-request.js +1 -0
- package/lib/aux-request.js.map +1 -1
- package/lib/client/DashboardCards.d.ts +62 -0
- package/lib/client/DashboardCards.d.ts.map +1 -0
- package/lib/client/DashboardCards.js +25 -0
- package/lib/client/DashboardCards.js.map +1 -0
- package/lib/client/OverheadRows.d.ts +30 -0
- package/lib/client/OverheadRows.d.ts.map +1 -0
- package/lib/client/OverheadRows.js +57 -0
- package/lib/client/OverheadRows.js.map +1 -0
- package/lib/client/OverviewBoard.d.ts +54 -0
- package/lib/client/OverviewBoard.d.ts.map +1 -0
- package/lib/client/OverviewBoard.js +35 -0
- package/lib/client/OverviewBoard.js.map +1 -0
- package/lib/client/PanellistMoreEntry.d.ts +29 -0
- package/lib/client/PanellistMoreEntry.d.ts.map +1 -0
- package/lib/client/PanellistMoreEntry.js +12 -0
- package/lib/client/PanellistMoreEntry.js.map +1 -0
- package/lib/client/PanellistPinEntry.d.ts +21 -0
- package/lib/client/PanellistPinEntry.d.ts.map +1 -0
- package/lib/client/PanellistPinEntry.js +24 -0
- package/lib/client/PanellistPinEntry.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +1 -0
- package/lib/client/QuotaButton.d.ts.map +1 -1
- package/lib/client/QuotaButton.js +69 -17
- package/lib/client/QuotaButton.js.map +1 -1
- package/lib/client/RequestPool.d.ts +39 -0
- package/lib/client/RequestPool.d.ts.map +1 -0
- package/lib/client/RequestPool.js +164 -0
- package/lib/client/RequestPool.js.map +1 -0
- package/lib/client/StatCard.d.ts +58 -5
- package/lib/client/StatCard.d.ts.map +1 -1
- package/lib/client/StatCard.js +27 -8
- package/lib/client/StatCard.js.map +1 -1
- package/lib/client/TokenActivity.d.ts +21 -0
- package/lib/client/TokenActivity.d.ts.map +1 -0
- package/lib/client/TokenActivity.js +71 -0
- package/lib/client/TokenActivity.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -1
- package/lib/client/TokenUsageCard.js +1 -1
- package/lib/client/TokenUsageCard.js.map +1 -1
- package/lib/client/TokenUsageSection.d.ts +13 -34
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +81 -93
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/TrendChart.d.ts +2 -1
- package/lib/client/TrendChart.d.ts.map +1 -1
- package/lib/client/TrendChart.js +31 -10
- package/lib/client/TrendChart.js.map +1 -1
- package/lib/client/UsageChart.d.ts +20 -0
- package/lib/client/UsageChart.d.ts.map +1 -0
- package/lib/client/UsageChart.js +26 -0
- package/lib/client/UsageChart.js.map +1 -0
- package/lib/client/UsagePanelPage.d.ts +37 -0
- package/lib/client/UsagePanelPage.d.ts.map +1 -0
- package/lib/client/UsagePanelPage.js +16 -0
- package/lib/client/UsagePanelPage.js.map +1 -0
- package/lib/client/UsageRows.d.ts +102 -0
- package/lib/client/UsageRows.d.ts.map +1 -0
- package/lib/client/UsageRows.js +261 -0
- package/lib/client/UsageRows.js.map +1 -0
- package/lib/client/UsageView.d.ts.map +1 -1
- package/lib/client/UsageView.js +79 -5
- package/lib/client/UsageView.js.map +1 -1
- package/lib/client/activity-grid.d.ts +42 -0
- package/lib/client/activity-grid.d.ts.map +1 -0
- package/lib/client/activity-grid.js +86 -0
- package/lib/client/activity-grid.js.map +1 -0
- package/lib/client/async-resource.d.ts +8 -0
- package/lib/client/async-resource.d.ts.map +1 -1
- package/lib/client/async-resource.js +22 -4
- package/lib/client/async-resource.js.map +1 -1
- package/lib/client/card-form.d.ts +15 -0
- package/lib/client/card-form.d.ts.map +1 -1
- package/lib/client/card-form.js +27 -5
- package/lib/client/card-form.js.map +1 -1
- package/lib/client/cost-split.d.ts +26 -0
- package/lib/client/cost-split.d.ts.map +1 -0
- package/lib/client/cost-split.js +37 -0
- package/lib/client/cost-split.js.map +1 -0
- package/lib/client/format.d.ts +31 -1
- package/lib/client/format.d.ts.map +1 -1
- package/lib/client/format.js +48 -0
- package/lib/client/format.js.map +1 -1
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +102 -0
- package/lib/client/index.js.map +1 -1
- package/lib/client/locales.d.ts +93 -1
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +186 -2
- package/lib/client/locales.js.map +1 -1
- package/lib/client/project-rows.d.ts +4 -0
- package/lib/client/project-rows.d.ts.map +1 -0
- package/lib/client/project-rows.js +3 -0
- package/lib/client/project-rows.js.map +1 -0
- package/lib/client/quota-format.d.ts +6 -4
- package/lib/client/quota-format.d.ts.map +1 -1
- package/lib/client/quota-format.js +7 -5
- package/lib/client/quota-format.js.map +1 -1
- package/lib/client.js +3034 -1490
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +50 -7
- package/lib/index.js.map +1 -1
- package/lib/project-rows.d.ts +22 -0
- package/lib/project-rows.d.ts.map +1 -0
- package/lib/project-rows.js +82 -0
- package/lib/project-rows.js.map +1 -0
- package/lib/quota/adapters/magpie.d.ts +84 -0
- package/lib/quota/adapters/magpie.d.ts.map +1 -0
- package/lib/quota/adapters/magpie.js +290 -0
- package/lib/quota/adapters/magpie.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +15 -4
- package/lib/quota/provider-tracking.d.ts.map +1 -1
- package/lib/quota/provider-tracking.js +18 -7
- package/lib/quota/provider-tracking.js.map +1 -1
- package/lib/quota/quota-route.d.ts +3 -3
- package/lib/quota/quota-route.d.ts.map +1 -1
- package/lib/quota/quota-route.js +3 -3
- package/lib/quota/quota-route.js.map +1 -1
- package/lib/quota/quota-service.d.ts +14 -4
- package/lib/quota/quota-service.d.ts.map +1 -1
- package/lib/quota/quota-service.js +45 -15
- package/lib/quota/quota-service.js.map +1 -1
- package/lib/quota/registry.d.ts.map +1 -1
- package/lib/quota/registry.js +6 -0
- package/lib/quota/registry.js.map +1 -1
- package/lib/quota/types.d.ts +9 -0
- package/lib/quota/types.d.ts.map +1 -1
- package/lib/quota/types.js.map +1 -1
- package/lib/request-details.d.ts +104 -0
- package/lib/request-details.d.ts.map +1 -0
- package/lib/request-details.js +215 -0
- package/lib/request-details.js.map +1 -0
- package/lib/request-observe.d.ts +167 -0
- package/lib/request-observe.d.ts.map +1 -0
- package/lib/request-observe.js +468 -0
- package/lib/request-observe.js.map +1 -0
- package/lib/rollup.d.ts +18 -0
- package/lib/rollup.d.ts.map +1 -1
- package/lib/rollup.js +12 -0
- package/lib/rollup.js.map +1 -1
- package/lib/session-request-details.d.ts +48 -0
- package/lib/session-request-details.d.ts.map +1 -0
- package/lib/session-request-details.js +315 -0
- package/lib/session-request-details.js.map +1 -0
- package/lib/stats-route.d.ts +9 -1
- package/lib/stats-route.d.ts.map +1 -1
- package/lib/stats-route.js +38 -4
- package/lib/stats-route.js.map +1 -1
- package/lib/stats.d.ts +23 -8
- package/lib/stats.d.ts.map +1 -1
- package/lib/stats.js +119 -27
- package/lib/stats.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +1 -0
- package/lib/sync.js.map +1 -1
- package/lib/usage-record.d.ts +61 -0
- package/lib/usage-record.d.ts.map +1 -1
- package/lib/usage-record.js +80 -0
- package/lib/usage-record.js.map +1 -1
- package/lib/wire.d.ts +172 -5
- package/lib/wire.d.ts.map +1 -1
- package/lib/wire.js +8 -0
- package/lib/wire.js.map +1 -1
- package/package.json +30 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quota-service.js","sourceRoot":"","sources":["../../src/quota/quota-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"qu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,KAAK,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,KAAK,CAAC,OAAO,CAAA;IACtB,CAAC;IAED,yBAAyB;IACzB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;IACzC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE/D,mDAAmD;AACnD,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAgBjD,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,GAAG,SAAS,CAEpF"}
|
package/lib/quota/registry.js
CHANGED
|
@@ -14,6 +14,7 @@ import { commandCodeAdapter } from "./adapters/command-code.js";
|
|
|
14
14
|
import { deepseekAccountAdapter } from "./adapters/deepseek-account.js";
|
|
15
15
|
import { deepseekBalanceAdapter } from "./adapters/deepseek-balance.js";
|
|
16
16
|
import { kimiAdapter } from "./adapters/kimi.js";
|
|
17
|
+
import { magpieAdapter } from "./adapters/magpie.js";
|
|
17
18
|
import { minimaxAdapter } from "./adapters/minimax.js";
|
|
18
19
|
import { opencodeGoAdapter } from "./adapters/opencode-go.js";
|
|
19
20
|
import { openrouterAdapter } from "./adapters/openrouter.js";
|
|
@@ -30,6 +31,11 @@ export const QUOTA_ADAPTERS = [
|
|
|
30
31
|
deepseekAccountAdapter,
|
|
31
32
|
deepseekBalanceAdapter,
|
|
32
33
|
openrouterAdapter,
|
|
34
|
+
// Last: the magpie adapter claims only its route key here — a gateway
|
|
35
|
+
// route is a user-declared name at an arbitrary host, so the service
|
|
36
|
+
// resolves those through the MagpieDetector probe when this table (and
|
|
37
|
+
// every host-based match above) finds nothing.
|
|
38
|
+
magpieAdapter,
|
|
33
39
|
];
|
|
34
40
|
/**
|
|
35
41
|
* The adapter handling one provider route, or undefined when none does
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGlD,mDAAmD;AACnD,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,YAAY;IACZ,WAAW;IACX,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,oEAAoE;IACpE,yDAAyD;IACzD,sBAAsB;IACtB,sBAAsB;IACtB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGlD,mDAAmD;AACnD,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,YAAY;IACZ,WAAW;IACX,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,oEAAoE;IACpE,yDAAyD;IACzD,sBAAsB;IACtB,sBAAsB;IACtB,iBAAiB;IACjB,sEAAsE;IACtE,qEAAqE;IACrE,uEAAuE;IACvE,+CAA+C;IAC/C,aAAa;CACd,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAsB;IACxD,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AAC/D,CAAC"}
|
package/lib/quota/types.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export interface QuotaQueryContext {
|
|
|
48
48
|
/** The provider's API key, resolved through the credentials seam.
|
|
49
49
|
* Empty when the adapter does not use an API key. */
|
|
50
50
|
apiKey: string;
|
|
51
|
+
/** The model id the asking session's request used (or the model chip
|
|
52
|
+
* selected), when one is known — adapters that aggregate a whole
|
|
53
|
+
* gateway's upstreams (magpie) filter their cards by it. */
|
|
54
|
+
model?: string;
|
|
51
55
|
/** Deadline signal; the service stamps one per query. */
|
|
52
56
|
signal?: AbortSignal;
|
|
53
57
|
/** Transport to use — global fetch in production, a stub in tests. */
|
|
@@ -88,6 +92,11 @@ export interface QuotaAdapter {
|
|
|
88
92
|
* kimi adapter matches on host or the catalog route `kimi-coding`).
|
|
89
93
|
*/
|
|
90
94
|
matches(input: QuotaMatchInput): boolean;
|
|
95
|
+
/** Per-query deadline override, ms. Absent reads the service default —
|
|
96
|
+
* an adapter whose gateway relays to upstreams with a longer deadline
|
|
97
|
+
* of their own (magpie's 12s fan-out) raises it so the client does not
|
|
98
|
+
* cut the relay off first. */
|
|
99
|
+
queryTimeoutMs?: number;
|
|
91
100
|
/** Query the provider's quota endpoint and normalize the windows.
|
|
92
101
|
* Transport failures throw {@link QuotaQueryError} with the normalized
|
|
93
102
|
* kind; anything else is treated as a parse failure by the service. */
|
package/lib/quota/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7D,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B;;sDAEkD;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB;;0CAEsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7D,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B;;sDAEkD;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB;;0CAEsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AACD;iEACiE;AACjE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,4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AAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACzD;AAED,2DAA2D;AAC3D,qBAAa,eAAgB,SAAQ,KAAK;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc;gBAApB,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;CAI3D"}
|
package/lib/quota/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAmGH,2DAA2D;AAC3D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACnB;IAArB,YAAqB,IAAoB,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QADK,SAAI,GAAJ,IAAI,CAAgB;QAEvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure rules of the conversation usage tab's live request pool (最新请求 /
|
|
3
|
+
* 实时请求): the settled per-request speed gate, the per-request cache
|
|
4
|
+
* assessment (the 50%/80% request-area policy with every exclusion reason),
|
|
5
|
+
* and the route-sequence walk that marks a session's first request and
|
|
6
|
+
* model-switch firsts. No I/O and no runtime imports beyond types, so the
|
|
7
|
+
* stats route, its tests, and any future consumer share one implementation.
|
|
8
|
+
*
|
|
9
|
+
* The assessment NEVER touches the global hit-rate color scale
|
|
10
|
+
* (client/format.ts bandOf) — that one keeps summarizing whole sessions and
|
|
11
|
+
* models; this module judges one request at a time.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/request-details
|
|
14
|
+
*/
|
|
15
|
+
import type { RequestCacheExclusion, RequestDetailCache, RequestDetailState } from './wire.ts';
|
|
16
|
+
/** Inputs of one request's cache assessment: the merged attempt's trusted
|
|
17
|
+
* facts, plus the route-sequence exclusion the caller walked beforehand. */
|
|
18
|
+
export interface CacheAssessInput {
|
|
19
|
+
state: RequestDetailState;
|
|
20
|
+
kind: 'request' | 'compaction' | 'failure';
|
|
21
|
+
/** Provider route key, used only for the documented minimum-input rule. */
|
|
22
|
+
provider?: string;
|
|
23
|
+
/** Uncached input count reported by the provider. */
|
|
24
|
+
inputTokens?: number;
|
|
25
|
+
outputTokens?: number;
|
|
26
|
+
cacheReadTokens?: number;
|
|
27
|
+
/** `cold-start` / `model-switch` when the route sequence walk excluded
|
|
28
|
+
* this request; other exclusions derive from the fields above. */
|
|
29
|
+
sequenceExclusion?: 'cold-start' | 'model-switch';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Assess one request's cache hit for the request-area policy. The rules,
|
|
33
|
+
* in evaluation order:
|
|
34
|
+
*
|
|
35
|
+
* 1. **State**: waiting/streaming rows are `in-flight`; failed / cancelled /
|
|
36
|
+
* interrupted rows are `not-success`; compaction rows are excluded by
|
|
37
|
+
* their kind. None of them ever carry the loss label.
|
|
38
|
+
* 2. **Data**: a missing/invalid input side, or a denominator that is zero /
|
|
39
|
+
* non-finite, renders the rate absent — never 0%.
|
|
40
|
+
* 3. **Reporting**: the cache-read field must have been explicitly reported
|
|
41
|
+
* (a 0 included); a missing field is `cache-unreported`, never 0%.
|
|
42
|
+
* 4. **Sequence**: the session's first request (`cold-start`) and the first
|
|
43
|
+
* request after a model change (`model-switch`) are excluded by the
|
|
44
|
+
* caller's walk — regardless of their rate.
|
|
45
|
+
* 5. **Input qualification**: on the documented DeepSeek routes only, a
|
|
46
|
+
* cacheable input side below one 64-token block is `insufficient-input`.
|
|
47
|
+
* 6. **Policy bands**: all routes with valid reported data use rate < 50% → `loss` (the 「缓存过低」 label),
|
|
48
|
+
* 50% ≤ rate < 80% → `low` (no label), ≥ 80% → `normal`.
|
|
49
|
+
* Numeric colours follow the shared summary-card scale independently.
|
|
50
|
+
* Boundaries use the raw value: exactly 80% is `normal`, exactly 50% is
|
|
51
|
+
* `low` (no label).
|
|
52
|
+
*
|
|
53
|
+
* A `loss` band is a low-hit heuristic hint, never proof of a server-side
|
|
54
|
+
* cache failure — the client copy says so.
|
|
55
|
+
*/
|
|
56
|
+
export declare function assessRequestCache(input: CacheAssessInput): RequestDetailCache;
|
|
57
|
+
/**
|
|
58
|
+
* One entry of a session's request sequence, in start order: the session it
|
|
59
|
+
* belongs to, the model name the route/display folds under (the effective
|
|
60
|
+
* model — response model when the adapter reported one), and the provider
|
|
61
|
+
* route key when the row carries one.
|
|
62
|
+
*/
|
|
63
|
+
export interface RouteSequenceEntry {
|
|
64
|
+
sessionId: string;
|
|
65
|
+
model: string;
|
|
66
|
+
/** Provider route key; absent on legacy rows (recorded before the field
|
|
67
|
+
* existed) and on failure rows whose session never named a route. */
|
|
68
|
+
provider?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Walk a session's request sequence in start order and mark the exclusion
|
|
72
|
+
* each entry's cache label would carry: the session's very first request is
|
|
73
|
+
* a `cold-start`, and any entry whose immediate predecessor in the same
|
|
74
|
+
* session named a different route is a `model-switch`. The route identity is
|
|
75
|
+
* provider + model when BOTH sides carry a provider (the cache lineage is
|
|
76
|
+
* per-route: switching `deepseek-official` → `deepseek-account` at the same
|
|
77
|
+
* model name starts a new cache context); when either side lacks the
|
|
78
|
+
* provider key (legacy rows, unattributed failures) the walk falls back to
|
|
79
|
+
* the model-only comparison those rows have always had — an absent key never
|
|
80
|
+
* widens the exclusion. Switching BACK to an earlier route is still a switch
|
|
81
|
+
* first — conservative. Entries outside this vocabulary (unknown future
|
|
82
|
+
* reasons) yield undefined. The walk always covers the FULL sequence the
|
|
83
|
+
* caller filtered to scope — never just the display window — so a first
|
|
84
|
+
* request that fell out of the 20-item pool is still correctly marked, and
|
|
85
|
+
* the marks do not move as the window slides.
|
|
86
|
+
*
|
|
87
|
+
* Predecessors are by adjacent request regardless of kind: a compaction
|
|
88
|
+
* summarize call is a real provider request of the same session and takes
|
|
89
|
+
* part in the cache lineage.
|
|
90
|
+
*/
|
|
91
|
+
export declare function routeExclusionsOf(entries: readonly RouteSequenceEntry[]): ReadonlyMap<object, 'cold-start' | 'model-switch'>;
|
|
92
|
+
/**
|
|
93
|
+
* The settled single-request decode speed: output tokens over the generation
|
|
94
|
+
* span (latency − first token), in tokens/second. The gate mirrors the
|
|
95
|
+
* global performance accumulators: the generation span must be a real
|
|
96
|
+
* streaming sample (≥ {@link PERF_STREAM_MIN_GEN_MS}) and the output must be
|
|
97
|
+
* positive. A whole-body (non-streaming) response has no first-token figure
|
|
98
|
+
* and stays undefined — its tiny arrival interval would fabricate enormous
|
|
99
|
+
* tok/s. Never returns Infinity/NaN.
|
|
100
|
+
*/
|
|
101
|
+
export declare function settledSpeedOf(outputTokens: number | undefined, latencyMs: number | undefined, firstTokenLatencyMs: number | undefined): number | undefined;
|
|
102
|
+
/** All exclusion reasons, for locale-key coverage tests. */
|
|
103
|
+
export declare const CACHE_EXCLUSION_REASONS: readonly RequestCacheExclusion[];
|
|
104
|
+
//# sourceMappingURL=request-details.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-details.d.ts","sourceRoot":"","sources":["../src/request-details.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAc9F;4EAC4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,kBAAkB,CAAA;IACzB,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;sEACkE;IAClE,iBAAiB,CAAC,EAAE,YAAY,GAAG,cAAc,CAAA;CAClD;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,kBAAkB,CAqE9E;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb;yEACqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,kBAAkB,EAAE,GACrC,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CAAC,CA0BpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,mBAAmB,EAAE,MAAM,GAAG,SAAS,GACtC,MAAM,GAAG,SAAS,CAQpB;AAED,4DAA4D;AAC5D,eAAO,MAAM,uBAAuB,EAAE,SAAS,qBAAqB,EASnE,CAAA"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure rules of the conversation usage tab's live request pool (最新请求 /
|
|
3
|
+
* 实时请求): the settled per-request speed gate, the per-request cache
|
|
4
|
+
* assessment (the 50%/80% request-area policy with every exclusion reason),
|
|
5
|
+
* and the route-sequence walk that marks a session's first request and
|
|
6
|
+
* model-switch firsts. No I/O and no runtime imports beyond types, so the
|
|
7
|
+
* stats route, its tests, and any future consumer share one implementation.
|
|
8
|
+
*
|
|
9
|
+
* The assessment NEVER touches the global hit-rate color scale
|
|
10
|
+
* (client/format.ts bandOf) — that one keeps summarizing whole sessions and
|
|
11
|
+
* models; this module judges one request at a time.
|
|
12
|
+
*
|
|
13
|
+
* @module token-usage/request-details
|
|
14
|
+
*/
|
|
15
|
+
import { PERF_STREAM_MIN_GEN_MS } from "./stats.js";
|
|
16
|
+
/**
|
|
17
|
+
* DeepSeek context caching stores the prompt in 64-token blocks (provider
|
|
18
|
+
* documentation). A request on these routes whose whole
|
|
19
|
+
* cacheable input side is below one block cannot hit the cache, so its 0%
|
|
20
|
+
* is explained by the input itself — an exclusion with evidence, not a
|
|
21
|
+
* blanket minimum-token rule for every provider.
|
|
22
|
+
*/
|
|
23
|
+
const DEEPSEEK_CACHE_BLOCK_TOKENS = 64;
|
|
24
|
+
/** Only these routes have a documented minimum; this is not an alert allowlist. */
|
|
25
|
+
const DEEPSEEK_BLOCK_PROVIDERS = new Set(['deepseek-official', 'deepseek-account']);
|
|
26
|
+
/**
|
|
27
|
+
* Whether the token figures are individually trustworthy counts: finite and
|
|
28
|
+
* non-negative. (There is no separate total-input figure to contradict —
|
|
29
|
+
* uncached input + cache reads IS the served input side, so no cross-field
|
|
30
|
+
* contradiction dimension exists beyond per-field validity.)
|
|
31
|
+
*/
|
|
32
|
+
function countsAreValid(input) {
|
|
33
|
+
const { inputTokens, outputTokens, cacheReadTokens } = input;
|
|
34
|
+
if (inputTokens === undefined || !Number.isFinite(inputTokens) || inputTokens < 0)
|
|
35
|
+
return false;
|
|
36
|
+
if (outputTokens !== undefined && (!Number.isFinite(outputTokens) || outputTokens < 0))
|
|
37
|
+
return false;
|
|
38
|
+
if (cacheReadTokens !== undefined && (!Number.isFinite(cacheReadTokens) || cacheReadTokens < 0))
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Assess one request's cache hit for the request-area policy. The rules,
|
|
44
|
+
* in evaluation order:
|
|
45
|
+
*
|
|
46
|
+
* 1. **State**: waiting/streaming rows are `in-flight`; failed / cancelled /
|
|
47
|
+
* interrupted rows are `not-success`; compaction rows are excluded by
|
|
48
|
+
* their kind. None of them ever carry the loss label.
|
|
49
|
+
* 2. **Data**: a missing/invalid input side, or a denominator that is zero /
|
|
50
|
+
* non-finite, renders the rate absent — never 0%.
|
|
51
|
+
* 3. **Reporting**: the cache-read field must have been explicitly reported
|
|
52
|
+
* (a 0 included); a missing field is `cache-unreported`, never 0%.
|
|
53
|
+
* 4. **Sequence**: the session's first request (`cold-start`) and the first
|
|
54
|
+
* request after a model change (`model-switch`) are excluded by the
|
|
55
|
+
* caller's walk — regardless of their rate.
|
|
56
|
+
* 5. **Input qualification**: on the documented DeepSeek routes only, a
|
|
57
|
+
* cacheable input side below one 64-token block is `insufficient-input`.
|
|
58
|
+
* 6. **Policy bands**: all routes with valid reported data use rate < 50% → `loss` (the 「缓存过低」 label),
|
|
59
|
+
* 50% ≤ rate < 80% → `low` (no label), ≥ 80% → `normal`.
|
|
60
|
+
* Numeric colours follow the shared summary-card scale independently.
|
|
61
|
+
* Boundaries use the raw value: exactly 80% is `normal`, exactly 50% is
|
|
62
|
+
* `low` (no label).
|
|
63
|
+
*
|
|
64
|
+
* A `loss` band is a low-hit heuristic hint, never proof of a server-side
|
|
65
|
+
* cache failure — the client copy says so.
|
|
66
|
+
*/
|
|
67
|
+
export function assessRequestCache(input) {
|
|
68
|
+
const { state, kind } = input;
|
|
69
|
+
const assessment = { eligibility: 'unknown', band: 'unknown' };
|
|
70
|
+
// 1. State exclusions (before any rate is computed — an in-flight row has
|
|
71
|
+
// no trustworthy usage yet anyway).
|
|
72
|
+
if (state === 'waiting' || state === 'streaming') {
|
|
73
|
+
assessment.band = 'excluded';
|
|
74
|
+
assessment.reason = 'in-flight';
|
|
75
|
+
return assessment;
|
|
76
|
+
}
|
|
77
|
+
if (state !== 'completed') {
|
|
78
|
+
assessment.band = 'excluded';
|
|
79
|
+
assessment.reason = 'not-success';
|
|
80
|
+
return assessment;
|
|
81
|
+
}
|
|
82
|
+
if (kind === 'compaction') {
|
|
83
|
+
assessment.band = 'excluded';
|
|
84
|
+
assessment.reason = 'compaction';
|
|
85
|
+
return assessment;
|
|
86
|
+
}
|
|
87
|
+
// 2. Data validity.
|
|
88
|
+
if (!countsAreValid(input)) {
|
|
89
|
+
assessment.band = 'unknown';
|
|
90
|
+
assessment.reason = 'invalid-data';
|
|
91
|
+
return assessment;
|
|
92
|
+
}
|
|
93
|
+
const served = input.inputTokens + (input.cacheReadTokens ?? 0);
|
|
94
|
+
if (!Number.isFinite(served) || served <= 0) {
|
|
95
|
+
assessment.band = 'unknown';
|
|
96
|
+
assessment.reason = 'invalid-data';
|
|
97
|
+
return assessment;
|
|
98
|
+
}
|
|
99
|
+
// 3. Explicit reporting. The field's PRESENCE is the evidence: the
|
|
100
|
+
// DeepSeek wire copies each field verbatim, so a reported 0 survives as
|
|
101
|
+
// cacheReadTokens: 0 (an assessable 0%), and a missing field means the
|
|
102
|
+
// provider did not report — never "0% hit". On the pi-ai routes a
|
|
103
|
+
// reported 0 was folded away at the adapter, which lands here the same
|
|
104
|
+
// way: unknown, never 0%.
|
|
105
|
+
if (input.cacheReadTokens === undefined) {
|
|
106
|
+
assessment.band = 'unknown';
|
|
107
|
+
assessment.reason = 'cache-unreported';
|
|
108
|
+
return assessment;
|
|
109
|
+
}
|
|
110
|
+
const rate = (input.cacheReadTokens ?? 0) / served;
|
|
111
|
+
assessment.rate = rate;
|
|
112
|
+
assessment.eligibility = 'eligible';
|
|
113
|
+
// 4. Route-sequence exclusions (the caller's walk).
|
|
114
|
+
if (input.sequenceExclusion !== undefined) {
|
|
115
|
+
assessment.band = 'excluded';
|
|
116
|
+
assessment.reason = input.sequenceExclusion;
|
|
117
|
+
return assessment;
|
|
118
|
+
}
|
|
119
|
+
// 5. Input qualification: below one cache block the 0% is explained by
|
|
120
|
+
// the input itself, not by a cache failure.
|
|
121
|
+
if (input.provider !== undefined && DEEPSEEK_BLOCK_PROVIDERS.has(input.provider)
|
|
122
|
+
&& rate === 0 && served < DEEPSEEK_CACHE_BLOCK_TOKENS) {
|
|
123
|
+
assessment.band = 'excluded';
|
|
124
|
+
assessment.reason = 'insufficient-input';
|
|
125
|
+
return assessment;
|
|
126
|
+
}
|
|
127
|
+
// 6. Policy bands on the raw value, regardless of provider identity.
|
|
128
|
+
assessment.band = rate < 0.5 ? 'loss' : rate < 0.8 ? 'low' : 'normal';
|
|
129
|
+
return assessment;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Walk a session's request sequence in start order and mark the exclusion
|
|
133
|
+
* each entry's cache label would carry: the session's very first request is
|
|
134
|
+
* a `cold-start`, and any entry whose immediate predecessor in the same
|
|
135
|
+
* session named a different route is a `model-switch`. The route identity is
|
|
136
|
+
* provider + model when BOTH sides carry a provider (the cache lineage is
|
|
137
|
+
* per-route: switching `deepseek-official` → `deepseek-account` at the same
|
|
138
|
+
* model name starts a new cache context); when either side lacks the
|
|
139
|
+
* provider key (legacy rows, unattributed failures) the walk falls back to
|
|
140
|
+
* the model-only comparison those rows have always had — an absent key never
|
|
141
|
+
* widens the exclusion. Switching BACK to an earlier route is still a switch
|
|
142
|
+
* first — conservative. Entries outside this vocabulary (unknown future
|
|
143
|
+
* reasons) yield undefined. The walk always covers the FULL sequence the
|
|
144
|
+
* caller filtered to scope — never just the display window — so a first
|
|
145
|
+
* request that fell out of the 20-item pool is still correctly marked, and
|
|
146
|
+
* the marks do not move as the window slides.
|
|
147
|
+
*
|
|
148
|
+
* Predecessors are by adjacent request regardless of kind: a compaction
|
|
149
|
+
* summarize call is a real provider request of the same session and takes
|
|
150
|
+
* part in the cache lineage.
|
|
151
|
+
*/
|
|
152
|
+
export function routeExclusionsOf(entries) {
|
|
153
|
+
const marks = new Map();
|
|
154
|
+
const lastRoute = new Map();
|
|
155
|
+
for (const entry of entries) {
|
|
156
|
+
// An unattributed entry (model '' — a failure row whose session never
|
|
157
|
+
// named a route) takes no mark and leaves no predecessor: it would
|
|
158
|
+
// otherwise forge a model switch around itself.
|
|
159
|
+
if (entry.model === '')
|
|
160
|
+
continue;
|
|
161
|
+
const previous = lastRoute.get(entry.sessionId);
|
|
162
|
+
if (previous === undefined) {
|
|
163
|
+
marks.set(entry, 'cold-start');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Route identity: provider + model when both sides carry a provider;
|
|
167
|
+
// model-only when either side predates the field (conservative — the
|
|
168
|
+
// legacy comparison never gains exclusions it cannot evidence).
|
|
169
|
+
const switched = previous.provider !== undefined && entry.provider !== undefined
|
|
170
|
+
? previous.provider !== entry.provider || previous.model !== entry.model
|
|
171
|
+
: previous.model !== entry.model;
|
|
172
|
+
if (switched)
|
|
173
|
+
marks.set(entry, 'model-switch');
|
|
174
|
+
}
|
|
175
|
+
lastRoute.set(entry.sessionId, {
|
|
176
|
+
model: entry.model,
|
|
177
|
+
...(entry.provider !== undefined ? { provider: entry.provider } : {}),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return marks;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The settled single-request decode speed: output tokens over the generation
|
|
184
|
+
* span (latency − first token), in tokens/second. The gate mirrors the
|
|
185
|
+
* global performance accumulators: the generation span must be a real
|
|
186
|
+
* streaming sample (≥ {@link PERF_STREAM_MIN_GEN_MS}) and the output must be
|
|
187
|
+
* positive. A whole-body (non-streaming) response has no first-token figure
|
|
188
|
+
* and stays undefined — its tiny arrival interval would fabricate enormous
|
|
189
|
+
* tok/s. Never returns Infinity/NaN.
|
|
190
|
+
*/
|
|
191
|
+
export function settledSpeedOf(outputTokens, latencyMs, firstTokenLatencyMs) {
|
|
192
|
+
if (outputTokens === undefined || latencyMs === undefined || firstTokenLatencyMs === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
if (!Number.isFinite(outputTokens) || !Number.isFinite(latencyMs) || !Number.isFinite(firstTokenLatencyMs))
|
|
195
|
+
return undefined;
|
|
196
|
+
if (outputTokens <= 0 || latencyMs < 0 || firstTokenLatencyMs < 0)
|
|
197
|
+
return undefined;
|
|
198
|
+
const genMs = latencyMs - firstTokenLatencyMs;
|
|
199
|
+
if (genMs < PERF_STREAM_MIN_GEN_MS)
|
|
200
|
+
return undefined;
|
|
201
|
+
const speed = outputTokens / (genMs / 1_000);
|
|
202
|
+
return Number.isFinite(speed) ? speed : undefined;
|
|
203
|
+
}
|
|
204
|
+
/** All exclusion reasons, for locale-key coverage tests. */
|
|
205
|
+
export const CACHE_EXCLUSION_REASONS = [
|
|
206
|
+
'cold-start',
|
|
207
|
+
'model-switch',
|
|
208
|
+
'in-flight',
|
|
209
|
+
'not-success',
|
|
210
|
+
'compaction',
|
|
211
|
+
'cache-unreported',
|
|
212
|
+
'insufficient-input',
|
|
213
|
+
'invalid-data',
|
|
214
|
+
];
|
|
215
|
+
//# sourceMappingURL=request-details.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-details.js","sourceRoot":"","sources":["../src/request-details.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAGnD;;;;;;GAMG;AACH,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAEtC,mFAAmF;AACnF,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAA;AAkBxG;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAuB;IAC7C,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,KAAK,CAAA;IAC5D,IAAI,WAAW,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/F,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IACpG,IAAI,eAAe,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CA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AAC,CAAC,EAAE,CAAC;SACtE,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,YAAgC,EAChC,SAA6B,EAC7B,mBAAuC;IAEvC,IAAI,YAAY,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,IAAI,mBAAmB,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAChH,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAAE,OAAO,SAAS,CAAA;IAC5H,IAAI,YAAY,IAAI,CAAC,IAAI,SAAS,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IACnF,MAAM,KAAK,GAAG,SAAS,GAAG,mBAAmB,CAAA;IAC7C,IAAI,KAAK,GAAG,sBAAsB;QAAE,OAAO,SAAS,CAAA;IACpD,MAAM,KAAK,GAAG,YAAY,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,uBAAuB,GAAqC;IACvE,YAAY;IACZ,cAAc;IACd,WAAW;IACX,aAAa;IACb,YAAY;IACZ,kBAAkB;IAClB,oBAAoB;IACpB,cAAc;CACf,CAAA"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live request observation (node half): a passive, pass-through watcher on
|
|
3
|
+
* the `llm/stream` waterfall that tracks one entry per real provider attempt
|
|
4
|
+
* (per `sessionId` + turn/step + attempt ordinal) so the conversation usage
|
|
5
|
+
* tab can show 请求池 rows WHILE a request waits, streams, fails, or is
|
|
6
|
+
* cancelled — not only after its usage record lands.
|
|
7
|
+
*
|
|
8
|
+
* Registration is INDEPENDENT of the auxiliary-recording switch: the
|
|
9
|
+
* listener is installed unconditionally whenever the llm service exists, so
|
|
10
|
+
* `recordAux: false` cannot silently disable the pool. The listener is
|
|
11
|
+
* strictly passive — every chunk is yielded unchanged, nothing is buffered,
|
|
12
|
+
* awaited on disk, or pre-read; cancel, backpressure, and listener-chain
|
|
13
|
+
* semantics are the caller's own (same shape as the auxiliary recorder).
|
|
14
|
+
* Prompt text, reasoning, tool arguments, and credentials never leave this
|
|
15
|
+
* module: only counts, timings, model ids, and failure codes cross to the
|
|
16
|
+
* stats route.
|
|
17
|
+
*
|
|
18
|
+
* Lifecycle facts this module relies on (verified against the host source):
|
|
19
|
+
* - Every provider attempt dispatches its own `llm/stream` waterfall call —
|
|
20
|
+
* dsh-llm-retry retries on the agent loop's `agent/request-error` seam,
|
|
21
|
+
* and the loop re-dispatches through `llm.stream()` within the SAME
|
|
22
|
+
* turn/step, so the Nth waterfall call of one (session, turn, step) is
|
|
23
|
+
* the Nth attempt.
|
|
24
|
+
* - The streaming protocol carries `usage` exactly once, just before the
|
|
25
|
+
* terminal `finish` — there is NO in-generation token progress route, so
|
|
26
|
+
* live rows show lifecycle only (capability `lifecycle`), never a
|
|
27
|
+
* fabricated tok/s.
|
|
28
|
+
* - A mid-stream abort settles as `assistant/message` (interrupted, partial
|
|
29
|
+
* usage) or `assistant/attempt` (nothing delivered, which this plugin does
|
|
30
|
+
* not record); a retried failure settles as `assistant/attempt` then
|
|
31
|
+
* `llm/retry` / `llm/retry-started`. Every settlement the plugin records a
|
|
32
|
+
* row for is LINKED here by its durable id: `assistant/message` names the
|
|
33
|
+
* turn/step's completing attempt, `llm/retry` (appended before the
|
|
34
|
+
* backoff, so the cell's latest dispatch is the attempt that just failed)
|
|
35
|
+
* and a turn-ending error map to `failure:<session>:<seq>`, and a
|
|
36
|
+
* `compaction/summary` maps to its summarize call via the compaction lock
|
|
37
|
+
* window (`compaction/start` holds the per-session lock through `end`, so
|
|
38
|
+
* the window's compaction attempt is the summarized one). `turn/end`
|
|
39
|
+
* resolves whatever the stream never did.
|
|
40
|
+
* - Compaction summarize calls carry `purpose: 'compaction'` and the owning
|
|
41
|
+
* session id but no step; auxiliary bypass calls (session title, review
|
|
42
|
+
* authorization, translation) carry no session id — they stay out of the
|
|
43
|
+
* pool, exactly like the stats route refuses to attribute them.
|
|
44
|
+
*
|
|
45
|
+
* @module token-usage/request-observe
|
|
46
|
+
*/
|
|
47
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
48
|
+
import { type UsageFields, type UsageRecord } from './usage-record.ts';
|
|
49
|
+
import type { RequestDetailState } from './wire.ts';
|
|
50
|
+
/** One live attempt observed at the waterfall: the runtime-state shape the
|
|
51
|
+
* stats route merges against the persisted records. */
|
|
52
|
+
export interface LiveAttempt {
|
|
53
|
+
/** Stable attempt identity: `<epoch>:<sessionId>:t<turn>:s<step>:a<n>`
|
|
54
|
+
* (turn/step `-1` when the attempt ran outside a step, e.g. compaction).
|
|
55
|
+
* Unique per process; a restarted process gets a new epoch. */
|
|
56
|
+
readonly id: string;
|
|
57
|
+
sessionId: string;
|
|
58
|
+
kind: 'request' | 'compaction' | 'failure';
|
|
59
|
+
state: RequestDetailState;
|
|
60
|
+
/** True for attempts that entered the waiting/streaming lifecycle. Used
|
|
61
|
+
* to distinguish a just-finished live request from a synthetic settled
|
|
62
|
+
* snapshot supplied by a caller. */
|
|
63
|
+
wasActive?: boolean;
|
|
64
|
+
provider: string;
|
|
65
|
+
requestedModel: string;
|
|
66
|
+
/** Absolute epoch ms of the waterfall dispatch (the attempt's start). */
|
|
67
|
+
startedAt: number;
|
|
68
|
+
/** Absolute epoch ms when the attempt settled (finish/abort/turn-end). */
|
|
69
|
+
settledAt?: number;
|
|
70
|
+
/** Absolute epoch ms of the first non-empty token delta. */
|
|
71
|
+
firstTokenAt?: number;
|
|
72
|
+
/** The attempt's provider usage (the single pre-finish chunk); a reported
|
|
73
|
+
* 0 cache-read bucket survives the copy as 0 — presence IS the evidence. */
|
|
74
|
+
usage?: UsageFields;
|
|
75
|
+
failureCode?: string;
|
|
76
|
+
/** The durable request id once a settlement named it — `assistant/message`
|
|
77
|
+
* for the turn/step's completing attempt, `failure:<session>:<seq>` for a
|
|
78
|
+
* retried-failed or turn-ending attempt, `compaction:<session>:<seq>` for
|
|
79
|
+
* a summarize call. The merge key against the persisted rows. */
|
|
80
|
+
durableRequestId?: string;
|
|
81
|
+
/** The compaction this summarize call belongs to (`compaction/start`'s
|
|
82
|
+
* id, observed when the call dispatched inside the compaction's lock
|
|
83
|
+
* window); the summary event's linking key. */
|
|
84
|
+
compactionId?: string;
|
|
85
|
+
/** The loop turn/step the attempt dispatched inside (`-1` when outside a
|
|
86
|
+
* step, e.g. compaction); the settlement-linking key. */
|
|
87
|
+
turn: number;
|
|
88
|
+
step: number;
|
|
89
|
+
}
|
|
90
|
+
/** Everything the stats route needs from the observer for one scope. */
|
|
91
|
+
export interface LiveSnapshot {
|
|
92
|
+
/** Live attempts belonging to the scope (settled ones included — the
|
|
93
|
+
* route merges/dedupes them against the persisted records). */
|
|
94
|
+
attempts: readonly LiveAttempt[];
|
|
95
|
+
/** Attempts still waiting/streaming in the scope. */
|
|
96
|
+
activeCount: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Passive live-request observer. One instance per plugin apply; the stats
|
|
100
|
+
* route reads `snapshot()` per request, and dispose clears everything.
|
|
101
|
+
*/
|
|
102
|
+
export declare class RequestObserver {
|
|
103
|
+
private readonly epoch;
|
|
104
|
+
private readonly attempts;
|
|
105
|
+
/** The loop's open step per session (`step/start` … `assistant/message` /
|
|
106
|
+
* `step/end`). Attempt ordinals read it at dispatch time. */
|
|
107
|
+
private readonly activeSteps;
|
|
108
|
+
/** Next attempt ordinal per (session, turn, step) — and per session for
|
|
109
|
+
* out-of-step callers (compaction). */
|
|
110
|
+
private readonly counters;
|
|
111
|
+
/** The compaction currently holding a session's lock (`compaction/start`
|
|
112
|
+
* … `compaction/end`): the lock window a summarize waterfall call
|
|
113
|
+
* dispatches inside, keyed by its `compactionId`. */
|
|
114
|
+
private readonly openCompactions;
|
|
115
|
+
private disposed;
|
|
116
|
+
private disposers;
|
|
117
|
+
constructor(epoch: number);
|
|
118
|
+
/**
|
|
119
|
+
* Register the waterfall watcher. Returns the detach function (the caller
|
|
120
|
+
* wraps it in its effect); the listener is inert after {@link dispose}.
|
|
121
|
+
* A host without the llm service never calls this, and the snapshot
|
|
122
|
+
* stays empty (capability `settled-only`).
|
|
123
|
+
*/
|
|
124
|
+
attachLlm(llmCtx: Context): () => void;
|
|
125
|
+
/** Track the loop's step boundaries and resolve settlements the stream
|
|
126
|
+
* itself could not (message ids, turn-end failure codes). */
|
|
127
|
+
attachSessions(ctx: Context): void;
|
|
128
|
+
/** Clear every tracked attempt and detach nothing (listeners self-inert). */
|
|
129
|
+
dispose(): void;
|
|
130
|
+
/** The scope's live attempts plus its in-flight count. */
|
|
131
|
+
snapshot(sessionIds: readonly string[]): LiveSnapshot;
|
|
132
|
+
/** Persist the exact linked attempt clock without changing the ledger's
|
|
133
|
+
* step timings or billing timestamp. This survives cleanup/restarts. */
|
|
134
|
+
decorateRecord(record: UsageRecord): UsageRecord;
|
|
135
|
+
/** Housekeeping the route never sees: drop settled rows past the TTL or
|
|
136
|
+
* beyond the per-session bound, so idle sessions shrink back to zero. */
|
|
137
|
+
cleanup(now?: number): void;
|
|
138
|
+
private observeEvent;
|
|
139
|
+
/** The counter key of one (session, turn, step) cell. */
|
|
140
|
+
private keyOf;
|
|
141
|
+
/** The most recent attempt of one (session, turn, step) cell — its last
|
|
142
|
+
* dispatch, whether settled or not. */
|
|
143
|
+
private lastAttemptOf;
|
|
144
|
+
/** The compaction attempt a `compaction/summary` names: the lock window's
|
|
145
|
+
* own attempt when the waterfall dispatch was observed inside it (matched
|
|
146
|
+
* by `compactionId`), else the session's latest unlinked compaction
|
|
147
|
+
* attempt — the lock admits at most one at a time, so "latest" is the
|
|
148
|
+
* structural answer, not a timing guess. */
|
|
149
|
+
private compactionAttemptOf;
|
|
150
|
+
/**
|
|
151
|
+
* The waterfall listener body: stamp a live attempt, pass the stream
|
|
152
|
+
* through untouched, and fold the observed chunks back into the attempt's
|
|
153
|
+
* lifecycle. The wrapper is a plain async generator object, so the
|
|
154
|
+
* waterfall chain keeps its synchronous shape.
|
|
155
|
+
*/
|
|
156
|
+
private observe;
|
|
157
|
+
/** Defensive usage copy: keep only trustworthy, non-negative finite
|
|
158
|
+
* counts; a bad bucket drops the whole usage (the record path does the
|
|
159
|
+
* same via projectUsage). */
|
|
160
|
+
private copyUsage;
|
|
161
|
+
private bumpCounter;
|
|
162
|
+
/** Drop counters of other sessions' finished cells (rarely needed; a
|
|
163
|
+
* purely defensive bound on a map that only grows per step). */
|
|
164
|
+
private pruneCounters;
|
|
165
|
+
private track;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=request-observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-observe.d.ts","sourceRoot":"","sources":["../src/request-observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAQlD,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEnD;uDACuD;AACvD,MAAM,WAAW,WAAW;IAC1B;;mEAE+D;IAC/D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAAA;IAC1C,KAAK,EAAE,kBAAkB,CAAA;IACzB;;wCA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