@ramarivera/coding-agent-langfuse 0.1.11 → 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.
- package/dist/backfill.js +15 -15
- 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
|
-
|
|
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";
|
|
@@ -569,9 +571,7 @@ function opencodeEvents(homeDir, rowLimit) {
|
|
|
569
571
|
const sessionId = asString(message.session_id);
|
|
570
572
|
const session = sessionsById.get(sessionId);
|
|
571
573
|
const tokens = normalizeUsage(parseMaybeJson(message.tokens));
|
|
572
|
-
const usage = tokens
|
|
573
|
-
? { ...tokens, cost: asNumber(message.cost) ?? tokens.cost }
|
|
574
|
-
: normalizeUsage(parseMaybeJson(message.usage));
|
|
574
|
+
const usage = tokens ?? normalizeUsage(parseMaybeJson(message.usage));
|
|
575
575
|
events.push({
|
|
576
576
|
agent: "opencode",
|
|
577
577
|
sourcePath: db,
|