@goodandready/dsh-cost-meter 0.8.28 → 0.8.30

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/lib/index.js CHANGED
@@ -33,6 +33,7 @@ export * from './fx.js'
33
33
  export * from './alerts.js'
34
34
  export * from './commands.js'
35
35
  export * from './export.js'
36
+ export * from './analytics.js'
36
37
  export { STATE_PATH, REFRESH_PATH } from './routes.js'
37
38
  import { indexCatalog, resolveTariff, matchModel, unwrapVolatile, calculateCacheSavings } from './tariff.js'
38
39
  import { usageByModelProjection, getLastTurns, resetLastTurns } from './projection.js'
package/lib/routes.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createHash } from 'node:crypto'
3
3
  import { registerPluginUpdater } from './updater.js'
4
4
  import { getLastTurns } from './projection.js'
5
- import { calculateBurnRateAndProjection } from './analytics.js'
5
+ import { calculateBurnRateAndProjection, calculateContextMetrics } from './analytics.js'
6
6
  import { getCachedFxState } from './fx.js'
7
7
 
8
8
  export const STATE_PATH = '/dsh-cost-meter/state'
@@ -105,6 +105,10 @@ export function registerRoutes(ctx, options) {
105
105
  }
106
106
  }
107
107
 
108
+ const turnsList = getLastTurns()
109
+ const fxRateVal = Number(cfg?.usdRate) > 0 ? Number(cfg.usdRate) : 1
110
+ const ctxMetrics = calculateContextMetrics(turnsList, own, route)
111
+
108
112
  const payloadObj = {
109
113
  currency: typeof cfg?.currency === 'string' && cfg.currency ? cfg.currency : '$',
110
114
  usdRate: Number(cfg?.usdRate) > 0 ? Number(cfg.usdRate) : 1,
@@ -129,6 +133,14 @@ export function registerRoutes(ctx, options) {
129
133
  catalogError: catalog.error,
130
134
  catalogModelsCount: Object.keys((catalog.index && catalog.index.byId) || {}).length,
131
135
  schedule: own.schedule,
136
+ contextMetrics: {
137
+ currentTokens: ctxMetrics.currentTokens,
138
+ contextLength: ctxMetrics.contextLength,
139
+ saturationPercent: ctxMetrics.saturationPercent,
140
+ riskLevel: ctxMetrics.riskLevel,
141
+ nextTurnEstUsd: ctxMetrics.nextTurnEstUsd,
142
+ nextTurnEstLocal: ctxMetrics.nextTurnEstUsd * fxRateVal,
143
+ },
132
144
  }
133
145
 
134
146
  const serialized = JSON.stringify(payloadObj)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-cost-meter",
3
- "version": "0.8.28",
3
+ "version": "0.8.30",
4
4
  "description": "DeepSeek Harness plugin: a session cost chip in the conversation header - live token usage by bucket, peak/off-peak tariff, and a countdown to the next tariff switch.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",