@nexus-aethra/dshell-usage 0.1.14-alpha.3 → 0.1.14-alpha.4

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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/lib/index-store.js +43 -43
  3. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Nexus Aethra
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nexus Aethra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -69,27 +69,27 @@ export class UsageStore {
69
69
  // drop the columns it does not know, so it stops instead.
70
70
  throw new Error(`dshell usage: index at ${this.path} has layout ${String(version)}, this build writes ${String(LAYOUT)}`);
71
71
  }
72
- this.#db.exec(`
73
- CREATE TABLE usage_bucket (
74
- day TEXT NOT NULL,
75
- provider TEXT NOT NULL,
76
- model TEXT NOT NULL,
77
- uncached_input INTEGER NOT NULL DEFAULT 0,
78
- output INTEGER NOT NULL DEFAULT 0,
79
- cache_read INTEGER NOT NULL DEFAULT 0,
80
- cache_write INTEGER NOT NULL DEFAULT 0,
81
- turns INTEGER NOT NULL DEFAULT 0,
82
- PRIMARY KEY (day, provider, model)
83
- );
84
- CREATE TABLE usage_cursor (
85
- session_id TEXT NOT NULL PRIMARY KEY,
86
- seq INTEGER NOT NULL
87
- );
88
- CREATE TABLE usage_meta (
89
- key TEXT NOT NULL PRIMARY KEY,
90
- value TEXT NOT NULL
91
- );
92
- PRAGMA user_version = ${String(LAYOUT)};
72
+ this.#db.exec(`
73
+ CREATE TABLE usage_bucket (
74
+ day TEXT NOT NULL,
75
+ provider TEXT NOT NULL,
76
+ model TEXT NOT NULL,
77
+ uncached_input INTEGER NOT NULL DEFAULT 0,
78
+ output INTEGER NOT NULL DEFAULT 0,
79
+ cache_read INTEGER NOT NULL DEFAULT 0,
80
+ cache_write INTEGER NOT NULL DEFAULT 0,
81
+ turns INTEGER NOT NULL DEFAULT 0,
82
+ PRIMARY KEY (day, provider, model)
83
+ );
84
+ CREATE TABLE usage_cursor (
85
+ session_id TEXT NOT NULL PRIMARY KEY,
86
+ seq INTEGER NOT NULL
87
+ );
88
+ CREATE TABLE usage_meta (
89
+ key TEXT NOT NULL PRIMARY KEY,
90
+ value TEXT NOT NULL
91
+ );
92
+ PRAGMA user_version = ${String(LAYOUT)};
93
93
  `);
94
94
  }
95
95
  /** The highest seq already counted for one session, or undefined. */
@@ -111,23 +111,23 @@ export class UsageStore {
111
111
  applyBatch(batch) {
112
112
  if (batch.rows.length === 0 && batch.cursors.length === 0)
113
113
  return;
114
- const bucket = this.#db.prepare(`
115
- INSERT INTO usage_bucket (day, provider, model, uncached_input, output, cache_read, cache_write, turns)
116
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
117
- ON CONFLICT (day, provider, model) DO UPDATE SET
118
- uncached_input = uncached_input + excluded.uncached_input,
119
- output = output + excluded.output,
120
- cache_read = cache_read + excluded.cache_read,
121
- cache_write = cache_write + excluded.cache_write,
122
- turns = turns + excluded.turns
114
+ const bucket = this.#db.prepare(`
115
+ INSERT INTO usage_bucket (day, provider, model, uncached_input, output, cache_read, cache_write, turns)
116
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
117
+ ON CONFLICT (day, provider, model) DO UPDATE SET
118
+ uncached_input = uncached_input + excluded.uncached_input,
119
+ output = output + excluded.output,
120
+ cache_read = cache_read + excluded.cache_read,
121
+ cache_write = cache_write + excluded.cache_write,
122
+ turns = turns + excluded.turns
123
123
  `);
124
- const cursor = this.#db.prepare(`
125
- INSERT INTO usage_cursor (session_id, seq) VALUES (?, ?)
126
- ON CONFLICT (session_id) DO UPDATE SET seq = excluded.seq
124
+ const cursor = this.#db.prepare(`
125
+ INSERT INTO usage_cursor (session_id, seq) VALUES (?, ?)
126
+ ON CONFLICT (session_id) DO UPDATE SET seq = excluded.seq
127
127
  `);
128
- const meta = this.#db.prepare(`
129
- INSERT INTO usage_meta (key, value) VALUES ('scannedAt', ?)
130
- ON CONFLICT (key) DO UPDATE SET value = excluded.value
128
+ const meta = this.#db.prepare(`
129
+ INSERT INTO usage_meta (key, value) VALUES ('scannedAt', ?)
130
+ ON CONFLICT (key) DO UPDATE SET value = excluded.value
131
131
  `);
132
132
  this.#db.exec('BEGIN');
133
133
  try {
@@ -155,10 +155,10 @@ export class UsageStore {
155
155
  const bound = days === null ? undefined : localDay(new Date(Date.now() - days * 86_400_000));
156
156
  const where = bound === undefined ? '' : 'WHERE day >= ?';
157
157
  const args = bound === undefined ? [] : [bound];
158
- const dayRows = this.#db.prepare(`
159
- SELECT day, provider, model, uncached_input, output, cache_read, cache_write, turns
160
- FROM usage_bucket ${where}
161
- ORDER BY day, provider, model
158
+ const dayRows = this.#db.prepare(`
159
+ SELECT day, provider, model, uncached_input, output, cache_read, cache_write, turns
160
+ FROM usage_bucket ${where}
161
+ ORDER BY day, provider, model
162
162
  `).all(...args);
163
163
  const byDay = dayRows.map(row => ({
164
164
  day: String(row.day),
@@ -189,9 +189,9 @@ export class UsageStore {
189
189
  // rhythm question ("which days do I burn tokens on") is not the same
190
190
  // question as "what did this week cost", and re-shaping the calendar every
191
191
  // time the reader moves the range would answer neither.
192
- const heat = this.#db.prepare(`
193
- SELECT day, sum(uncached_input + output + cache_read + cache_write) AS total, sum(turns) AS turns
194
- FROM usage_bucket GROUP BY day ORDER BY day
192
+ const heat = this.#db.prepare(`
193
+ SELECT day, sum(uncached_input + output + cache_read + cache_write) AS total, sum(turns) AS turns
194
+ FROM usage_bucket GROUP BY day ORDER BY day
195
195
  `).all().map(row => ({
196
196
  day: String(row.day),
197
197
  total: Number(row.total),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-aethra/dshell-usage",
3
- "version": "0.1.14-alpha.3",
3
+ "version": "0.1.14-alpha.4",
4
4
  "description": "dshell usage: a durable per-model token index over every session's reported usage, and the settings page that charts it.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "zod": "4.4.3",
37
- "@nexus-aethra/dshell-std": "^0.1.14-alpha.3"
37
+ "@nexus-aethra/dshell-std": "^0.1.14-alpha.4"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@deepseek-ai/cordis": "^4.0.2",