@drsamonline/telemetry 0.12.9 → 0.12.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/package.json +1 -1
- package/src/ledger.js +7 -1
package/package.json
CHANGED
package/src/ledger.js
CHANGED
|
@@ -87,7 +87,7 @@ export class Ledger {
|
|
|
87
87
|
const key = this.#dayKey(row);
|
|
88
88
|
let day = this.daily.get(key);
|
|
89
89
|
if (!day) {
|
|
90
|
-
day = { costUsd: 0, turns: 0, failed: 0, cached: 0, byProvider: new Map() };
|
|
90
|
+
day = { costUsd: 0, turns: 0, failed: 0, cached: 0, byProvider: new Map(), byModel: new Map() };
|
|
91
91
|
this.daily.set(key, day);
|
|
92
92
|
// keep at most three days: yesterday is useful, last week is not
|
|
93
93
|
if (this.daily.size > 3) {
|
|
@@ -101,6 +101,7 @@ export class Ledger {
|
|
|
101
101
|
if (row.cached) day.cached += 1;
|
|
102
102
|
const provider = row.provider ?? 'unknown';
|
|
103
103
|
day.byProvider.set(provider, (day.byProvider.get(provider) ?? 0) + Number(row.costUsd ?? 0));
|
|
104
|
+
if (row.modelId) day.byModel.set(row.modelId, (day.byModel.get(row.modelId) ?? 0) + 1);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
/** The bucket for a given day, or an empty one. */
|
|
@@ -205,6 +206,11 @@ export class Ledger {
|
|
|
205
206
|
return round6(this.#day(now).costUsd);
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
/** Turns a model has answered today. Used by quota-weighted routing. */
|
|
210
|
+
turnsForModel(modelId, now = new Date()) {
|
|
211
|
+
return this.#day(now).byModel?.get(modelId) ?? 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
208
214
|
providerSpendToday(provider, now = new Date()) {
|
|
209
215
|
// same rule as todaySpendUsd: from the day bucket, not the window
|
|
210
216
|
return round6(this.#day(now).byProvider.get(provider) ?? 0);
|