dsh-token-usage-ledger 0.0.0-stage → 0.0.37
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/CHANGELOG.md +1081 -0
- package/LICENSE +21 -0
- package/README.md +247 -2
- package/cordis.patch.yml +30 -0
- package/docs/token-usage-image01.png +0 -0
- package/docs/token-usage-image02.png +0 -0
- package/lib/client.js +4469 -0
- package/lib/host/aggregate.d.ts +132 -0
- package/lib/host/aggregate.js +840 -0
- package/lib/host/api.d.ts +118 -0
- package/lib/host/api.js +346 -0
- package/lib/host/backfill.d.ts +54 -0
- package/lib/host/backfill.js +265 -0
- package/lib/host/collector.d.ts +139 -0
- package/lib/host/collector.js +441 -0
- package/lib/host/ledger-io.d.ts +125 -0
- package/lib/host/ledger-io.js +211 -0
- package/lib/host/operation-error.d.ts +22 -0
- package/lib/host/operation-error.js +28 -0
- package/lib/host/paths.d.ts +35 -0
- package/lib/host/paths.js +63 -0
- package/lib/host/pricing-module.d.ts +112 -0
- package/lib/host/pricing-module.js +63 -0
- package/lib/host/pricing-modules/deepseek-2026-09-10.d.ts +31 -0
- package/lib/host/pricing-modules/deepseek-2026-09-10.js +67 -0
- package/lib/host/pricing-modules/index.d.ts +27 -0
- package/lib/host/pricing-modules/index.js +30 -0
- package/lib/host/pricing.d.ts +192 -0
- package/lib/host/pricing.js +287 -0
- package/lib/host/records.d.ts +47 -0
- package/lib/host/records.js +116 -0
- package/lib/host/runtime-marker.d.ts +67 -0
- package/lib/host/runtime-marker.js +71 -0
- package/lib/host/schema.d.ts +77 -0
- package/lib/host/schema.js +158 -0
- package/lib/host/store.d.ts +171 -0
- package/lib/host/store.js +337 -0
- package/lib/host/workspace-titles.d.ts +38 -0
- package/lib/host/workspace-titles.js +136 -0
- package/lib/host/zstd.d.ts +41 -0
- package/lib/host/zstd.js +134 -0
- package/lib/index.d.ts +82 -0
- package/lib/index.js +512 -0
- package/lib/shared/format.d.ts +415 -0
- package/lib/shared/format.js +714 -0
- package/lib/shared/protocol.d.ts +646 -0
- package/lib/shared/protocol.js +129 -0
- package/package.json +87 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host↔Client wire protocol and the pure vocabulary shared by both halves.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this module is dependency-free plain data + arithmetic so that
|
|
5
|
+
* the browser bundle can import it without pulling in any Node builtin or any
|
|
6
|
+
* `@deepseek-ai/*` runtime package. The Host half is the only writer of the
|
|
7
|
+
* ledger; the Client half is a read-only consumer of the JSON summary below.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-token-usage-ledger/shared/protocol
|
|
10
|
+
*/
|
|
11
|
+
/** Bumped whenever the persisted record shape changes incompatibly. */
|
|
12
|
+
export const RECORD_SCHEMA_VERSION = 1;
|
|
13
|
+
/** Bumped whenever the wire summary shape changes incompatibly. */
|
|
14
|
+
export const SUMMARY_SCHEMA_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* Report whether a value is a currency this build can price and display.
|
|
17
|
+
* @param value - candidate.
|
|
18
|
+
* @returns true for a supported currency.
|
|
19
|
+
*/
|
|
20
|
+
export function isCurrency(value) {
|
|
21
|
+
return value === 'CNY' || value === 'USD';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Report whether a value is an object (not an array, not null).
|
|
25
|
+
* @param value - candidate.
|
|
26
|
+
* @returns true for a plain-object-like value.
|
|
27
|
+
*/
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Shallow structural check of a summary payload.
|
|
33
|
+
*
|
|
34
|
+
* The dashboard reads a fixed set of containers (`daily`, `facets`, `totals`,
|
|
35
|
+
* `pricing`, both breakdown arrays). Validating just those containers before the
|
|
36
|
+
* type assertion keeps a malformed or half-upgraded Host response from throwing
|
|
37
|
+
* inside the render tree; every deeper field is still read defensively at the
|
|
38
|
+
* call site. It is deliberately shallow: a few thousand daily points are not
|
|
39
|
+
* worth validating field by field on every fetch.
|
|
40
|
+
*
|
|
41
|
+
* @param value - parsed JSON body.
|
|
42
|
+
* @returns true when the payload carries the containers the dashboard reads.
|
|
43
|
+
*/
|
|
44
|
+
export function isSummaryResponseLike(value) {
|
|
45
|
+
if (!isObject(value))
|
|
46
|
+
return false;
|
|
47
|
+
if (typeof value['currency'] !== 'string')
|
|
48
|
+
return false;
|
|
49
|
+
if (typeof value['pluginVersion'] !== 'string')
|
|
50
|
+
return false;
|
|
51
|
+
const totals = value['totals'];
|
|
52
|
+
const allTime = value['allTime'];
|
|
53
|
+
const health = value['health'];
|
|
54
|
+
const pricing = value['pricing'];
|
|
55
|
+
const facets = value['facets'];
|
|
56
|
+
if (!isObject(totals) || !isObject(allTime) || !isObject(health))
|
|
57
|
+
return false;
|
|
58
|
+
if (!isObject(pricing) || !isObject(facets))
|
|
59
|
+
return false;
|
|
60
|
+
if (!Array.isArray(value['daily']))
|
|
61
|
+
return false;
|
|
62
|
+
if (!Array.isArray(value['byModel']) || !Array.isArray(value['byWorkspace']))
|
|
63
|
+
return false;
|
|
64
|
+
if (!Array.isArray(facets['workspaces']) || !Array.isArray(facets['models']))
|
|
65
|
+
return false;
|
|
66
|
+
if (typeof facets['records'] !== 'number')
|
|
67
|
+
return false;
|
|
68
|
+
if (typeof totals['total'] !== 'number' || !isObject(totals['tokens']))
|
|
69
|
+
return false;
|
|
70
|
+
if (typeof pricing['currency'] !== 'string')
|
|
71
|
+
return false;
|
|
72
|
+
if (!Array.isArray(pricing['rows']) || !Array.isArray(pricing['peakWindows']))
|
|
73
|
+
return false;
|
|
74
|
+
if (typeof pricing['offPeakRatio'] !== 'number')
|
|
75
|
+
return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/** Server-enforced bounds, mirrored by the client's own controls. */
|
|
79
|
+
export const API_LIMITS = {
|
|
80
|
+
/** Default daily window. */
|
|
81
|
+
defaultDays: 90,
|
|
82
|
+
/** Maximum daily window the server will serialize. */
|
|
83
|
+
maxDays: 1825,
|
|
84
|
+
/**
|
|
85
|
+
* Largest number of ledger records the reader will hold.
|
|
86
|
+
*
|
|
87
|
+
* The reader streams the ledger, so this bounds MEMORY rather than file size;
|
|
88
|
+
* reaching it sets `HealthReport.ledgerTruncated` and keeps the newest records.
|
|
89
|
+
*/
|
|
90
|
+
maxRecords: 500_000,
|
|
91
|
+
};
|
|
92
|
+
/** Marker written into backup files exported from the dashboard. */
|
|
93
|
+
export const BACKUP_FORMAT = 'dsh-token-usage-backup';
|
|
94
|
+
/** Backup envelope version this build writes and can read. */
|
|
95
|
+
export const BACKUP_FORMAT_VERSION = 1;
|
|
96
|
+
/** Bounds shared by the Host endpoints and the browser's file picker. */
|
|
97
|
+
export const BACKUP_LIMITS = {
|
|
98
|
+
/** Maximum JSON bytes accepted for one export/import operation. */
|
|
99
|
+
maxBytes: 64 * 1024 * 1024,
|
|
100
|
+
/** Maximum record count accepted from one backup file. */
|
|
101
|
+
maxRecords: 200_000,
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Report whether a value is shaped like a backup file.
|
|
105
|
+
*
|
|
106
|
+
* Deliberately shallow: the Host re-validates every record through the schema
|
|
107
|
+
* reader. The browser only needs enough to avoid POSTing an unrelated JSON file.
|
|
108
|
+
*
|
|
109
|
+
* @param value - parsed JSON value.
|
|
110
|
+
* @returns true when the envelope fields are present and sane.
|
|
111
|
+
*/
|
|
112
|
+
export function isBackupFileLike(value) {
|
|
113
|
+
if (!isObject(value))
|
|
114
|
+
return false;
|
|
115
|
+
if (value['format'] !== BACKUP_FORMAT)
|
|
116
|
+
return false;
|
|
117
|
+
if (typeof value['formatVersion'] !== 'number' || !Number.isSafeInteger(value['formatVersion'])) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (value['formatVersion'] > BACKUP_FORMAT_VERSION)
|
|
121
|
+
return false;
|
|
122
|
+
if (!Array.isArray(value['records']))
|
|
123
|
+
return false;
|
|
124
|
+
if (typeof value['recordCount'] !== 'number' || !Number.isSafeInteger(value['recordCount'])) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return value['recordCount'] === value['records'].length;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=protocol.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-token-usage-ledger",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.37",
|
|
4
|
+
"description": "Token usage and cost ledger with a dashboard for DeepSeek Harness: per-turn ledger, 365-day heatmap, charts, filters, export/import and backfill.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"default": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./client": {
|
|
13
|
+
"default": "./lib/client.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"!lib/**/*.map",
|
|
20
|
+
"!lib/.tsbuildinfo",
|
|
21
|
+
"cordis.patch.yml",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"docs/token-usage-image01.png",
|
|
26
|
+
"docs/token-usage-image02.png"
|
|
27
|
+
],
|
|
28
|
+
"dsh": {
|
|
29
|
+
"bundle": {
|
|
30
|
+
"patch": "./cordis.patch.yml"
|
|
31
|
+
},
|
|
32
|
+
"client": {
|
|
33
|
+
"platform": "web"
|
|
34
|
+
},
|
|
35
|
+
"pluginCompat": {
|
|
36
|
+
"dshVersion": "0.2.2-rc.2",
|
|
37
|
+
"checkedAt": "2026-11-12"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"dsh": "^0.2.2-rc.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
45
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.2",
|
|
46
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.2",
|
|
47
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.2",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.2",
|
|
50
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
51
|
+
"@deepseek-ai/dsh-token-meter": "0.2.2-rc.2",
|
|
52
|
+
"@deepseek-ai/dsh-workspace": "0.2.2-rc.2",
|
|
53
|
+
"@types/node": "^24.9.2",
|
|
54
|
+
"@types/react": "^19.3.0",
|
|
55
|
+
"esbuild": "^0.25.0",
|
|
56
|
+
"react": "^19.3.0",
|
|
57
|
+
"typescript": "^5.9.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "npm run build:host && npm run build:client",
|
|
61
|
+
"build:host": "tsc -p tsconfig.json",
|
|
62
|
+
"build:client": "node scripts/build-client.mjs",
|
|
63
|
+
"pack:install": "node scripts/pack-install-package.mjs",
|
|
64
|
+
"pack:check": "npm pack --dry-run",
|
|
65
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
|
|
66
|
+
"clean": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
67
|
+
"pretest": "npm run build",
|
|
68
|
+
"test": "node --test tests/*.test.mjs",
|
|
69
|
+
"prepack": "npm run build",
|
|
70
|
+
"prepublishOnly": "npm run typecheck && npm test"
|
|
71
|
+
},
|
|
72
|
+
"private": false,
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"author": "Mizukishun",
|
|
77
|
+
"keywords": [
|
|
78
|
+
"dsh",
|
|
79
|
+
"dsh-plugin",
|
|
80
|
+
"deepseek",
|
|
81
|
+
"deepseek-harness",
|
|
82
|
+
"token-usage",
|
|
83
|
+
"token",
|
|
84
|
+
"cost",
|
|
85
|
+
"dashboard",
|
|
86
|
+
"ledger"
|
|
87
|
+
],
|
|
88
|
+
"license": "MIT"
|
|
89
|
+
}
|