@ramarivera/coding-agent-langfuse 0.1.12 → 0.1.13

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 (2) hide show
  1. package/dist/backfill.js +14 -12
  2. package/package.json +1 -1
package/dist/backfill.js CHANGED
@@ -311,21 +311,23 @@ function pricingForModel(model) {
311
311
  function costDetails(usage, model) {
312
312
  if (!usage)
313
313
  return undefined;
314
+ const rates = pricingForModel(model);
315
+ if (rates) {
316
+ const input = ((usage.input ?? 0) * rates.input) / 1_000_000;
317
+ const output = (((usage.output ?? 0) + (usage.reasoning ?? 0)) * rates.output) /
318
+ 1_000_000;
319
+ const cache_read = ((usage.cacheRead ?? 0) * rates.cacheRead) / 1_000_000;
320
+ const cache_write = ((usage.cacheWrite ?? 0) * rates.cacheWrite) /
321
+ 1_000_000;
322
+ const total = input + output + cache_read + cache_write;
323
+ if (total > 0) {
324
+ return { input, output, cache_read, cache_write, total, source: "estimated" };
325
+ }
326
+ }
314
327
  if (usage.cost !== undefined && usage.cost > 0) {
315
328
  return { total: usage.cost, source: "recorded" };
316
329
  }
317
- const rates = pricingForModel(model);
318
- if (!rates)
319
- return undefined;
320
- const input = ((usage.input ?? 0) * rates.input) / 1_000_000;
321
- const output = (((usage.output ?? 0) + (usage.reasoning ?? 0)) * rates.output) /
322
- 1_000_000;
323
- const cache_read = ((usage.cacheRead ?? 0) * rates.cacheRead) / 1_000_000;
324
- const cache_write = ((usage.cacheWrite ?? 0) * rates.cacheWrite) / 1_000_000;
325
- const total = input + output + cache_read + cache_write;
326
- if (total <= 0)
327
- return undefined;
328
- return { input, output, cache_read, cache_write, total, source: "estimated" };
330
+ return undefined;
329
331
  }
330
332
  function isGenerationEvent(event) {
331
333
  return event.usage !== undefined && event.role !== "user";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramarivera/coding-agent-langfuse",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Universal coding-agent Langfuse backfiller and live OTLP helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",